diff --git a/Test/CMakeLists.txt b/Test/CMakeLists.txt index b590bed..bf422c3 100644 --- a/Test/CMakeLists.txt +++ b/Test/CMakeLists.txt @@ -4,11 +4,12 @@ set(TESTS - objc_msgSend.m BlockImpTest.m + PropertyAttributeTest.m PropertyIntrospectionTest.m ProtocolCreation.m RuntimeTest.m + objc_msgSend.m ) #ExceptionTest.m diff --git a/Test/PropertyAttributeTest.m b/Test/PropertyAttributeTest.m index dd9a9b9..3d4b089 100644 --- a/Test/PropertyAttributeTest.m +++ b/Test/PropertyAttributeTest.m @@ -1,9 +1,14 @@ #include -#import #import +#include #include -@interface helloclass : NSObject { +#ifdef __has_attribute +#if __has_attribute(objc_root_class) +__attribute__((objc_root_class)) +#endif +#endif +@interface helloclass { @private int varName; } @property (readwrite,assign) int propName; @@ -11,6 +16,7 @@ @implementation helloclass @synthesize propName = varName; ++ (id)class { return self; } @end int main() diff --git a/properties.m b/properties.m index fd8bf87..f26a2a4 100644 --- a/properties.m +++ b/properties.m @@ -400,6 +400,7 @@ PRIVATE const char *constructPropertyAttributes(objc_property_t property, unsigned char *encoding = malloc(encodingSize); // Set the leading 0 and the offset of the name unsigned char *insert = encoding; + BOOL needsComma = NO; *(insert++) = 0; *(insert++) = 0; // Set the type encoding @@ -408,33 +409,39 @@ PRIVATE const char *constructPropertyAttributes(objc_property_t property, *(insert++) = 'T'; memcpy(insert, typeEncoding, typeSize); insert += typeSize; + needsComma = YES; } // Set the flags memcpy(insert, flags, i); insert += i; if ((property->attributes & OBJC_PR_getter) == OBJC_PR_getter) { - if (i > 0) + if (needsComma) { *(insert++) = ','; } i++; + needsComma = YES; *(insert++) = 'G'; memcpy(insert, property->getter_name, getterLength); insert += getterLength; } if ((property->attributes & OBJC_PR_setter) == OBJC_PR_setter) { - if (i > 0) + if (needsComma) { *(insert++) = ','; } i++; + needsComma = YES; *(insert++) = 'S'; memcpy(insert, property->setter_name, setterLength); insert += setterLength; } - *(insert++) = ','; + if (needsComma) + { + *(insert++) = ','; + } *(insert++) = 'V'; // If the instance variable name is the same as the property name, then we // use the same string for both, otherwise we write the ivar name in the