@@ -120,143 +120,63 @@ - (instancetype)init { OF_INVALID_INIT_METHOD } -#if defined(OF_OBJFW_RUNTIME) -- (instancetype)of_initWithProperty: (struct objc_property *)property -{ - self = [super init]; - - @try { - _name = [[OFString alloc] initWithUTF8String: property->name]; - _attributes = - property->attributes | (property->extendedAttributes << 8); - - if (property->getter.name != NULL) - _getter = [[OFString alloc] - initWithUTF8String: property->getter.name]; - if (property->setter.name != NULL) - _setter = [[OFString alloc] - initWithUTF8String: property->setter.name]; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} -#elif defined(OF_APPLE_RUNTIME) - (instancetype)of_initWithProperty: (objc_property_t)property { self = [super init]; @try { - const char *attributes; + char *value; _name = [[OFString alloc] initWithUTF8String: property_getName(property)]; - if ((attributes = property_getAttributes(property)) == NULL) - @throw [OFInitializationFailedException - exceptionWithClass: self.class]; - - while (*attributes != '\0') { - const char *start; - - switch (*attributes) { - case 'T': - while (*attributes != ',' && - *attributes != '\0') - attributes++; - break; - case 'R': - _attributes |= OF_PROPERTY_READONLY; - attributes++; - break; - case 'C': - _attributes |= OF_PROPERTY_COPY; - attributes++; - break; - case '&': - _attributes |= OF_PROPERTY_RETAIN; - attributes++; - break; - case 'N': - _attributes |= OF_PROPERTY_NONATOMIC; - attributes++; - break; - case 'G': - start = ++attributes; - - if (_getter != nil) - @throw [OFInitializationFailedException - exceptionWithClass: self.class]; - - while (*attributes != ',' && - *attributes != '\0') - attributes++; - + value = property_copyAttributeValue(property, "G"); + if (value != NULL) { + @try { _getter = [[OFString alloc] - initWithUTF8String: start - length: attributes - start]; - - break; - case 'S': - start = ++attributes; - - if (_setter != nil) - @throw [OFInitializationFailedException - exceptionWithClass: self.class]; - - while (*attributes != ',' && - *attributes != '\0') - attributes++; - + initWithUTF8String: value]; + } @finally { + free(value); + } + } + + value = property_copyAttributeValue(property, "S"); + if (value != NULL) { + @try { _setter = [[OFString alloc] - initWithUTF8String: start - length: attributes - start]; - - break; - case 'D': - _attributes |= OF_PROPERTY_DYNAMIC; - attributes++; - break; - case 'W': - _attributes |= OF_PROPERTY_WEAK; - attributes++; - break; - case 'P': - attributes++; - break; - case 'V': - start = ++attributes; - - if (_iVar != nil) - @throw [OFInitializationFailedException - exceptionWithClass: self.class]; - - while (*attributes != ',' && - *attributes != '\0') - attributes++; - + initWithUTF8String: value]; + } @finally { + free(value); + } + } + +#define BOOL_ATTRIBUTE(name, flag) \ + value = property_copyAttributeValue(property, name); \ + if (value != NULL) { \ + _attributes |= flag; \ + free(value); \ + } + + BOOL_ATTRIBUTE("R", OF_PROPERTY_READONLY) + BOOL_ATTRIBUTE("C", OF_PROPERTY_COPY) + BOOL_ATTRIBUTE("&", OF_PROPERTY_RETAIN) + BOOL_ATTRIBUTE("N", OF_PROPERTY_NONATOMIC) + BOOL_ATTRIBUTE("D", OF_PROPERTY_DYNAMIC) + BOOL_ATTRIBUTE("W", OF_PROPERTY_WEAK) +#undef BOOL_ATTRIBUTE + + value = property_copyAttributeValue(property, "V"); + if (value != NULL) { + @try { _iVar = [[OFString alloc] - initWithUTF8String: start - length: attributes - start]; - - break; - default: - @throw [OFInitializationFailedException - exceptionWithClass: self.class]; - } - - if (*attributes != ',' && *attributes != '\0') - @throw [OFInitializationFailedException - exceptionWithClass: self.class]; - - if (*attributes != '\0') - attributes++; + initWithUTF8String: value]; + } @finally { + free(value); + } } if (!(_attributes & OF_PROPERTY_READONLY)) _attributes |= OF_PROPERTY_READWRITE; @@ -289,13 +209,10 @@ @throw e; } return self; } -#else -# error Invalid ObjC runtime! -#endif - (void)dealloc { [_name release]; [_getter release]; @@ -421,15 +338,11 @@ self = [super init]; @try { Method *methodList; Ivar *iVarList; -#if defined(OF_OBJFW_RUNTIME) - struct objc_property_list *propertyList; -#elif defined(OF_APPLE_RUNTIME) objc_property_t *propertyList; -#endif unsigned count; void *pool; _classMethods = [[OFMutableArray alloc] init]; _instanceMethods = [[OFMutableArray alloc] init]; @@ -477,23 +390,10 @@ objc_autoreleasePoolPop(pool); } @finally { free(iVarList); } -#if defined(OF_OBJFW_RUNTIME) - for (propertyList = class->properties; propertyList != NULL; - propertyList = propertyList->next) { - pool = objc_autoreleasePoolPush(); - - for (unsigned int i = 0; i < propertyList->count; i++) - [_properties addObject: [[[OFProperty alloc] - of_initWithProperty: - &propertyList->properties[i]] autorelease]]; - - objc_autoreleasePoolPop(pool); - } -#elif defined(OF_APPLE_RUNTIME) propertyList = class_copyPropertyList(class, &count); @try { pool = objc_autoreleasePoolPush(); for (unsigned int i = 0; i < count; i++) @@ -503,13 +403,10 @@ objc_autoreleasePoolPop(pool); } @finally { free(propertyList); } -#else -# error Invalid ObjC runtime! -#endif [_classMethods makeImmutable]; [_instanceMethods makeImmutable]; [_properties makeImmutable]; [_instanceVariables makeImmutable];