From 85549433db976ef36b3cb5458b43b9c14f925104 Mon Sep 17 00:00:00 2001 From: theraven Date: Thu, 9 Sep 2010 15:06:09 +0000 Subject: [PATCH] A huge blob of changes to make -base build with libobjc2, without using the old libobjc2 headers. Most of these changes involve simply removing direct manipulation of any runtime structures and replacing them with runtime function calls. For example class->name becomes class_getName(class) and so on. libobjc2, like the Apple runtime, the NeXT runtime, and every version of the Objective-C spec, calls the class pointer in id isa. A few files now have #define class_pointer isa at the top. This line replaces class_pointer in the old GNU libobjc headers with isa so either class_pointer or isa can be used for accessing the class of an object. Note: object_getClass() should be used in most cases because, in some future version of the runtime, this will skip things like lock classes and other hidden classes (e.g. KVO classes). All of the old forwarding stuff has been removed. Most of this stuff followed convoluted code paths that ended with an exception. A few simply broke in exciting ways. Hopefully no one has used them for the last ten years or so, but we can bring them back with some #ifndef stuff if they're really needed by anyone. There is currently a bug in configure, which prevents dladdr() from being detected, so you need to manually tweak config.h to build - I have not fixed the fall-back code in objc-load.m to work with libobjc2, I just added a new version that uses the loader's functionality directly. Although -base now builds, it builds with a lot of warnings. is missing from a lot of files, so memcpy() and strlen() generate implicit function declaration warnings. Additionally, libobjc2 does still provide the sel_{get,register}_*() functions, but they're wrappers around the newer API ones. These are deprecated and are not exposed in the headers. Although they work, we should be replacing them with the libobjc2 versions as soon as possible. This incorporates a patch by Eric. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31265 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 37 ++++ .../GNUstepBase/DistributedObjects.h | 3 - Headers/Foundation/NSInvocation.h | 2 - Source/Additions/GSXML.m | 1 + Source/GSFFIInvocation.m | 37 ++-- Source/GSPrivate.h | 4 + Source/NSBundle.m | 24 ++- Source/NSConnection.m | 20 +- Source/NSCopyObject.m | 5 +- Source/NSDebug.m | 8 +- Source/NSDistantObject.m | 85 ++------ Source/NSInvocation.m | 38 ---- Source/NSMethodSignature.m | 1 + Source/NSObjCRuntime.m | 2 +- Source/NSObject.m | 197 +++--------------- Source/NSProtocolChecker.m | 141 +------------ Source/NSProxy.m | 21 +- Source/NSSerializer.m | 16 -- 18 files changed, 141 insertions(+), 501 deletions(-) diff --git a/ChangeLog b/ChangeLog index 270ee025d..c95082088 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,40 @@ +2010-09-02 9avid Chisnall + + * Source/NSBundle.m + * Source/NSMethodSignature.m + * Source/NSDebug.m + * Source/GSFFIInvocation.m + * Source/GSPrivate.h + * Source/NSInvocation.m + * Source/NSCopyObject.m + * Source/NSObject.m + * Source/Additions/GSXML.m + * Source/Additions/GSObjCRuntime.m + * Source/NSConnection.m + * Source/NSObjCRuntime.m + * Source/NSProxy.m + * Source/NSProtocolChecker.m + * Source/NSSerializer.m + * Source/NSDistantObject.m + * Headers/Foundation/NSInvocation.h + * Headers/Additions/GNUstepBase/DistributedObjects.h + + A huge blob of changes to make -base build with libobjc2, without using the old libobjc2 headers. + + Most of these changes involve simply removing direct manipulation of any runtime structures and replacing them with runtime function calls. For example class->name becomes class_getName(class) and so on. + + libobjc2, like the Apple runtime, the NeXT runtime, and every version of the Objective-C spec, calls the class pointer in id isa. A few files now have #define class_pointer isa at the top. This line replaces class_pointer in the old GNU libobjc headers with isa so either class_pointer or isa can be used for accessing the class of an object. Note: object_getClass() should be used in most cases because, in some future version of the runtime, this will skip things like lock classes and other hidden classes (e.g. KVO classes). + + All of the old forwarding stuff has been removed. Most of this stuff followed convoluted code paths that ended with an exception. A few simply broke in exciting ways. Hopefully no one has used them for the last ten years or so, but we can bring them back with some #ifndef stuff if they're really needed by anyone. + + There is currently a bug in configure, which prevents dladdr() from being detected, so you need to manually tweak config.h to build - I have not fixed the fall-back code in objc-load.m to work with libobjc2, I just added a new version that uses the loader's functionality directly. + + Although -base now builds, it builds with a lot of warnings. is missing from a lot of files, so memcpy() and strlen() generate implicit function declaration warnings. + + Additionally, libobjc2 does still provide the sel_{get,register}_*() functions, but they're wrappers around the newer API ones. These are deprecated and are not exposed in the headers. Although they work, we should be replacing them with the libobjc2 versions as soon as possible. + + This incorporates a patch by Eric. + 2010-09-08 Eric Wasylishen * Source/ObjectiveC2/runtime.h: diff --git a/Headers/Additions/GNUstepBase/DistributedObjects.h b/Headers/Additions/GNUstepBase/DistributedObjects.h index a6c52a4c1..e553496af 100644 --- a/Headers/Additions/GNUstepBase/DistributedObjects.h +++ b/Headers/Additions/GNUstepBase/DistributedObjects.h @@ -76,9 +76,6 @@ enum { - (NSDistantObject*) proxyForTarget: (unsigned)target; - (void) retainTarget: (unsigned)target; -- (retval_t) forwardForProxy: (NSDistantObject*)object - selector: (SEL)sel - argFrame: (arglist_t)argframe; - (void) forwardInvocation: (NSInvocation *)inv forProxy: (NSDistantObject*)object; - (const char *) typeForSelector: (SEL)sel remoteTarget: (unsigned)target; diff --git a/Headers/Foundation/NSInvocation.h b/Headers/Foundation/NSInvocation.h index e9b18e64c..a7e4420e0 100644 --- a/Headers/Foundation/NSInvocation.h +++ b/Headers/Foundation/NSInvocation.h @@ -120,9 +120,7 @@ extern "C" { + (id) _newProxyForInvocation: (id)target; + (id) _newProxyForMessage: (id)target; + (NSInvocation*) _returnInvocationAndDestroyProxy: (id)proxy; -- (id) initWithArgframe: (arglist_t)frame selector: (SEL)aSelector; - (id) initWithMethodSignature: (NSMethodSignature*)aSignature; -- (void*) returnFrame: (arglist_t)argFrame; @end /** diff --git a/Source/Additions/GSXML.m b/Source/Additions/GSXML.m index be8aec901..2ac27f906 100644 --- a/Source/Additions/GSXML.m +++ b/Source/Additions/GSXML.m @@ -40,6 +40,7 @@ */ +#include #import "common.h" #import "GNUstepBase/preface.h" #import "GNUstepBase/Unicode.h" diff --git a/Source/GSFFIInvocation.m b/Source/GSFFIInvocation.m index f962e6fab..11502df64 100644 --- a/Source/GSFFIInvocation.m +++ b/Source/GSFFIInvocation.m @@ -22,6 +22,8 @@ Boston, MA 02111 USA. */ +#define class_pointer isa + #import "common.h" #define EXPOSE_NSInvocation_IVARS 1 #import "Foundation/NSException.h" @@ -68,7 +70,7 @@ gs_method_for_receiver_and_selector (id receiver, SEL sel) YES); } - return METHOD_NULL; + return 0; } @@ -118,6 +120,7 @@ gs_find_best_typed_sel (SEL sel) static INLINE SEL gs_find_by_receiver_best_typed_sel (id receiver, SEL sel) { + // FIXME: libobjc2 contains a much more sane way of doing this if (sel_get_type (sel)) return sel; @@ -135,7 +138,7 @@ gs_find_by_receiver_best_typed_sel (id receiver, SEL sel) if we have an implementation. */ if (method) - sel = method->method_name; + sel = method_getName(method); } return gs_find_best_typed_sel (sel); } @@ -269,7 +272,7 @@ BOOL class_respondsToSelector(Class cls, SEL sel); */ static id gs_objc_proxy_lookup(id receiver, SEL op) { - Class cls = object_getClass(receiver); + id cls = object_getClass(receiver); BOOL resolved = NO; /* Let the class try to add a method for this thing. */ @@ -316,15 +319,6 @@ static id gs_objc_proxy_lookup(id receiver, SEL op) #endif } -- (id) initWithArgframe: (arglist_t)frame selector: (SEL)aSelector -{ - /* We should never get here */ - [self dealloc]; - self = nil; - [NSException raise: NSInternalInconsistencyException - format: @"Runtime incorrectly configured to pass argframes"]; - return nil; -} /* * This is the designated initialiser. @@ -463,14 +457,15 @@ GSFFIInvokeWithTargetAndImp(NSInvocation *inv, id anObject, IMP imp) if (_sendToSuper == YES) { - Super s; - - s.self = _target; + Class cls; if (GSObjCIsInstance(_target)) - s.class = class_getSuperclass(object_getClass(_target)); + cls = class_getSuperclass(object_getClass(_target)); else - s.class = class_getSuperclass((Class)_target); - imp = objc_msg_lookup_super(&s, _selector); + cls = class_getSuperclass((Class)_target); + { + struct objc_super s = {_target, cls}; + imp = objc_msg_lookup_super(&s, _selector); + } } else { @@ -481,7 +476,7 @@ GSFFIInvokeWithTargetAndImp(NSInvocation *inv, id anObject, IMP imp) _selector, GSObjCIsInstance(_target), YES); - imp = method_get_imp(method); + imp = method_getImplementation(method); /* * If fast lookup failed, we may be forwarding or something ... */ @@ -506,10 +501,6 @@ GSFFIInvokeWithTargetAndImp(NSInvocation *inv, id anObject, IMP imp) _validReturn = YES; } -- (void*) returnFrame: (arglist_t)argFrame -{ - return _retval; -} @end /* diff --git a/Source/GSPrivate.h b/Source/GSPrivate.h index 983ffe5e9..86ad70e52 100644 --- a/Source/GSPrivate.h +++ b/Source/GSPrivate.h @@ -54,6 +54,10 @@ #include "Foundation/NSArray.h" +#ifdef __GNUSTEP_RUNTIME__ +struct objc_category; +typedef struct objc_category* Category; +#endif @interface GSArray : NSArray { diff --git a/Source/NSBundle.m b/Source/NSBundle.m index a384936fc..445313800 100644 --- a/Source/NSBundle.m +++ b/Source/NSBundle.m @@ -512,21 +512,24 @@ _find_main_bundle_for_tool(NSString *toolName) NSString **fmClasses; NSString *bundlePath = nil; unsigned int len; + const char *frameworkClassName; if (frameworkClass == Nil) { return; } - len = strlen (frameworkClass->name); + frameworkClassName = class_getName(frameworkClass); + + len = strlen (frameworkClassName); if (len > 12 * sizeof(char) - && !strncmp ("NSFramework_", frameworkClass->name, 12)) + && !strncmp ("NSFramework_", frameworkClassName, 12)) { /* The name of the framework. */ NSString *name; - name = [NSString stringWithUTF8String: &frameworkClass->name[12]]; + name = [NSString stringWithUTF8String: &frameworkClassName[12]]; /* Important - gnustep-make mangles framework names to encode * them as ObjC class names. Here we need to demangle them. We * apply the reverse transformations in the reverse order. @@ -778,6 +781,7 @@ _find_main_bundle_for_tool(NSString *toolName) static void _bundle_load_callback(Class theClass, struct objc_category *theCategory) { + const char *className; NSCAssert(_loadingBundle, NSInternalInconsistencyException); NSCAssert(_loadingFrameworks, NSInternalInconsistencyException); @@ -786,11 +790,12 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory) { return; } + className = class_getName(theClass); /* Don't store the internal NSFramework_xxx class into the list of bundle classes, but store the linked frameworks in _loadingFrameworks */ - if (strlen (theClass->name) > 12 && !strncmp ("NSFramework_", - theClass->name, 12)) + if (strlen (className) > 12 && !strncmp ("NSFramework_", + className, 12)) { if (_currentFrameworkName) { @@ -798,7 +803,7 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory) frameworkName = [_currentFrameworkName cString]; - if (!strcmp(theClass->name, frameworkName)) + if (!strcmp(className, frameworkName)) return; } @@ -890,10 +895,11 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory) while ((class = objc_next_class(&state))) { - unsigned int len = strlen (class->name); + const char *className = class_getName(class); + unsigned int len = strlen (className); if (len > sizeof("NSFramework_") - && !strncmp("NSFramework_", class->name, 12)) + && !strncmp("NSFramework_", className, 12)) { [self _addFrameworkFromClass: class]; } @@ -1208,7 +1214,7 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory) if (bundle == nil) { /* Is it in the main bundle or a library? */ - if (class_is_class(aClass)) + if (!class_isMetaClass(aClass)) { NSString *lib; diff --git a/Source/NSConnection.m b/Source/NSConnection.m index 1b8c9ac68..387048a74 100644 --- a/Source/NSConnection.m +++ b/Source/NSConnection.m @@ -169,9 +169,6 @@ GSRunLoopForThread(NSThread *aThread) @interface NSConnection (GNUstepExtensions) - (void) finalize; -- (retval_t) forwardForProxy: (NSDistantObject*)object - selector: (SEL)sel - argFrame: (arglist_t)argframe; - (void) forwardInvocation: (NSInvocation *)inv forProxy: (NSDistantObject*)object; - (const char *) typeForSelector: (SEL)sel remoteTarget: (unsigned)target; @@ -1956,19 +1953,6 @@ static NSLock *cached_proxies_gate = nil; RELEASE(arp); } -/* - * NSDistantObject's -forward:: method calls this to send the message - * over the wire. - */ -- (retval_t) forwardForProxy: (NSDistantObject*)object - selector: (SEL)sel - argFrame: (arglist_t)argframe -{ -[NSException raise: NSInternalInconsistencyException - format: @"Obsolete method called"]; - return 0; -} - /* * NSDistantObject's -forwardInvocation: method calls this to send the message * over the wire. @@ -2594,7 +2578,7 @@ static NSLock *cached_proxies_gate = nil; if (meth != 0) { - type = meth->method_types; + type = method_getTypeEncoding(meth); } else { @@ -3067,7 +3051,7 @@ static NSLock *cached_proxies_gate = nil; version of the method types that has the type qualifiers in it. Search the protocols list. */ if (m) - type = m->method_types; + type = method_getTypeEncoding(m); else type = ""; [op encodeValueOfObjCType: @encode(char*) at: &type]; diff --git a/Source/NSCopyObject.m b/Source/NSCopyObject.m index 31f2280fb..99321533f 100644 --- a/Source/NSCopyObject.m +++ b/Source/NSCopyObject.m @@ -29,7 +29,10 @@ NSObject *NSCopyObject(NSObject *anObject, NSUInteger extraBytes, NSZone *zone) { - id copy = NSAllocateObject(((id)anObject)->class_pointer, extraBytes, zone); + // Note: The cast to Class* and dereference gets the isa pointer. This is + // ugly, but is required because the old GNU runtime calls this + // class_pointer, rather than isa, just to be different. + id copy = NSAllocateObject((*(Class*)anObject), extraBytes, zone); memcpy(copy, anObject, class_getInstanceSize(object_getClass(anObject)) + extraBytes); return copy; diff --git a/Source/NSDebug.m b/Source/NSDebug.m index 7b90b7ae8..f4c12eea2 100644 --- a/Source/NSDebug.m +++ b/Source/NSDebug.m @@ -493,7 +493,7 @@ _GSDebugAllocationList(BOOL difference) } if (val != 0) { - pos += 11 + strlen(the_table[i].class->name); + pos += 11 + strlen(class_getName(the_table[i].class)); } } if (pos == 0) @@ -539,7 +539,7 @@ _GSDebugAllocationList(BOOL difference) if (val != 0) { - sprintf(&buf[pos], "%d\t%s\n", val, the_table[i].class->name); + sprintf(&buf[pos], "%d\t%s\n", val, class_getName(the_table[i].class)); pos += strlen(&buf[pos]); } } @@ -587,7 +587,7 @@ _GSDebugAllocationListAll(void) if (val != 0) { - pos += 11 + strlen(the_table[i].class->name); + pos += 11 + strlen(class_getName(the_table[i].class)); } } if (pos == 0) @@ -619,7 +619,7 @@ _GSDebugAllocationListAll(void) if (val != 0) { - sprintf(&buf[pos], "%d\t%s\n", val, the_table[i].class->name); + sprintf(&buf[pos], "%d\t%s\n", val, class_getName(the_table[i].class)); pos += strlen(&buf[pos]); } } diff --git a/Source/NSDistantObject.m b/Source/NSDistantObject.m index 18305f6bc..f5cde3794 100644 --- a/Source/NSDistantObject.m +++ b/Source/NSDistantObject.m @@ -42,7 +42,6 @@ @interface NSDistantObject(GNUstepExtensions) - (Class) classForPortCoder; -- (id) forward: (SEL)aSel :(arglist_t)frame; - (void) finalize; @end @@ -162,7 +161,7 @@ enum proxyLocation + (BOOL) respondsToSelector: (SEL)sel { - return GSGetMethod(self, sel, NO, YES) != (GSMethod)0; + return class_getClassMethod(self, sel) != NULL; } + (id) initWithCoder: (NSCoder*)aCoder @@ -709,45 +708,17 @@ enum proxyLocation if (_protocol != nil) { - const char *types = 0; + struct objc_method_description mth; + mth = GSProtocolGetMethodDescriptionRecursive(_protocol, aSelector, YES, YES); - struct objc_method_description* mth; + if (mth.name == NULL && mth.types == NULL) + { + // Search for class method + mth = GSProtocolGetMethodDescriptionRecursive(_protocol, aSelector, YES, NO); + } - /* Older gcc versions may not initialise Protocol objects properly - * so we have an evil hack which checks for a known bad value of - * the class pointer, and uses an internal function - * (implemented in NSObject.m) to examine the protocol contents - * without sending any ObjectiveC message to it. - */ - if ((uintptr_t)object_getClass(_protocol) == 0x2) - { - extern struct objc_method_description* - GSDescriptionForInstanceMethod(Protocol *self, SEL aSel); - mth = GSDescriptionForInstanceMethod(_protocol, aSelector); - } - else - { - mth = [_protocol descriptionForInstanceMethod: aSelector]; - } - if (mth == 0) - { - if ((uintptr_t)object_getClass(_protocol) == 0x2) - { - extern struct objc_method_description* - GSDescriptionForClassMethod(Protocol *self, SEL aSel); - mth = GSDescriptionForClassMethod(_protocol, aSelector); - } - else - { - mth = [_protocol descriptionForClassMethod: aSelector]; - } - } - if (mth != 0) - { - types = mth->types; - } - if (types) - return [NSMethodSignature signatureWithObjCTypes: types]; + if (mth.types) + return [NSMethodSignature signatureWithObjCTypes: mth.types]; } if (_sigs != 0) @@ -873,42 +844,12 @@ enum proxyLocation } } -static inline BOOL class_is_kind_of (Class self, Class aClassObject) -{ - Class class; - - for (class = self; class!=Nil; class = class_getSuperclass(class)) - if (class==aClassObject) - return YES; - return NO; -} -/** - * For backward compatibility ... do not use this method.
- * Handle old fashioned forwarding to the proxy. - */ -- (id) forward: (SEL)aSel :(arglist_t)frame -{ - if (debug_proxy) - NSLog(@"NSDistantObject forwarding %s\n", sel_getName(aSel)); - - if (![_connection isValid]) - [NSException - raise: NSGenericException - format: @"Trying to send message to an invalid Proxy.\n" - @"You should request NSConnectionDidDieNotification's and\n" - @"release all references to the proxy's of invalid Connections."]; - - return [_connection forwardForProxy: self - selector: aSel - argFrame: frame]; -} - - (Class) classForCoder { - return object_get_class (self); + return object_getClass(self); } /** @@ -916,7 +857,7 @@ static inline BOOL class_is_kind_of (Class self, Class aClassObject) */ - (Class) classForPortCoder { - return object_get_class (self); + return object_getClass(self); } /** @@ -928,7 +869,7 @@ static inline BOOL class_is_kind_of (Class self, Class aClassObject) { if (_protocol != nil) { - return [_protocol conformsTo: aProtocol]; + return protocol_conformsToProtocol(_protocol, aProtocol); } else { diff --git a/Source/NSInvocation.m b/Source/NSInvocation.m index 22cee3536..7d9aa5682 100644 --- a/Source/NSInvocation.m +++ b/Source/NSInvocation.m @@ -773,18 +773,6 @@ _arg_addr(NSInvocation *inv, int index) * create invocations. */ @implementation NSInvocation (MacroSetup) -/** - * Internal use.
- * Initialises the receiver with a known selector and argument list - * as supplied to the forward:: method by the ObjectiveC runtime - * when it is unable to locate an implementation for the selector - * in a class. - */ -- (id) initWithArgframe: (arglist_t)frame selector: (SEL)aSelector -{ - [self subclassResponsibility: _cmd]; - return nil; -} /** * Initialised an invocation instance which can be used to send messages to @@ -804,11 +792,6 @@ _arg_addr(NSInvocation *inv, int index) * Provides a return frame that the ObjectiveC runtime can use to * return the result of an invocation to a calling function. */ -- (void*) returnFrame: (arglist_t)argFrame -{ - [self subclassResponsibility: _cmd]; - return NULL; -} + (id) _newProxyForInvocation: (id)target { @@ -839,10 +822,6 @@ _arg_addr(NSInvocation *inv, int index) #warning Using dummy NSInvocation implementation. It is strongly recommended that you use libffi. @implementation GSDummyInvocation -- (id) initWithArgframe: (arglist_t)frame selector: (SEL)aSelector -{ - return self; -} /* * This is the de_signated initialiser. @@ -866,10 +845,6 @@ _arg_addr(NSInvocation *inv, int index) } } -- (void*) returnFrame: (arglist_t)argFrame -{ - return 0; -} @end #endif @@ -886,19 +861,6 @@ _arg_addr(NSInvocation *inv, int index) { return invocation; } -- (retval_t) forward: (SEL)aSel : (arglist_t)argFrame -{ - NSInvocation *inv; - - if (aSel == 0) - [NSException raise: NSInvalidArgumentException - format: @"%@ null selector given", NSStringFromSelector(_cmd)]; - - inv = AUTORELEASE([[NSInvocation alloc] initWithArgframe: argFrame - selector: aSel]); - [self forwardInvocation: inv]; - return [inv returnFrame: argFrame]; -} - (void) forwardInvocation: (NSInvocation*)anInvocation { invocation = anInvocation; diff --git a/Source/NSMethodSignature.m b/Source/NSMethodSignature.m index 6bcdf7cf5..b09203dc4 100644 --- a/Source/NSMethodSignature.m +++ b/Source/NSMethodSignature.m @@ -28,6 +28,7 @@ */ #import "common.h" +#include #define EXPOSE_NSMethodSignature_IVARS 1 #import "Foundation/NSMethodSignature.h" diff --git a/Source/NSObjCRuntime.m b/Source/NSObjCRuntime.m index 3756845a1..b980140e3 100644 --- a/Source/NSObjCRuntime.m +++ b/Source/NSObjCRuntime.m @@ -37,7 +37,7 @@ NSString * NSStringFromProtocol(Protocol *aProtocol) { if (aProtocol != (Protocol*)0) - return [NSString stringWithUTF8String: (const char*)[aProtocol name]]; + return [NSString stringWithUTF8String: protocol_getName(aProtocol)]; return nil; } diff --git a/Source/NSObject.m b/Source/NSObject.m index 56f7e5445..80e7faeba 100644 --- a/Source/NSObject.m +++ b/Source/NSObject.m @@ -25,6 +25,10 @@ $Date$ $Revision$ */ +// Make sure that class_pointer in the old runtime's definition of id is +// renamed isa, and so are all uses. +#define class_pointer isa + /* On some versions of mingw we need to work around bad function declarations * by defining them away and doing the declarations ourself later. */ @@ -101,7 +105,6 @@ static Class NSConstantStringClass; Class isa; } - (Class) class; -- (retval_t) forward:(SEL)aSel :(arglist_t)argFrame; - (void) forwardInvocation: (NSInvocation*)anInvocation; - (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector; @end @@ -589,7 +592,7 @@ NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone) int size; GC_descr gc_type; - NSCAssert((CLS_ISCLASS(aClass)), @"Bad class for new object"); + NSCAssert((!class_isMetaClass(aClass)), @"Bad class for new object"); gc_type = (GC_descr)aClass->gc_object_type; size = class_getInstanceSize(aClass) + extraBytes; if (size % sizeof(void*) != 0) @@ -649,7 +652,7 @@ NSAllocateObject (Class aClass, NSUInteger extraBytes, NSZone *zone) id new; int size; - NSCAssert((CLS_ISCLASS(aClass)), @"Bad class for new object"); + NSCAssert((!class_isMetaClass(aClass)), @"Bad class for new object"); size = class_getInstanceSize(aClass) + extraBytes + sizeof(struct obj_layout); if (zone == 0) { @@ -670,7 +673,7 @@ NSAllocateObject (Class aClass, NSUInteger extraBytes, NSZone *zone) inline void NSDeallocateObject(id anObject) { - if ((anObject!=nil) && CLS_ISCLASS(((id)anObject)->class_pointer)) + if ((anObject!=nil) && !class_isMetaClass(((id)anObject)->class_pointer)) { obj o = &((obj)anObject)[-1]; NSZone *z = o->zone; @@ -743,101 +746,6 @@ NSShouldRetainWithZone (NSObject *anObject, NSZone *requestedZone) } - -/* FIXME ... the following code is a hack for the gnu runtime only - */ -struct objc_method_description_list { - int count; - struct objc_method_description list[1]; -}; - -/* Must have same layout as ivars of Protocol class - */ -struct protocol_class { - Class isa; - char *protocol_name; - struct objc_protocol_list *protocol_list; - struct objc_method_description_list *instance_methods; - struct objc_method_description_list *class_methods; -}; - -struct objc_method_description * -GSDescriptionForInstanceMethod(Protocol *self, SEL aSel) -{ - struct protocol_class *pcl = (struct protocol_class*)self; - int i; - struct objc_protocol_list *p_list; - const char *name = sel_getName(aSel); - struct objc_method_description *result; - - if (pcl->instance_methods != 0) - { - for (i = 0; i < pcl->instance_methods->count; i++) - { - if (!strcmp ((char*)pcl->instance_methods->list[i].name, name)) - return &(pcl->instance_methods->list[i]); - } - } - for (p_list = pcl->protocol_list; p_list != 0; p_list = p_list->next) - { - for (i = 0; i < p_list->count; i++) - { - result = GSDescriptionForInstanceMethod(p_list->list[i], aSel); - if (result) - { - return result; - } - } - } - - return NULL; -} - -struct objc_method_description * -GSDescriptionForClassMethod(Protocol *self, SEL aSel) -{ - struct protocol_class *pcl = (struct protocol_class*)self; - int i; - struct objc_protocol_list *p_list; - const char *name = sel_getName(aSel); - struct objc_method_description *result; - - if (pcl->class_methods != 0) - { - for (i = 0; i < pcl->class_methods->count; i++) - { - if (!strcmp ((char*)pcl->class_methods->list[i].name, name)) - return &(pcl->class_methods->list[i]); - } - } - for (p_list = pcl->protocol_list; p_list != 0; p_list = p_list->next) - { - for (i = 0; i < p_list->count; i++) - { - result = GSDescriptionForClassMethod(p_list->list[i], aSel); - if (result) - { - return result; - } - } - } - - return NULL; -} - -@implementation Protocol (Fixup) - -- (struct objc_method_description *) descriptionForInstanceMethod:(SEL)aSel -{ - return GSDescriptionForInstanceMethod(self, aSel); -} - -- (struct objc_method_description *) descriptionForClassMethod:(SEL)aSel; -{ - return GSDescriptionForClassMethod(self, aSel); -} - -@end /** *

@@ -1202,7 +1110,7 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak)); */ - (Class) class { - return object_get_class(self); + return object_getClass(self); } /** @@ -1455,7 +1363,7 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak)); mth = GSGetMethod(self, aSelector, YES, YES); if (mth == 0) return nil; - return [NSMethodSignature signatureWithObjCTypes:mth->method_types]; + return [NSMethodSignature signatureWithObjCTypes: method_getTypeEncoding(mth)]; } /** @@ -1492,37 +1400,26 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak)); * used by the Distributed Objects system, which the * runtime does not maintain in classes. */ - if (c->protocols != 0) + int count; + Protocol **protocols = class_copyProtocolList(isa, &count); + if (NULL != protocols) { - struct objc_protocol_list *protocols = c->protocols; - BOOL found = NO; + struct objc_method_description mth; + for (int i=0 ; icount) - { - Protocol *p; - struct objc_method_description *pmth; - - p = protocols->list[i++]; - if (c == (Class)self) - { - pmth = [p descriptionForClassMethod: aSelector]; - } - else - { - pmth = [p descriptionForInstanceMethod: aSelector]; - } - if (pmth != 0) - { - types = pmth->types; - found = YES; - } - } - protocols = protocols->next; - } + if (NULL != mth.types) { break; } + } + free(protocols); } if (types == 0) @@ -1590,20 +1487,6 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak)); aSelector ? sel_getName(aSelector) : "(null)"]; } -- (retval_t) forward: (SEL)aSel : (arglist_t)argFrame -{ - NSInvocation *inv; - - if (aSel == 0) - [NSException raise: NSInvalidArgumentException - format: @"%@ null selector given", NSStringFromSelector(_cmd)]; - - inv = AUTORELEASE([[NSInvocation alloc] initWithArgframe: argFrame - selector: aSel]); - [self forwardInvocation: inv]; - return [inv returnFrame: argFrame]; -} - /** * This method is called automatically to handle a message sent to * the receiver for which the receivers class has no method.
@@ -2062,7 +1945,7 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak)); [NSException raise: NSInvalidArgumentException format: @"%s +setVersion: may not set a negative version", GSClassNameFromObject(self)]; - class_set_version(self, aVersion); + class_setVersion(self, aVersion); return self; } @@ -2073,7 +1956,7 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak)); */ + (NSInteger) version { - return class_get_version(self); + return class_getVersion(self); } - (id) autoContentAccessingProxy @@ -2155,15 +2038,6 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak)); return [self conformsToProtocol: aProtocol]; } -- (retval_t) performv: (SEL)aSel :(arglist_t)argFrame -{ - if (aSel == 0) - [NSException raise: NSInvalidArgumentException - format: @"%@ null selector given", NSStringFromSelector(_cmd)]; - - return objc_msg_sendv(self, aSel, argFrame); -} - + (IMP) instanceMethodFor: (SEL)aSel { return [self instanceMethodForSelector:aSel]; @@ -2180,7 +2054,7 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak)); mth = GSGetMethod(self, aSelector, YES, YES); if (mth == 0) return nil; - return [NSMethodSignature signatureWithObjCTypes:mth->method_types]; + return [NSMethodSignature signatureWithObjCTypes: method_getTypeEncoding(mth)]; } - (IMP) methodFor: (SEL)aSel @@ -2328,7 +2202,7 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak)); + (NSInteger) streamVersion: (void*)aStream { GSOnceMLog(@"[NSObject+streamVersion:] is deprecated ... do not use"); - return class_get_version (self); + return class_getVersion (self); } - (id) read: (void*)aStream { @@ -2359,15 +2233,6 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak)); { return NSMapGet(zombieMap, (void*)self); } -- (retval_t) forward:(SEL)aSel :(arglist_t)argFrame -{ - if (aSel == 0) - [NSException raise: NSInvalidArgumentException - format: @"%@ null selector given", NSStringFromSelector(_cmd)]; - - GSLogZombie(self, aSel); - return 0; -} - (void) forwardInvocation: (NSInvocation*)anInvocation { NSUInteger size = [[anInvocation methodSignature] methodReturnLength]; diff --git a/Source/NSProtocolChecker.m b/Source/NSProtocolChecker.m index 8d3765831..3f2f6e4bd 100644 --- a/Source/NSProtocolChecker.m +++ b/Source/NSProtocolChecker.m @@ -72,48 +72,15 @@ [super dealloc]; } -- (struct objc_method_description*) _methodDescription: (SEL)aSelector +- (const char *) _protocolTypeForSelector: (SEL)aSel { - extern struct objc_method_description - *GSDescriptionForInstanceMethod(Protocol *self, SEL aSel); - extern struct objc_method_description - *GSDescriptionForClassMethod(Protocol *self, SEL aSel); - - if (_myProtocol != nil && _myTarget != nil) + struct objc_method_description desc; + desc = GSProtocolGetMethodDescriptionRecursive(_myProtocol, aSel, YES, YES); + if (desc.name == NULL && desc.types == NULL) { - struct objc_method_description* mth; - - /* Older gcc versions may not initialise Protocol objects properly - * so we have an evil hack which checks for a known bad value of - * the class pointer, and uses an internal function - * (implemented in NSObject.m) to examine the protocol contents - * without sending any ObjectiveC message to it. - */ - if (GSObjCIsInstance(_myTarget)) - { - if ((uintptr_t)object_getClass(_myProtocol) == 0x2) - { - mth = GSDescriptionForInstanceMethod(_myProtocol, aSelector); - } - else - { - mth = [_myProtocol descriptionForInstanceMethod: aSelector]; - } - } - else - { - if ((uintptr_t)object_getClass(_myProtocol) == 0x2) - { - mth = GSDescriptionForClassMethod(_myProtocol, aSelector); - } - else - { - mth = [_myProtocol descriptionForClassMethod: aSelector]; - } - } - return mth; + desc = GSProtocolGetMethodDescriptionRecursive(_myProtocol, aSel, YES, NO); } - return 0; + return desc.types; } /** @@ -125,7 +92,7 @@ { const char *type; - if ([self _methodDescription: [anInvocation selector]] == 0) + if ([self _protocolTypeForSelector: [anInvocation selector]] == NULL) { if (GSObjCIsInstance(_myTarget)) { @@ -184,105 +151,17 @@ - (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector { - const char *types; - struct objc_method *mth; - Class c; - - if (aSelector == 0) - [NSException raise: NSInvalidArgumentException - format: @"%@ null selector given", NSStringFromSelector(_cmd)]; - - /* - * Evil hack to prevent recursion - if we are asking a remote - * object for a method signature, we can't ask it for the - * signature of methodSignatureForSelector:, so we hack in - * the signature required manually :-( - */ - if (sel_isEqual(aSelector, _cmd)) - { - static NSMethodSignature *sig = nil; - - if (sig == nil) - { - sig = [NSMethodSignature signatureWithObjCTypes: "@@::"]; - IF_NO_GC(RETAIN(sig);) - } - return sig; - } - if (_myProtocol != nil) { - const char *types = 0; - struct objc_method_description *desc; - - desc = [self _methodDescription: aSelector]; - if (desc != 0) - { - types = desc->types; - } - if (types == 0) + const char *types = [self _protocolTypeForSelector: aSelector]; + if (types == NULL) { return nil; } return [NSMethodSignature signatureWithObjCTypes: types]; } - c = object_getClass(self); - mth = GSGetMethod(c, aSelector, YES, YES); - if (mth == 0) - { - return nil; // Method not implemented - } - types = mth->method_types; - - /* - * If there are protocols that this class conforms to, - * the method may be listed in a protocol with more - * detailed type information than in the class itself - * and we must therefore use the information from the - * protocol. - * This is because protocols also carry information - * used by the Distributed Objects system, which the - * runtime does not maintain in classes. - */ - if (c->protocols != 0) - { - struct objc_protocol_list *protocols = c->protocols; - BOOL found = NO; - - while (found == NO && protocols != 0) - { - unsigned i = 0; - - while (found == NO && i < protocols->count) - { - Protocol *p; - struct objc_method_description *pmth; - - p = protocols->list[i++]; - if (c == (Class)self) - { - pmth = [p descriptionForClassMethod: aSelector]; - } - else - { - pmth = [p descriptionForInstanceMethod: aSelector]; - } - if (pmth != 0) - { - types = pmth->types; - found = YES; - } - } - protocols = protocols->next; - } - } - - if (types == 0) - { - return nil; - } - return [NSMethodSignature signatureWithObjCTypes: types]; + return [super methodSignatureForSelector: aSelector]; } /** diff --git a/Source/NSProxy.m b/Source/NSProxy.m index a36341907..cd7617ff3 100644 --- a/Source/NSProxy.m +++ b/Source/NSProxy.m @@ -154,7 +154,7 @@ extern BOOL __objc_responds_to(id, SEL); mth = GSGetMethod(self, aSelector, NO, YES); if (mth != 0) { - const char *types = mth->method_types; + const char *types = method_getTypeEncoding(mth); if (types != 0) { @@ -231,7 +231,7 @@ extern BOOL __objc_responds_to(id, SEL); */ - (Class) class { - return object_get_class(self); + return object_getClass(self); } /** @@ -271,19 +271,6 @@ extern BOOL __objc_responds_to(id, SEL); GSClassNameFromObject(self), (size_t)self]; } -/** - * Calls the -forwardInvocation: method and returns the result. - */ -- (retval_t) forward:(SEL)aSel :(arglist_t)argFrame -{ - NSInvocation *inv; - - inv = AUTORELEASE([[NSInvocation alloc] initWithArgframe: argFrame - selector: aSel]); - [self forwardInvocation: inv]; - return [inv returnFrame: argFrame]; -} - /** * Raises an NSInvalidArgumentException. */ @@ -400,7 +387,7 @@ extern BOOL __objc_responds_to(id, SEL); mth = GSGetMethod(object_getClass(self), aSelector, YES, YES); if (mth != 0) { - const char *types = mth->method_types; + const char *types = method_getTypeEncoding(mth); if (types != 0) { @@ -561,7 +548,7 @@ extern BOOL __objc_responds_to(id, SEL); */ - (Class) superclass { - return object_get_super_class(self); + return class_getSuperclass(isa); } /** diff --git a/Source/NSSerializer.m b/Source/NSSerializer.m index 4ccd0a5f8..1dce86a79 100644 --- a/Source/NSSerializer.m +++ b/Source/NSSerializer.m @@ -137,11 +137,6 @@ static SEL lenSel; static SEL serSel; static SEL setSel; -/* Compatibility methods from NEXTSTEP (Implemented in NSObject) */ -@interface NSObject (Serializer) -- (retval_t) performv: (SEL)aSel :(arglist_t)argFrame; -@end - static void initSerializerInfo(_NSSerializerInfo* info, NSMutableData *d, BOOL u) { @@ -793,17 +788,6 @@ deserializeFromInfo(_NSDeserializerInfo* info) [super dealloc]; } -- forward: (SEL)aSel :(arglist_t)frame -{ - if (plist == nil && info.data != nil) - { - plist = deserializeFromInfo(&info); - RELEASE(info.data); - info.data = nil; - } - return [plist performv: aSel :frame]; -} - - (BOOL) isEqual: (id)other { if (other == self)