Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -12,11 +12,10 @@ CPP="$OBJCPP" CPPFLAGS="$CPPFLAGS $OBJCPPFLAGS" OBJCFLAGS="$OBJCFLAGS -Wall -fexceptions -fobjc-exceptions" OBJCFLAGS="$OBJCFLAGS -fconstant-string-class=OFConstString" -LIBS="$LIBS -lobjc" AX_CHECK_COMPILER_FLAGS(-pipe, [OBJCFLAGS="$OBJCFLAGS -pipe"]) AX_CHECK_COMPILER_FLAGS(-fno-common, [OBJCFLAGS="$OBJCFLAGS -fno-common"]) AX_CHECK_COMPILER_FLAGS(-fno-constant-cfstrings, [ NO_CONST_CFSTRINGS="-fno-constant-cfstrings" @@ -55,26 +54,51 @@ AC_DEFINE(OF_HAVE_PROPERTIES, 1, [Compiler support for properties]) AC_SUBST(PROPERTIES_M, "properties.m") AC_MSG_RESULT(yes) ], [ AC_MSG_RESULT(no)]) + +AC_CHECK_HEADERS([objfw-rt.h objc/objc.h]) + +test x"$ac_cv_header_objfw_rt_h" = x"yes" && objc_runtime="ObjFW-RT" + +if test x"$ac_cv_header_objc_objc_h" = x"yes"; then + dnl TODO: This is ugly. Let's think of a better check. + AC_EGREP_CPP(gnu, [ + #import + #ifdef __objc_INCLUDE_GNU + gnu + #endif + ], + [test x"$objc_runtime" = "x" && objc_runtime="GNU"], + [objc_runtime="Apple"]) +fi AC_MSG_CHECKING(which Objective C runtime we use) -dnl TODO: This is ugly. Let's think of a better check. -AC_EGREP_CPP(gnu, [ - #import - #ifdef __objc_INCLUDE_GNU - gnu - #endif - ], [ - AC_DEFINE(OF_GNU_RUNTIME, 1, [Whether we use the GNU ObjC runtime]) - AC_SUBST(RUNTIME_DEF, "-DOF_GNU_RUNTIME") - objc_runtime="GNU" - ], [ - AC_DEFINE(OF_APPLE_RUNTIME, 1, [Whether we use the Apple ObjC runtime]) - AC_SUBST(RUNTIME_DEF, "-DOF_APPLE_RUNTIME") - objc_runtime="Apple"]) +case $objc_runtime in + ObjFW-RT) + AC_DEFINE(OF_OBJFW_RUNTIME, 1, + [Whether we use the ObjFW runtime]) + AC_SUBST(GNU_RUNTIME, "-fgnu-runtime") + OBJCFLAGS="$OBJCFLAGS -fgnu-runtime" + LIBS="$LIBS -lobjfw-rt" + ;; + Apple) + AC_DEFINE(OF_APPLE_RUNTIME, 1, + [Whether we use the Apple ObjC runtime]) + LIBS="$LIBS -lobjc" + ;; + GNU) + AC_DEFINE(OF_GNU_RUNTIME, 1, + [Whether we use the GNU ObjC runtime]) + LIBS="$LIBS -lobjc" + ;; + *) + AC_MSG_RESULT(none) + AC_MSG_ERROR(No ObjC runtime found! Please install ObjFW-RT!) + ;; +esac AC_MSG_RESULT($objc_runtime) AC_CHECK_FUNC(objc_getProperty,, [ AC_DEFINE(NEED_OBJC_PROPERTIES_INIT, 1, [Whether objc_properties_init needs to be called]) @@ -374,5 +398,12 @@ AC_SUBST(PACKAGE, ObjFW) AC_CONFIG_FILES([buildsys.mk extra.mk objfw-config]) AC_CONFIG_HEADERS([config.h src/objfw-defs.h]) AC_OUTPUT + +if test x"$objc_runtime" = x"GNU"; then + echo + echo "Warning: You are using GNU libobjc! Support for GNU libobjc will " + echo "be dropped in the next version! You should upgrade to ObjFW-RT" + echo "(the ObjFW runtime) instead!" +fi Index: objfw-config.in ================================================================== --- objfw-config.in +++ objfw-config.in @@ -3,11 +3,12 @@ exec_prefix="@exec_prefix@" libdir="@libdir@" CFLAGS="" CPPFLAGS="-I@includedir@" CXXFLAGS="" -OBJCFLAGS="-fexceptions -fobjc-exceptions -fconstant-string-class=OFConstString" +OBJCFLAGS="@GNU_RUNTIME@ -fexceptions -fobjc-exceptions" +OBJCFLAGS="$OBJCFLAGS -fconstant-string-class=OFConstString" OBJCFLAGS="$OBJCFLAGS @NO_CONST_CFSTRINGS@ @NO_WARN_UNUSED@ @ATOMIC_OBJCFLAGS@" LDFLAGS="" LDFLAGS_RPATH="@LDFLAGS_RPATH@" LIBS="-L${libdir} -lobjfw @LIBS@" VERSION="0.3-dev" Index: src/OFExceptions.m ================================================================== --- src/OFExceptions.m +++ src/OFExceptions.m @@ -14,16 +14,18 @@ #define _GNU_SOURCE #include #include #include -#import #ifdef OF_APPLE_RUNTIME # import -# define SEL_NAME(x) sel_getName(x) -#else -# define SEL_NAME(x) sel_get_name(x) +# import +#endif + +#ifdef OF_GNU_RUNTIME +# import +# define sel_getName(x) sel_get_name(x) #endif #import "OFExceptions.h" #import "OFString.h" #import "OFTCPSocket.h" @@ -242,11 +244,11 @@ if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"The method %s of class %s is not or not fully implemented!", - SEL_NAME(selector), [class_ className]]; + sel_getName(selector), [class_ className]]; return string; } @end @@ -292,11 +294,11 @@ if (string != nil) return string; string = [[OFString alloc] initWithFormat: @"The argument for method %s of class %s is invalid!", - SEL_NAME(selector), [class_ className]]; + sel_getName(selector), [class_ className]]; return string; } @end Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -12,11 +12,15 @@ #import "objfw-defs.h" #include #include -#import +#ifdef OF_OBJFW_RUNTIME +# import +#else +# import +#endif /** * \brief A result of a comparison. */ typedef enum __of_comparison_result { Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -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 { Index: src/objc_sync.m ================================================================== --- src/objc_sync.m +++ src/objc_sync.m @@ -13,11 +13,15 @@ #include #include #include -#import +#ifdef OF_OBJFW_RUNTIME +# import +#else +# import +#endif #import "threading.h" /// \cond internal struct locks_s { Index: src/objfw-defs.h.in ================================================================== --- src/objfw-defs.h.in +++ src/objfw-defs.h.in @@ -6,8 +6,9 @@ #undef OF_HAVE_GCC_ATOMIC_OPS #undef OF_HAVE_LIBKERN_OSATOMIC_H #undef OF_HAVE_PTHREADS #undef OF_HAVE_PTHREAD_SPINLOCKS #undef OF_HAVE_SCHED_YIELD +#undef OF_OBJFW_RUNTIME #undef OF_PLUGINS #undef OF_THREADS #undef SIZE_MAX