From dfa14d5d340c317c21525bed42cabf82b8601825 Mon Sep 17 00:00:00 2001 From: theraven Date: Mon, 25 Jan 2010 15:35:08 +0000 Subject: [PATCH] Made Object less magic. For now, because there are some weird people who want to use Objective-C without Foundation, Object is still included. If you compile without defining GNUSTEP (which GNUstep Make does automatically) then you get the old behaviour. If you build with GNUSTEP defined: +load will not be sent until both NSObject and NSConstantString have been seen. NSObject will be set as the superclass for all metaclasses, not Object. This is in line with Cocoa and should make it a bit easier for people porting code who have categories on NSObject and are confused that they don't work as expected. Object and NXConstantString are now deprecated. They're staying here because I use them for producing reduced test cases for the runtime and compiler, but they shouldn't be used. I will probably remove them from the default build soon. --- class.c | 5 ++++- init.c | 5 +++-- magic_objects.h | 7 +++++++ 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 magic_objects.h diff --git a/class.c b/class.c index b844ead..5a40e75 100644 --- a/class.c +++ b/class.c @@ -94,6 +94,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "objc/objc-api.h" #include "lock.h" +#include "magic_objects.h" #include @@ -230,13 +231,15 @@ void __objc_resolve_class_links (void) { void *es = NULL; - Class object_class = objc_get_class ("Object"); + Class object_class = objc_get_class (ROOT_OBJECT_CLASS_NAME); + fprintf(stderr, "Using root class: %s\n", ROOT_OBJECT_CLASS_NAME); Class class1; assert (object_class); LOCK(__objc_runtime_mutex); + /* Assign subclass links. */ while ((class1 = class_table_next (&es))) { diff --git a/init.c b/init.c index 27588ea..edb4c97 100644 --- a/init.c +++ b/init.c @@ -28,6 +28,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "objc/runtime-legacy.h" #include "objc/encoding.h" #include "lock.h" +#include "magic_objects.h" /* The version number of this runtime. This must match the number defined in gcc (objc-act.c). */ @@ -837,8 +838,8 @@ objc_send_load (void) /* Special check to allow creating and sending messages to constant strings in +load methods. If these classes are not yet known, even if all the other classes are known, delay sending of +load. */ - if (! objc_lookup_class ("NXConstantString") || - ! objc_lookup_class ("Object")) + if (! objc_lookup_class (CONSTANT_STRING_CLASS) || + ! objc_lookup_class (ROOT_OBJECT_CLASS_NAME)) return; /* Iterate over all modules in the __objc_module_list and call on diff --git a/magic_objects.h b/magic_objects.h new file mode 100644 index 0000000..2b483a6 --- /dev/null +++ b/magic_objects.h @@ -0,0 +1,7 @@ +#ifdef GNUSTEP +static const char *ROOT_OBJECT_CLASS_NAME = "NSObject"; +static const char *CONSTANT_STRING_CLASS = "NSConstantString"; +#else +static const char *ROOT_OBJECT_CLASS_NAME = "Object"; +static const char *CONSTANT_STRING_CLASS = "NXConstantString"; +#endif