Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -126,88 +126,45 @@ ], [ AC_MSG_RESULT(no) OBJCFLAGS="$old_OBJCFLAGS" ]) -AC_CHECK_HEADERS([objfw-rt.h objc/objc.h]) - -test x"$ac_cv_header_objfw_rt_h" = x"yes" && objc_runtime="ObjFW-RT" - -AC_MSG_CHECKING(which Objective C runtime we use) -AS_IF([test x"$ac_cv_header_objc_objc_h" = x"yes"], [ - dnl Only accept it if it's from gcc >= 4.7, as the one in 4.6 is buggy - dnl when using the new API. - AC_EGREP_CPP(yes, [ - #import - #if defined(__GNU_LIBOBJC__) && __GNU_LIBOBJC__ >= 20110608 - yes - #endif - ], [ - test x"$objc_runtime" = x"" && objc_runtime="GNU" - ], [ - dnl TODO: This is ugly. Let's think of a better check. - AC_EGREP_CPP(yes, [ - #import - #ifdef __objc_INCLUDE_GNU - yes - #endif - ], [ - test x"$objc_runtime" = x"" && objc_runtime="old GNU" - ], [ - objc_runtime="Apple" - ]) +objc_runtime="ObjFW runtime" +AC_CHECK_HEADER(objc/objc.h) +AC_MSG_CHECKING(which Objective C runtime to use) +AS_IF([test x"$ac_cv_header_objc_objc_h" = x"yes"], [ + dnl TODO: This is ugly. Let's think of a better check. + AC_EGREP_CPP(yes, [ + #import + #ifdef __objc_INCLUDE_GNU + yes + #endif + ], [ + dnl We don't want the GNU runtime + ], [ + objc_runtime="Apple runtime" ]) ]) AC_MSG_RESULT($objc_runtime) case $objc_runtime in - ObjFW-RT) + "ObjFW runtime") AC_DEFINE(OF_OBJFW_RUNTIME, 1, [Whether we use the ObjFW runtime]) AC_SUBST(GNU_RUNTIME, "-fgnu-runtime") OBJCFLAGS="$OBJCFLAGS -fgnu-runtime" - - AC_CHECK_LIB(objfw-rt, objc_msg_lookup, [ - LIBS="-lobjfw-rt $LIBS" - ], [ - AC_MSG_ERROR([libobjfw-rt not found!]) - ]) ;; - Apple) + "Apple runtime") AC_DEFINE(OF_APPLE_RUNTIME, 1, [Whether we use the Apple ObjC runtime]) AC_CHECK_LIB(objc, objc_msgSend, [ LIBS="-lobjc $LIBS" ], [ AC_MSG_ERROR([libobjc not found!]) ]) ;; - GNU) - AC_DEFINE(OF_GNU_RUNTIME, 1, - [Whether we use the GNU ObjC runtime]) - - AC_CHECK_LIB(objc, objc_msg_lookup, [ - LIBS="-lobjc $LIBS" - ], [ - AC_MSG_ERROR([libobjc not found!]) - ]) - ;; - "old GNU") - AC_DEFINE(OF_OLD_GNU_RUNTIME, 1, - [Whether we use the old GNU ObjC runtime]) - - AC_CHECK_LIB(objc, objc_msg_lookup, [ - LIBS="-lobjc $LIBS" - ], [ - AC_MSG_ERROR([libobjc not found!]) - ]) - ;; - *) - AC_MSG_RESULT(none) - AC_MSG_ERROR(No ObjC runtime found! Please install ObjFW-RT!) - ;; esac AC_CHECK_FUNC(objc_getProperty,, [ AC_DEFINE(NEED_OBJC_PROPERTIES_INIT, 1, [Whether objc_properties_init needs to be called]) @@ -226,16 +183,20 @@ AS_IF([test x"$enable_shared" != x"no"], [ BUILDSYS_SHARED_LIB AC_SUBST(OBJFW_SHARED_LIB, "${LIB_PREFIX}objfw${LIB_SUFFIX}") AC_SUBST(EXCEPTIONS_LIB_A, "exceptions.lib.a") AC_SUBST(EXCEPTIONS_EXCEPTIONS_LIB_A, "exceptions/exceptions.lib.a") + AC_SUBST(RUNTIME_LIB_A, "runtime.lib.a") + AC_SUBST(RUNTIME_RUNTIME_LIB_A, "runtime/runtime.lib.a") ]) AC_ARG_ENABLE(static, AS_HELP_STRING([--enable-static], [build static library])) AS_IF([test x"$enable_static" = x"yes" -o x"$enable_shared" = x"no"], [ AC_SUBST(OBJFW_STATIC_LIB, "libobjfw.a") AC_SUBST(EXCEPTIONS_A, "exceptions.a") AC_SUBST(EXCEPTIONS_EXCEPTIONS_A, "exceptions/exceptions.a") + AC_SUBST(RUNTIME_A, "runtime.a") + AC_SUBST(RUNTIME_RUNTIME_A, "runtime/runtime.a.") ]) AC_DEFINE_UNQUOTED(PLUGIN_SUFFIX, "$PLUGIN_SUFFIX", [Suffix for plugins]) AS_IF([test x"$PLUGIN_SUFFIX" != x""], [ AC_SUBST(OFPLUGIN_M, "OFPlugin.m") @@ -576,11 +537,11 @@ ]) ], [ AC_MSG_RESULT(no) ]) -AS_IF([test x"$objc_runtime" = x"Apple"], [ +AS_IF([test x"$objc_runtime" = x"Apple runtime"], [ AC_CHECK_HEADER(Foundation/NSObject.h, [ AC_SUBST(FOUNDATION_COMPAT_M, "foundation-compat.m") ]) ]) Index: extra.mk.in ================================================================== --- extra.mk.in +++ extra.mk.in @@ -24,9 +24,13 @@ OFSTREAMOBSERVER_SELECT_M = @OFSTREAMOBSERVER_SELECT_M@ OFTHREAD_M = @OFTHREAD_M@ OFTHREADTESTS_M = @OFTHREADTESTS_M@ PROPERTIESTESTS_M = @PROPERTIESTESTS_M@ REEXPORT_LIBOBJC = @REEXPORT_LIBOBJC@ +RUNTIME_A = @RUNTIME_A@ +RUNTIME_RUNTIME_A = @RUNTIME_RUNTIME_A@ +RUNTIME_RUNTIME_LIB_A = @RUNTIME_RUNTIME_LIB_A@ +RUNTIME_LIB_A = @RUNTIME_LIB_A@ TESTPLUGIN = @TESTPLUGIN@ TESTS = @TESTS@ TEST_LAUNCHER = @TEST_LAUNCHER@ THREADING_H = @THREADING_H@ Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -1,8 +1,8 @@ include ../extra.mk -SUBDIRS = exceptions +SUBDIRS = exceptions runtime SHARED_LIB = ${OBJFW_SHARED_LIB} STATIC_LIB = ${OBJFW_STATIC_LIB} LIB_MAJOR = ${OBJFW_LIB_MAJOR} LIB_MINOR = ${OBJFW_LIB_MINOR} @@ -98,11 +98,11 @@ ${OBJC_PROPERTIES_M} \ ${OBJC_SYNC_M} include ../buildsys.mk -CPPFLAGS += -I. -I.. -Iexceptions +CPPFLAGS += -I. -I.. -Iexceptions -Iruntime LD = ${OBJC} LDFLAGS += ${REEXPORT_LIBOBJC} ${MACH_ALIAS_LIST} -LIB_OBJS := ${LIB_OBJS} ${EXCEPTIONS_EXCEPTIONS_LIB_A} -OBJS += ${EXCEPTIONS_EXCEPTIONS_A} +LIB_OBJS := ${LIB_OBJS} ${EXCEPTIONS_EXCEPTIONS_LIB_A} ${RUNTIME_RUNTIME_LIB_A} +OBJS += ${EXCEPTIONS_EXCEPTIONS_A} ${RUNTIME_RUNTIME_A} Index: src/OFBlock.m ================================================================== --- src/OFBlock.m +++ src/OFBlock.m @@ -71,39 +71,18 @@ @protocol RetainRelease - retain; - (void)release; @end -#if defined(OF_OBJFW_RUNTIME) || defined(OF_GNU_RUNTIME) || \ - defined(OF_OLD_GNU_RUNTIME) -struct objc_abi_class { - struct objc_abi_metaclass *metaclass; - const char *superclass, *name; - unsigned long version, info, instance_size; - void *ivars, *methodlist, *dtable, *subclass_list, *sibling_class; - void *protocols, *gc_object_type; - long abi_version; - void *ivar_offsets, *properties; -}; - -struct objc_abi_metaclass { - const char *metaclass, *superclass, *name; - unsigned long version, info, instance_size; - void *ivars, *methodlist, *dtable, *subclass_list, *sibling_class; - void *protocols, *gc_object_type; - long abi_version; - void *ivar_offsets, *properties; -}; - #ifndef OF_OBJFW_RUNTIME -/* ObjFW-RT already defines those */ enum objc_abi_class_info { OBJC_CLASS_INFO_CLASS = 0x01, OBJC_CLASS_INFO_METACLASS = 0x02 }; #endif +#if defined(OF_OBJFW_RUNTIME) extern void __objc_exec_class(void*); /* Begin of ObjC module */ static struct objc_abi_metaclass _NSConcreteStackBlock_metaclass = { "OFBlock", "OFBlock", "OFStackBlock", 8, OBJC_CLASS_INFO_METACLASS, Index: src/OFIntrospection.m ================================================================== --- src/OFIntrospection.m +++ src/OFIntrospection.m @@ -16,14 +16,12 @@ #include "config.h" #include -#if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME) +#if defined(OF_APPLE_RUNTIME) # import -#elif defined(OF_OLD_GNU_RUNTIME) -# import #endif #import "OFIntrospection.h" #import "OFString.h" #import "OFArray.h" @@ -30,11 +28,11 @@ #import "OFAutoreleasePool.h" #import "macros.h" @implementation OFMethod -#if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME) +#if defined(OF_APPLE_RUNTIME) - _initWithMethod: (Method)method { self = [super init]; @try { @@ -46,28 +44,10 @@ } @catch (id e) { [self release]; @throw e; } - return self; -} -#elif defined(OF_OLD_GNU_RUNTIME) -- _initWithMethod: (Method_t)method -{ - self = [super init]; - - @try { - selector = method->method_name; - name = [[OFString alloc] - initWithCString: sel_get_name(selector) - encoding: OF_STRING_ENCODING_ASCII]; - typeEncoding = method->method_types; - } @catch (id e) { - [self release]; - @throw e; - } - return self; } #endif - (void)dealloc @@ -98,11 +78,11 @@ name, typeEncoding]; } @end @implementation OFInstanceVariable -#if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME) +#if defined(OF_APPLE_RUNTIME) - _initWithIvar: (Ivar)ivar { self = [super init]; @try { @@ -114,28 +94,10 @@ } @catch (id e) { [self release]; @throw e; } - return self; -} -#elif defined(OF_OLD_GNU_RUNTIME) -- _initWithIvar: (Ivar_t)ivar -{ - self = [super init]; - - @try { - name = [[OFString alloc] - initWithCString: ivar->ivar_name - encoding: OF_STRING_ENCODING_ASCII]; - offset = ivar->ivar_offset; - typeEncoding = ivar->ivar_type; - } @catch (id e) { - [self release]; - @throw e; - } - return self; } #endif - (void)dealloc @@ -170,11 +132,11 @@ #ifdef OF_HAVE_PROPERTIES @implementation OFProperty @synthesize name, attributes; -#if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME) +#if defined(OF_APPLE_RUNTIME) - _initWithProperty: (objc_property_t)property { self = [super init]; @try { @@ -220,29 +182,27 @@ { self = [super init]; @try { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; -#if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME) +#if defined(OF_APPLE_RUNTIME) Method *methodList; Ivar *ivarList; # ifdef OF_HAVE_PROPERTIES objc_property_t *propertyList; # endif unsigned i, count; -#elif defined(OF_OLD_GNU_RUNTIME) - MethodList_t methodList; #endif classMethods = [[OFMutableArray alloc] init]; instanceMethods = [[OFMutableArray alloc] init]; instanceVariables = [[OFMutableArray alloc] init]; #ifdef OF_HAVE_PROPERTIES properties = [[OFMutableArray alloc] init]; #endif -#if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME) +#if defined(OF_APPLE_RUNTIME) methodList = class_copyMethodList(((OFObject*)class)->isa, &count); @try { for (i = 0; i < count; i++) { [classMethods addObject: [[[OFMethod alloc] @@ -288,46 +248,10 @@ [pool releaseObjects]; } } @finally { free(propertyList); } -#elif defined(OF_OLD_GNU_RUNTIME) - for (methodList = class->class_pointer->methods; - methodList != NULL; methodList = methodList->method_next) { - int i; - - for (i = 0; i < methodList->method_count; i++) { - [classMethods addObject: [[[OFMethod alloc] - _initWithMethod: - &methodList->method_list[i]] autorelease]]; - [pool releaseObjects]; - } - } - - for (methodList = class->methods; methodList != NULL; - methodList = methodList->method_next) { - int i; - - for (i = 0; i < methodList->method_count; i++) { - [instanceMethods addObject: [[[OFMethod alloc] - _initWithMethod: - &methodList->method_list[i]] autorelease]]; - [pool releaseObjects]; - } - } - - if (class->ivars != NULL) { - int i; - - for (i = 0; i < class->ivars->ivar_count; i++) { - [instanceVariables addObject: - [[[OFInstanceVariable alloc] - _initWithIvar: class->ivars->ivar_list + i] - autorelease]]; - [pool releaseObjects]; - } - } #endif [classMethods makeImmutable]; [instanceMethods makeImmutable]; [instanceVariables makeImmutable]; Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -26,11 +26,11 @@ #include #include #include #ifdef OF_OBJFW_RUNTIME -# import +# import "runtime.h" #else # import #endif #define OF_RETAIN_COUNT_MAX UINT_MAX Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -38,16 +38,14 @@ #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "macros.h" -#if (defined(OF_APPLE_RUNTIME) && __OBJC2__) || defined(OF_GNU_RUNTIME) +#if (defined(OF_APPLE_RUNTIME) && __OBJC2__) # import #elif defined(OF_OBJFW_RUNTIME) -# import -#elif defined(OF_OLD_GNU_RUNTIME) -# import +# import "runtime.h" #endif #ifdef _WIN32 # include #endif @@ -76,14 +74,10 @@ #define PRE_IVAR_ALIGN ((sizeof(struct pre_ivar) + \ (__BIGGEST_ALIGNMENT__ - 1)) & ~(__BIGGEST_ALIGNMENT__ - 1)) #define PRE_IVAR ((struct pre_ivar*)(void*)((char*)self - PRE_IVAR_ALIGN)) -#ifdef OF_OLD_GNU_RUNTIME -extern void __objc_update_dispatch_table_for_class(Class); -#endif - static struct { Class isa; } alloc_failed_exception; static Class autoreleasePool = Nil; @@ -98,11 +92,11 @@ #ifdef NEED_OBJC_PROPERTIES_INIT extern BOOL objc_properties_init(); #endif -#if (defined(OF_APPLE_RUNTIME) && __OBJC2__) || defined(OF_GNU_RUNTIME) +#if (defined(OF_APPLE_RUNTIME) && __OBJC2__) static void uncaught_exception_handler(id exception) { fprintf(stderr, "\nUnhandled exception:\n%s\n", [[exception description] UTF8String]); @@ -123,51 +117,17 @@ { enumeration_mutation_handler(object); } #endif -#if defined(HAVE_OBJC_ENUMERATIONMUTATION) && defined(OF_OLD_GNU_RUNTIME) -extern void objc_setEnumerationMutationHandler(void(*handler)(id)); -#endif - const char* _NSPrintForDebugger(id object) { return [[object description] cStringWithEncoding: OF_STRING_ENCODING_NATIVE]; } -#ifdef OF_OLD_GNU_RUNTIME -static BOOL -protocol_conformsToProtocol(Protocol *a, Protocol *b) -{ - /* - * This function is an ugly workaround for a bug that only happens with - * Clang 2.9 together with the libobjc from GCC 4.6. - * Since the instance variables of Protocol are @private, we have to - * cast them to a struct here in order to access them. - */ - struct objc_protocol { - Class isa; - const char *protocol_name; - struct objc_protocol_list *protocol_list; - } *pa = (struct objc_protocol*)a, *pb = (struct objc_protocol*)b; - struct objc_protocol_list *pl; - size_t i; - - if (!strcmp(pa->protocol_name, pb->protocol_name)) - return YES; - - for (pl = pa->protocol_list; pl != NULL; pl = pl->next) - for (i = 0; i < pl->count; i++) - if (protocol_conformsToProtocol(pl->list[i], b)) - return YES; - - return NO; -} -#endif - /* References for static linking */ void _references_to_categories_of_OFObject(void) { _OFObject_Serialization_reference = 1; } @@ -188,11 +148,11 @@ stderr); abort(); } #endif -#if (defined(OF_APPLE_RUNTIME) && __OBJC2__) || defined(OF_GNU_RUNTIME) +#if (defined(OF_APPLE_RUNTIME) && __OBJC2__) objc_setUncaughtExceptionHandler(uncaught_exception_handler); #endif #ifdef HAVE_OBJC_ENUMERATIONMUTATION objc_setEnumerationMutationHandler(enumeration_mutation_handler); @@ -300,49 +260,28 @@ return class_getSuperclass(self); } + (BOOL)instancesRespondToSelector: (SEL)selector { -#ifdef OF_OLD_GNU_RUNTIME - return class_get_instance_method(self, selector) != METHOD_NULL; -#else return class_respondsToSelector(self, selector); -#endif } + (BOOL)conformsToProtocol: (Protocol*)protocol { -#ifdef OF_OLD_GNU_RUNTIME - Class c; - struct objc_protocol_list *pl; - size_t i; - - for (c = self; c != Nil; c = class_get_super_class(c)) - for (pl = c->protocols; pl != NULL; pl = pl->next) - for (i = 0; i < pl->count; i++) - if (protocol_conformsToProtocol(pl->list[i], - 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 { #if defined(OF_OBJFW_RUNTIME) return objc_get_instance_method(self, selector); -#elif defined(OF_OLD_GNU_RUNTIME) - return method_get_imp(class_get_instance_method(self, selector)); #else return class_getMethodImplementation(self, selector); #endif } @@ -354,19 +293,10 @@ if ((ret = objc_get_type_encoding(self, selector)) == NULL) @throw [OFNotImplementedException exceptionWithClass: self selector: selector]; return ret; -#elif defined(OF_OLD_GNU_RUNTIME) - Method_t m; - - if ((m = class_get_instance_method(self, selector)) == NULL || - m->method_types == NULL) - @throw [OFNotImplementedException exceptionWithClass: self - selector: selector]; - - return m->method_types; #else Method m; const char *ret; if ((m = class_getInstanceMethod(self, selector)) == NULL || @@ -390,44 +320,10 @@ if (newImp == (IMP)0 || !class_respondsToSelector(self->isa, selector)) @throw [OFInvalidArgumentException exceptionWithClass: self selector: _cmd]; return objc_replace_class_method(self, selector, newImp); -#elif defined(OF_OLD_GNU_RUNTIME) - Method_t method; - MethodList_t iter; - - method = class_get_class_method(self->class_pointer, selector); - - if (newImp == (IMP)0 || method == METHOD_NULL) - @throw [OFInvalidArgumentException exceptionWithClass: self - selector: _cmd]; - - for (iter = ((Class)self->class_pointer)->methods; iter != NULL; - iter = iter->method_next) { - int i; - - for (i = 0; i < iter->method_count; i++) - if (sel_eq(iter->method_list[i].method_name, - selector)) { - IMP oldImp; - - oldImp = iter->method_list[i].method_imp; - iter->method_list[i].method_imp = newImp; - - __objc_update_dispatch_table_for_class( - (Class)self->class_pointer); - - return oldImp; - } - } - - assert([self addClassMethod: selector - withTypeEncoding: method->method_types - implementation: newImp]); - - return (IMP)0; #else Method method; if (newImp == (IMP)0 || (method = class_getClassMethod(self, selector)) == NULL) @@ -465,43 +361,10 @@ if (newImp == (IMP)0 || !class_respondsToSelector(self, selector)) @throw [OFInvalidArgumentException exceptionWithClass: self selector: _cmd]; return objc_replace_instance_method(self, selector, newImp); -#elif defined(OF_OLD_GNU_RUNTIME) - Method_t method; - MethodList_t iter; - - method = class_get_instance_method(self, selector); - - if (newImp == (IMP)0 || method == METHOD_NULL) - @throw [OFInvalidArgumentException exceptionWithClass: self - selector: _cmd]; - - for (iter = ((Class)self)->methods; iter != NULL; - iter = iter->method_next) { - int i; - - for (i = 0; i < iter->method_count; i++) - if (sel_eq(iter->method_list[i].method_name, - selector)) { - IMP oldImp; - - oldImp = iter->method_list[i].method_imp; - iter->method_list[i].method_imp = newImp; - - __objc_update_dispatch_table_for_class(self); - - return oldImp; - } - } - - assert([self addInstanceMethod: selector - withTypeEncoding: method->method_types - implementation: newImp]); - - return (IMP)0; #else Method method; if (newImp == (IMP)0 || (method = class_getInstanceMethod(self, selector)) == NULL) @@ -530,88 +393,22 @@ + (BOOL)addInstanceMethod: (SEL)selector withTypeEncoding: (const char*)typeEncoding implementation: (IMP)implementation { -#if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME) +#if defined(OF_APPLE_RUNTIME) return class_addMethod(self, selector, implementation, typeEncoding); -#elif defined(OF_OLD_GNU_RUNTIME) - MethodList_t methodList; - - for (methodList = ((Class)self)->methods; methodList != NULL; - methodList = methodList->method_next) { - int i; - - for (i = 0; i < methodList->method_count; i++) - if (sel_eq(methodList->method_list[i].method_name, - selector)) - return NO; - } - - if ((methodList = malloc(sizeof(*methodList))) == NULL) - @throw [OFOutOfMemoryException - exceptionWithClass: self - requestedSize: sizeof(*methodList)]; - - methodList->method_next = ((Class)self)->methods; - methodList->method_count = 1; - - methodList->method_list[0].method_name = selector; - methodList->method_list[0].method_types = typeEncoding; - methodList->method_list[0].method_imp = implementation; - - ((Class)self)->methods = methodList; - - __objc_update_dispatch_table_for_class(self); - - return YES; -#else - @throw [OFNotImplementedException exceptionWithClass: self - selector: _cmd]; #endif } + (BOOL)addClassMethod: (SEL)selector withTypeEncoding: (const char*)typeEncoding implementation: (IMP)implementation { -#if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME) +#if defined(OF_APPLE_RUNTIME) return class_addMethod(((OFObject*)self)->isa, selector, implementation, typeEncoding); -#elif defined(OF_OLD_GNU_RUNTIME) - MethodList_t methodList; - - for (methodList = ((Class)self->class_pointer)->methods; - methodList != NULL; methodList = methodList->method_next) { - int i; - - for (i = 0; i < methodList->method_count; i++) - if (sel_eq(methodList->method_list[i].method_name, - selector)) - return NO; - } - - if ((methodList = malloc(sizeof(*methodList))) == NULL) - @throw [OFOutOfMemoryException - exceptionWithClass: self - requestedSize: sizeof(*methodList)]; - - methodList->method_next = ((Class)self->class_pointer)->methods; - methodList->method_count = 1; - - methodList->method_list[0].method_name = selector; - methodList->method_list[0].method_types = typeEncoding; - methodList->method_list[0].method_imp = implementation; - - ((Class)self->class_pointer)->methods = methodList; - - __objc_update_dispatch_table_for_class((Class)self->class_pointer); - - return YES; -#else - @throw [OFNotImplementedException exceptionWithClass: self - selector: _cmd]; #endif } + (void)inheritMethodsFromClass: (Class)class { @@ -618,11 +415,11 @@ Class superclass = [self superclass]; if ([self isSubclassOfClass: class]) return; -#if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME) +#if defined(OF_APPLE_RUNTIME) Method *methodList; unsigned i, count; methodList = class_copyMethodList(((OFObject*)class)->isa, &count); @try { @@ -682,76 +479,12 @@ } } } @finally { free(methodList); } -#elif defined(OF_OLD_GNU_RUNTIME) - MethodList_t methodList; - - for (methodList = class->class_pointer->methods; - methodList != NULL; methodList = methodList->method_next) { - int i; - - for (i = 0; i < methodList->method_count; i++) { - SEL selector = methodList->method_list[i].method_name; - IMP implementation; - - /* - * Don't replace methods implemented in receiving class. - */ - if ([self methodForSelector: selector] != - [superclass methodForSelector: selector]) - continue; - - implementation = [class methodForSelector: selector]; - - if ([self respondsToSelector: selector]) - [self setImplementation: implementation - forClassMethod: selector]; - else { - const char *typeEncoding = - methodList->method_list[i].method_types; - [self addClassMethod: selector - withTypeEncoding: typeEncoding - implementation: implementation]; - } - } - } - - for (methodList = class->methods; methodList != NULL; - methodList = methodList->method_next) { - int i; - - for (i = 0; i < methodList->method_count; i++) { - SEL selector = methodList->method_list[i].method_name; - IMP implementation; - - /* - * Don't replace methods implemented in receiving class. - */ - if ([self instanceMethodForSelector: selector] != - [superclass instanceMethodForSelector: selector]) - continue; - - implementation = - [class instanceMethodForSelector: selector]; - - if ([self instancesRespondToSelector: selector]) - [self setImplementation: implementation - forInstanceMethod: selector]; - else { - const char *typeEncoding = - methodList->method_list[i].method_types; - [self addInstanceMethod: selector - withTypeEncoding: typeEncoding - implementation: implementation]; - } - } - } #else - @throw [OFNotImplementedException exceptionWithClass: self - selector: _cmd]; + /* FIXME */ #endif [self inheritMethodsFromClass: [class superclass]]; } @@ -787,28 +520,21 @@ return (isa == class); } - (BOOL)respondsToSelector: (SEL)selector { -#ifdef OF_OLD_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 { return [isa conformsToProtocol: protocol]; } - (IMP)methodForSelector: (SEL)selector { -#if defined(OF_OBJFW_RUNTIME) || defined(OF_OLD_GNU_RUNTIME) +#if defined(OF_OBJFW_RUNTIME) return objc_msg_lookup(self, selector); #else return class_getMethodImplementation(isa, selector); #endif } @@ -847,19 +573,10 @@ if ((ret = objc_get_type_encoding(isa, selector)) == NULL) @throw [OFNotImplementedException exceptionWithClass: isa selector: selector]; return ret; -#elif defined(OF_OLD_GNU_RUNTIME) - Method_t m; - - if ((m = class_get_instance_method(isa, selector)) == NULL || - m->method_types == NULL) - @throw [OFNotImplementedException exceptionWithClass: isa - selector: selector]; - - return m->method_types; #else Method m; const char *ret; if ((m = class_getInstanceMethod(isa, selector)) == NULL || Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -25,14 +25,10 @@ # include #else # include #endif -#if defined(OF_GNU_RUNTIME) || defined(OF_OLD_GNU_RUNTIME) -# import -#endif - #import "OFThread.h" #import "OFList.h" #import "OFDate.h" #import "OFAutoreleasePool.h" @@ -59,14 +55,10 @@ static id call_main(id object) { OFThread *thread = (OFThread*)object; -#if defined(OF_GNU_RUNTIME) || defined(OF_OLD_GNU_RUNTIME) - objc_thread_add(); -#endif - if (!of_tlskey_set(threadSelf, thread)) @throw [OFInitializationFailedException exceptionWithClass: [thread class]]; /* @@ -89,14 +81,10 @@ [OFTLSKey callAllDestructors]; [OFAutoreleasePool _releaseAll]; [thread release]; -#if defined(OF_GNU_RUNTIME) || defined(OF_OLD_GNU_RUNTIME) - objc_thread_remove(); -#endif - return 0; } @implementation OFThread #if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS) @@ -225,14 +213,10 @@ [OFTLSKey callAllDestructors]; [OFAutoreleasePool _releaseAll]; [thread release]; -#if defined(OF_GNU_RUNTIME) || defined(OF_OLD_GNU_RUNTIME) - objc_thread_remove(); -#endif - of_thread_exit(); } - initWithObject: (id)object_ { Index: src/base64.h ================================================================== --- src/base64.h +++ src/base64.h @@ -22,11 +22,11 @@ #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif #ifdef OF_OBJFW_RUNTIME -# import +# import "runtime.h" #else # import #endif @class OFString; Index: src/macros.h ================================================================== --- src/macros.h +++ src/macros.h @@ -17,14 +17,12 @@ #import "OFObject.h" #include #include -#if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME) +#if defined(OF_APPLE_RUNTIME) # import -#elif defined(OF_OLD_GNU_RUNTIME) -# import #endif #ifdef _PSP # define INTMAX_MAX LONG_LONG_MAX #endif @@ -74,22 +72,14 @@ # elif defined(__arm__) || defined(__ARM__) # define OF_ARM_ASM # endif #endif -#if defined(OF_OLD_GNU_RUNTIME) || defined(OF_OBJFW_RUNTIME) +#ifdef OF_OBJFW_RUNTIME # define objc_lookUpClass objc_lookup_class #endif -#ifdef OF_OLD_GNU_RUNTIME -# define class_getInstanceSize class_get_instance_size -# define class_getName class_get_class_name -# define class_getSuperclass class_get_super_class -# define sel_getName sel_get_name -# define sel_registerName sel_get_uid -#endif - #ifndef _WIN32 # define OF_PATH_DELIMITER '/' #else # define OF_PATH_DELIMITER '\\' #endif Index: src/objc_sync.m ================================================================== --- src/objc_sync.m +++ src/objc_sync.m @@ -21,11 +21,11 @@ #include #include #ifdef OF_OBJFW_RUNTIME -# import +# import "runtime.h" #else # import #endif #import "threading.h" ADDED src/runtime/Makefile Index: src/runtime/Makefile ================================================================== --- src/runtime/Makefile +++ src/runtime/Makefile @@ -0,0 +1,9 @@ +include ../../extra.mk + +STATIC_PIC_LIB_NOINST = ${RUNTIME_LIB_A} +STATIC_LIB_NOINST = ${RUNTIME_A} + +include ../../buildsys.mk + +CPPFLAGS += -I. -I.. -I../.. +LD = ${OBJC}