@@ -21,15 +21,16 @@ #import "OFAutoreleasePool.h" #import "OFExceptions.h" #import "OFMacros.h" #import -#ifdef __objc_INCLUDE_GNU -#import -#else +#ifdef OF_APPLE_RUNTIME #import #endif +#ifdef OF_GNU_RUNTIME +#import +#endif struct pre_ivar { void **memchunks; size_t memchunks_size; size_t retain_count; @@ -63,14 +64,14 @@ } + alloc { OFObject *instance; -#ifdef __objc_INCLUDE_GNU - size_t isize = class_get_instance_size(self); -#else +#ifdef OF_APPLE_RUNTIME size_t isize = class_getInstanceSize(self); +#else + size_t isize = class_get_instance_size(self); #endif if ((instance = malloc(isize + PRE_IVAR_ALIGN)) == NULL) { alloc_failed_exception.isa = [OFAllocFailedException class]; @throw (OFAllocFailedException*)&alloc_failed_exception; @@ -92,29 +93,37 @@ return self; } + (const char*)className { -#ifdef __objc_INCLUDE_GNU - return class_get_class_name(self); -#else +#ifdef OF_APPLE_RUNTIME return class_getName(self); +#else + return class_get_class_name(self); #endif } + (BOOL)instancesRespondToSelector: (SEL)selector { -#ifdef __objc_INCLUDE_GNU - return class_get_instance_method(self, selector) != METHOD_NULL; -#else +#ifdef OF_APPLE_RUNTIME return class_respondsToSelector(self, selector); +#else + return class_get_instance_method(self, selector) != METHOD_NULL; #endif } + (BOOL)conformsToProtocol: (Protocol*)protocol { -#ifdef __objc_INCLUDE_GNU +#ifdef OF_APPLE_RUNTIME + Class c; + + for (c = self; c != Nil; c = class_getSuperclass(c)) + if (class_conformsToProtocol(c, protocol)) + return YES; + + return NO; +#else Class c; struct objc_protocol_list *pl; size_t i; for (c = self; c != Nil; c = class_get_super_class(c)) @@ -121,35 +130,35 @@ for (pl = c->protocols; pl != NULL; pl = pl->next) for (i = 0; i < pl->count; i++) if ([pl->list[i] conformsToProtocol: protocol]) return YES; - return NO; -#else - Class c; - - for (c = self; c != Nil; c = class_getSuperclass(c)) - if (class_conformsToProtocol(c, protocol)) - return YES; - return NO; #endif } + (IMP)instanceMethodForSelector: (SEL)selector { -#ifdef __objc_INCLUDE_GNU - return method_get_imp(class_get_instance_method(self, selector)); -#else +#ifdef OF_APPLE_RUNTIME return class_getMethodImplementation(self, selector); +#else + return method_get_imp(class_get_instance_method(self, selector)); #endif } + (IMP)setImplementation: (IMP)newimp forMethod: (SEL)selector { -#ifdef __objc_INCLUDE_GNU +#ifdef OF_APPLE_RUNTIME + Method method; + + if ((method = class_getInstanceMethod(self, selector)) == NULL) + @throw [OFInvalidArgumentException newWithClass: self + selector: _cmd]; + + return method_setImplementation(method, newimp); +#else Method_t method = class_get_instance_method(self, selector); IMP oldimp; if (method == NULL) @throw [OFInvalidArgumentException newWithClass: self @@ -166,30 +175,22 @@ (sidx)method->method_name->sel_id)) sarray_at_put_safe(((Class)self)->dtable, (sidx)method->method_name->sel_id, method->method_imp); return oldimp; -#else - Method method; - - if ((method = class_getInstanceMethod(self, selector)) == NULL) - @throw [OFInvalidArgumentException newWithClass: self - selector: _cmd]; - - return method_setImplementation(method, newimp); #endif } + (IMP)replaceMethod: (SEL)selector withMethodFromClass: (Class)class; { IMP newimp; -#ifdef __objc_INCLUDE_GNU - newimp = method_get_imp(class_get_instance_method(class, selector)); +#ifdef OF_APPLE_RUNTIME + newimp = class_getMethodImplementation(class, selector); #else - newimp = class_getMethodImplementation(class, selector); + newimp = method_get_imp(class_get_instance_method(class, selector)); #endif return [self setImplementation: newimp forMethod: selector]; } @@ -204,41 +205,41 @@ return isa; } - (const char*)className { -#ifdef __objc_INCLUDE_GNU - return object_get_class_name(self); +#ifdef OF_APPLE_RUNTIME + return class_getName(isa); #else - return class_getName(isa); + return object_get_class_name(self); #endif } - (BOOL)isKindOfClass: (Class)class { Class iter; -#ifdef __objc_INCLUDE_GNU - for (iter = isa; iter != Nil; iter = class_get_super_class(iter)) +#ifdef OF_APPLE_RUNTIME + for (iter = isa; iter != Nil; iter = class_getSuperclass(iter)) #else - for (iter = isa; iter != Nil; iter = class_getSuperclass(iter)) + for (iter = isa; iter != Nil; iter = class_get_super_class(iter)) #endif if (iter == class) return YES; return NO; } - (BOOL)respondsToSelector: (SEL)selector { -#ifdef __objc_INCLUDE_GNU +#ifdef OF_APPLE_RUNTIME + return class_respondsToSelector(isa, selector); +#else if (object_is_instance(self)) return class_get_instance_method(isa, selector) != METHOD_NULL; else return class_get_class_method(isa, selector) != METHOD_NULL; -#else - return class_respondsToSelector(isa, selector); #endif } - (BOOL)conformsToProtocol: (Protocol*)protocol { @@ -245,17 +246,17 @@ return [isa conformsToProtocol: protocol]; } - (IMP)methodForSelector: (SEL)selector { -#ifdef __objc_INCLUDE_GNU +#ifdef OF_APPLE_RUNTIME + return class_getMethodImplementation(isa, selector); +#else if (object_is_instance(self)) return method_get_imp(class_get_instance_method(isa, selector)); else return method_get_imp(class_get_class_method(isa, selector)); -#else - return class_getMethodImplementation(isa, selector); #endif } - (BOOL)isEqual: (id)obj {