@@ -21,15 +21,17 @@ #import "OFObject.h" #import "OFAutoreleasePool.h" #import "OFExceptions.h" #import "macros.h" -#import -#ifdef OF_APPLE_RUNTIME +#if defined(OF_OBJFW_RUNTIME) +# import +#elif defined(OF_APPLE_RUNTIME) +# import # import -#endif -#ifdef OF_GNU_RUNTIME +#elif defined(OF_GNU_RUNTIME) +# import # import #endif #ifdef _WIN32 # include @@ -40,11 +42,11 @@ #else # import "threading.h" #endif /* A few macros to reduce #ifdefs */ -#ifndef OF_APPLE_RUNTIME +#ifdef OF_GNU_RUNTIME # define class_getInstanceSize class_get_instance_size # define class_getName class_get_class_name # define class_getSuperclass class_get_super_class #endif @@ -181,28 +183,20 @@ return class_getSuperclass(self); } + (BOOL)instancesRespondToSelector: (SEL)selector { -#ifdef OF_APPLE_RUNTIME - return class_respondsToSelector(self, selector); -#else +#ifdef OF_GNU_RUNTIME return class_get_instance_method(self, selector) != METHOD_NULL; +#else + return class_respondsToSelector(self, selector); #endif } + (BOOL)conformsToProtocol: (Protocol*)protocol { -#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 +#ifdef OF_GNU_RUNTIME Class c; struct objc_protocol_list *pl; size_t i; for (c = self; c != Nil; c = class_get_super_class(c)) @@ -209,27 +203,39 @@ 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 OF_APPLE_RUNTIME +#if defined(OF_OBJFW_RUNTIME) + return objc_get_instance_method(self, selector); +#elif defined(OF_APPLE_RUNTIME) return class_getMethodImplementation(self, selector); #else return method_get_imp(class_get_instance_method(self, selector)); #endif } + (IMP)setImplementation: (IMP)newimp forClassMethod: (SEL)selector { -#ifdef OF_APPLE_RUNTIME +#if defined(OF_OBJFW_RUNTIME) + return objc_replace_class_method(self, selector, newimp); +#elif defined(OF_APPLE_RUNTIME) return class_replaceMethod(self->isa, selector, newimp, method_getTypeEncoding(class_getClassMethod(self, selector))); #else Method_t method; IMP oldimp; @@ -259,11 +265,13 @@ + (IMP)replaceClassMethod: (SEL)selector withClassMethodFromClass: (Class)class; { IMP newimp; -#ifdef OF_APPLE_RUNTIME +#if defined(OF_OBJFW_RUNTIME) + newimp = objc_get_class_method(class, selector); +#elif defined(OF_APPLE_RUNTIME) newimp = method_getImplementation(class_getClassMethod(class, selector)); #else /* The class method is the instance method of the meta class */ newimp = method_get_imp(class_get_instance_method(class->class_pointer, @@ -275,11 +283,13 @@ } + (IMP)setImplementation: (IMP)newimp forInstanceMethod: (SEL)selector { -#ifdef OF_APPLE_RUNTIME +#if defined(OF_OBJFW_RUNTIME) + return objc_replace_instance_method(self, selector, newimp); +#elif defined(OF_APPLE_RUNTIME) return class_replaceMethod(self, selector, newimp, method_getTypeEncoding(class_getInstanceMethod(self, selector))); #else Method_t method = class_get_instance_method(self, selector); IMP oldimp; @@ -307,11 +317,13 @@ + (IMP)replaceInstanceMethod: (SEL)selector withInstanceMethodFromClass: (Class)class; { IMP newimp; -#ifdef OF_APPLE_RUNTIME +#if defined(OF_OBJFW_RUNTIME) + newimp = objc_get_instance_method(class, selector); +#elif defined(OF_APPLE_RUNTIME) newimp = class_getMethodImplementation(class, selector); #else newimp = method_get_imp(class_get_instance_method(class, selector)); #endif @@ -329,14 +341,14 @@ return isa; } - (const char*)className { -#ifdef OF_APPLE_RUNTIME - return class_getName(isa); +#ifdef OF_GNU_RUNTIME + return object_get_class_name(self); #else - return object_get_class_name(self); + return class_getName(isa); #endif } - (BOOL)isKindOfClass: (Class)class { @@ -349,17 +361,17 @@ return NO; } - (BOOL)respondsToSelector: (SEL)selector { -#ifdef OF_APPLE_RUNTIME - return class_respondsToSelector(isa, selector); -#else +#ifdef OF_GNU_RUNTIME 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 { @@ -369,14 +381,11 @@ - (IMP)methodForSelector: (SEL)selector { #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)); + return objc_msg_lookup(self, selector); #endif } - (BOOL)isEqual: (OFObject*)obj {