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.  <string.h> 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
This commit is contained in:
theraven 2010-09-09 15:06:09 +00:00
parent 9c0b83c8a9
commit 85549433db
18 changed files with 141 additions and 501 deletions

View file

@ -1,3 +1,40 @@
2010-09-02 9avid Chisnall <theraven@gna.org>
* 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. <string.h> 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 <ewasylishen@gmail.com> 2010-09-08 Eric Wasylishen <ewasylishen@gmail.com>
* Source/ObjectiveC2/runtime.h: * Source/ObjectiveC2/runtime.h:

View file

@ -76,9 +76,6 @@ enum {
- (NSDistantObject*) proxyForTarget: (unsigned)target; - (NSDistantObject*) proxyForTarget: (unsigned)target;
- (void) retainTarget: (unsigned)target; - (void) retainTarget: (unsigned)target;
- (retval_t) forwardForProxy: (NSDistantObject*)object
selector: (SEL)sel
argFrame: (arglist_t)argframe;
- (void) forwardInvocation: (NSInvocation *)inv - (void) forwardInvocation: (NSInvocation *)inv
forProxy: (NSDistantObject*)object; forProxy: (NSDistantObject*)object;
- (const char *) typeForSelector: (SEL)sel remoteTarget: (unsigned)target; - (const char *) typeForSelector: (SEL)sel remoteTarget: (unsigned)target;

View file

@ -120,9 +120,7 @@ extern "C" {
+ (id) _newProxyForInvocation: (id)target; + (id) _newProxyForInvocation: (id)target;
+ (id) _newProxyForMessage: (id)target; + (id) _newProxyForMessage: (id)target;
+ (NSInvocation*) _returnInvocationAndDestroyProxy: (id)proxy; + (NSInvocation*) _returnInvocationAndDestroyProxy: (id)proxy;
- (id) initWithArgframe: (arglist_t)frame selector: (SEL)aSelector;
- (id) initWithMethodSignature: (NSMethodSignature*)aSignature; - (id) initWithMethodSignature: (NSMethodSignature*)aSignature;
- (void*) returnFrame: (arglist_t)argFrame;
@end @end
/** /**

View file

@ -40,6 +40,7 @@
</chapter> </chapter>
*/ */
#include <string.h>
#import "common.h" #import "common.h"
#import "GNUstepBase/preface.h" #import "GNUstepBase/preface.h"
#import "GNUstepBase/Unicode.h" #import "GNUstepBase/Unicode.h"

View file

@ -22,6 +22,8 @@
Boston, MA 02111 USA. Boston, MA 02111 USA.
*/ */
#define class_pointer isa
#import "common.h" #import "common.h"
#define EXPOSE_NSInvocation_IVARS 1 #define EXPOSE_NSInvocation_IVARS 1
#import "Foundation/NSException.h" #import "Foundation/NSException.h"
@ -68,7 +70,7 @@ gs_method_for_receiver_and_selector (id receiver, SEL sel)
YES); YES);
} }
return METHOD_NULL; return 0;
} }
@ -118,6 +120,7 @@ gs_find_best_typed_sel (SEL sel)
static INLINE SEL static INLINE SEL
gs_find_by_receiver_best_typed_sel (id receiver, SEL 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)) if (sel_get_type (sel))
return sel; return sel;
@ -135,7 +138,7 @@ gs_find_by_receiver_best_typed_sel (id receiver, SEL sel)
if we have an implementation. if we have an implementation.
*/ */
if (method) if (method)
sel = method->method_name; sel = method_getName(method);
} }
return gs_find_best_typed_sel (sel); 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) static id gs_objc_proxy_lookup(id receiver, SEL op)
{ {
Class cls = object_getClass(receiver); id cls = object_getClass(receiver);
BOOL resolved = NO; BOOL resolved = NO;
/* Let the class try to add a method for this thing. */ /* 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 #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. * This is the designated initialiser.
@ -463,14 +457,15 @@ GSFFIInvokeWithTargetAndImp(NSInvocation *inv, id anObject, IMP imp)
if (_sendToSuper == YES) if (_sendToSuper == YES)
{ {
Super s; Class cls;
s.self = _target;
if (GSObjCIsInstance(_target)) if (GSObjCIsInstance(_target))
s.class = class_getSuperclass(object_getClass(_target)); cls = class_getSuperclass(object_getClass(_target));
else else
s.class = class_getSuperclass((Class)_target); cls = class_getSuperclass((Class)_target);
imp = objc_msg_lookup_super(&s, _selector); {
struct objc_super s = {_target, cls};
imp = objc_msg_lookup_super(&s, _selector);
}
} }
else else
{ {
@ -481,7 +476,7 @@ GSFFIInvokeWithTargetAndImp(NSInvocation *inv, id anObject, IMP imp)
_selector, _selector,
GSObjCIsInstance(_target), GSObjCIsInstance(_target),
YES); YES);
imp = method_get_imp(method); imp = method_getImplementation(method);
/* /*
* If fast lookup failed, we may be forwarding or something ... * If fast lookup failed, we may be forwarding or something ...
*/ */
@ -506,10 +501,6 @@ GSFFIInvokeWithTargetAndImp(NSInvocation *inv, id anObject, IMP imp)
_validReturn = YES; _validReturn = YES;
} }
- (void*) returnFrame: (arglist_t)argFrame
{
return _retval;
}
@end @end
/* /*

View file

@ -54,6 +54,10 @@
#include "Foundation/NSArray.h" #include "Foundation/NSArray.h"
#ifdef __GNUSTEP_RUNTIME__
struct objc_category;
typedef struct objc_category* Category;
#endif
@interface GSArray : NSArray @interface GSArray : NSArray
{ {

View file

@ -512,21 +512,24 @@ _find_main_bundle_for_tool(NSString *toolName)
NSString **fmClasses; NSString **fmClasses;
NSString *bundlePath = nil; NSString *bundlePath = nil;
unsigned int len; unsigned int len;
const char *frameworkClassName;
if (frameworkClass == Nil) if (frameworkClass == Nil)
{ {
return; return;
} }
len = strlen (frameworkClass->name); frameworkClassName = class_getName(frameworkClass);
len = strlen (frameworkClassName);
if (len > 12 * sizeof(char) if (len > 12 * sizeof(char)
&& !strncmp ("NSFramework_", frameworkClass->name, 12)) && !strncmp ("NSFramework_", frameworkClassName, 12))
{ {
/* The name of the framework. */ /* The name of the framework. */
NSString *name; NSString *name;
name = [NSString stringWithUTF8String: &frameworkClass->name[12]]; name = [NSString stringWithUTF8String: &frameworkClassName[12]];
/* Important - gnustep-make mangles framework names to encode /* Important - gnustep-make mangles framework names to encode
* them as ObjC class names. Here we need to demangle them. We * them as ObjC class names. Here we need to demangle them. We
* apply the reverse transformations in the reverse order. * apply the reverse transformations in the reverse order.
@ -778,6 +781,7 @@ _find_main_bundle_for_tool(NSString *toolName)
static void static void
_bundle_load_callback(Class theClass, struct objc_category *theCategory) _bundle_load_callback(Class theClass, struct objc_category *theCategory)
{ {
const char *className;
NSCAssert(_loadingBundle, NSInternalInconsistencyException); NSCAssert(_loadingBundle, NSInternalInconsistencyException);
NSCAssert(_loadingFrameworks, NSInternalInconsistencyException); NSCAssert(_loadingFrameworks, NSInternalInconsistencyException);
@ -786,11 +790,12 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
{ {
return; return;
} }
className = class_getName(theClass);
/* Don't store the internal NSFramework_xxx class into the list of /* Don't store the internal NSFramework_xxx class into the list of
bundle classes, but store the linked frameworks in _loadingFrameworks */ bundle classes, but store the linked frameworks in _loadingFrameworks */
if (strlen (theClass->name) > 12 && !strncmp ("NSFramework_", if (strlen (className) > 12 && !strncmp ("NSFramework_",
theClass->name, 12)) className, 12))
{ {
if (_currentFrameworkName) if (_currentFrameworkName)
{ {
@ -798,7 +803,7 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
frameworkName = [_currentFrameworkName cString]; frameworkName = [_currentFrameworkName cString];
if (!strcmp(theClass->name, frameworkName)) if (!strcmp(className, frameworkName))
return; return;
} }
@ -890,10 +895,11 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
while ((class = objc_next_class(&state))) 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_") if (len > sizeof("NSFramework_")
&& !strncmp("NSFramework_", class->name, 12)) && !strncmp("NSFramework_", className, 12))
{ {
[self _addFrameworkFromClass: class]; [self _addFrameworkFromClass: class];
} }
@ -1208,7 +1214,7 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
if (bundle == nil) if (bundle == nil)
{ {
/* Is it in the main bundle or a library? */ /* Is it in the main bundle or a library? */
if (class_is_class(aClass)) if (!class_isMetaClass(aClass))
{ {
NSString *lib; NSString *lib;

View file

@ -169,9 +169,6 @@ GSRunLoopForThread(NSThread *aThread)
@interface NSConnection (GNUstepExtensions) @interface NSConnection (GNUstepExtensions)
- (void) finalize; - (void) finalize;
- (retval_t) forwardForProxy: (NSDistantObject*)object
selector: (SEL)sel
argFrame: (arglist_t)argframe;
- (void) forwardInvocation: (NSInvocation *)inv - (void) forwardInvocation: (NSInvocation *)inv
forProxy: (NSDistantObject*)object; forProxy: (NSDistantObject*)object;
- (const char *) typeForSelector: (SEL)sel remoteTarget: (unsigned)target; - (const char *) typeForSelector: (SEL)sel remoteTarget: (unsigned)target;
@ -1956,19 +1953,6 @@ static NSLock *cached_proxies_gate = nil;
RELEASE(arp); 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 * NSDistantObject's -forwardInvocation: method calls this to send the message
* over the wire. * over the wire.
@ -2594,7 +2578,7 @@ static NSLock *cached_proxies_gate = nil;
if (meth != 0) if (meth != 0)
{ {
type = meth->method_types; type = method_getTypeEncoding(meth);
} }
else else
{ {
@ -3067,7 +3051,7 @@ static NSLock *cached_proxies_gate = nil;
version of the method types that has the type qualifiers in it. version of the method types that has the type qualifiers in it.
Search the protocols list. */ Search the protocols list. */
if (m) if (m)
type = m->method_types; type = method_getTypeEncoding(m);
else else
type = ""; type = "";
[op encodeValueOfObjCType: @encode(char*) at: &type]; [op encodeValueOfObjCType: @encode(char*) at: &type];

View file

@ -29,7 +29,10 @@
NSObject *NSCopyObject(NSObject *anObject, NSUInteger extraBytes, NSZone *zone) 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, memcpy(copy, anObject,
class_getInstanceSize(object_getClass(anObject)) + extraBytes); class_getInstanceSize(object_getClass(anObject)) + extraBytes);
return copy; return copy;

View file

@ -493,7 +493,7 @@ _GSDebugAllocationList(BOOL difference)
} }
if (val != 0) if (val != 0)
{ {
pos += 11 + strlen(the_table[i].class->name); pos += 11 + strlen(class_getName(the_table[i].class));
} }
} }
if (pos == 0) if (pos == 0)
@ -539,7 +539,7 @@ _GSDebugAllocationList(BOOL difference)
if (val != 0) 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]); pos += strlen(&buf[pos]);
} }
} }
@ -587,7 +587,7 @@ _GSDebugAllocationListAll(void)
if (val != 0) if (val != 0)
{ {
pos += 11 + strlen(the_table[i].class->name); pos += 11 + strlen(class_getName(the_table[i].class));
} }
} }
if (pos == 0) if (pos == 0)
@ -619,7 +619,7 @@ _GSDebugAllocationListAll(void)
if (val != 0) 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]); pos += strlen(&buf[pos]);
} }
} }

View file

@ -42,7 +42,6 @@
@interface NSDistantObject(GNUstepExtensions) @interface NSDistantObject(GNUstepExtensions)
- (Class) classForPortCoder; - (Class) classForPortCoder;
- (id) forward: (SEL)aSel :(arglist_t)frame;
- (void) finalize; - (void) finalize;
@end @end
@ -162,7 +161,7 @@ enum proxyLocation
+ (BOOL) respondsToSelector: (SEL)sel + (BOOL) respondsToSelector: (SEL)sel
{ {
return GSGetMethod(self, sel, NO, YES) != (GSMethod)0; return class_getClassMethod(self, sel) != NULL;
} }
+ (id) initWithCoder: (NSCoder*)aCoder + (id) initWithCoder: (NSCoder*)aCoder
@ -709,45 +708,17 @@ enum proxyLocation
if (_protocol != nil) 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 if (mth.types)
* so we have an evil hack which checks for a known bad value of return [NSMethodSignature signatureWithObjCTypes: mth.types];
* 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 (_sigs != 0) 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.<br />
* 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 - (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 - (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) if (_protocol != nil)
{ {
return [_protocol conformsTo: aProtocol]; return protocol_conformsToProtocol(_protocol, aProtocol);
} }
else else
{ {

View file

@ -773,18 +773,6 @@ _arg_addr(NSInvocation *inv, int index)
* create invocations. * create invocations.
*/ */
@implementation NSInvocation (MacroSetup) @implementation NSInvocation (MacroSetup)
/**
* Internal use.<br />
* 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;
}
/** <init /><override-subclass /> /** <init /><override-subclass />
* Initialised an invocation instance which can be used to send messages to * 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 * Provides a return frame that the ObjectiveC runtime can use to
* return the result of an invocation to a calling function. * return the result of an invocation to a calling function.
*/ */
- (void*) returnFrame: (arglist_t)argFrame
{
[self subclassResponsibility: _cmd];
return NULL;
}
+ (id) _newProxyForInvocation: (id)target + (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. #warning Using dummy NSInvocation implementation. It is strongly recommended that you use libffi.
@implementation GSDummyInvocation @implementation GSDummyInvocation
- (id) initWithArgframe: (arglist_t)frame selector: (SEL)aSelector
{
return self;
}
/* /*
* This is the de_signated initialiser. * This is the de_signated initialiser.
@ -866,10 +845,6 @@ _arg_addr(NSInvocation *inv, int index)
} }
} }
- (void*) returnFrame: (arglist_t)argFrame
{
return 0;
}
@end @end
#endif #endif
@ -886,19 +861,6 @@ _arg_addr(NSInvocation *inv, int index)
{ {
return invocation; 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 - (void) forwardInvocation: (NSInvocation*)anInvocation
{ {
invocation = anInvocation; invocation = anInvocation;

View file

@ -28,6 +28,7 @@
*/ */
#import "common.h" #import "common.h"
#include <objc/encoding.h>
#define EXPOSE_NSMethodSignature_IVARS 1 #define EXPOSE_NSMethodSignature_IVARS 1
#import "Foundation/NSMethodSignature.h" #import "Foundation/NSMethodSignature.h"

View file

@ -37,7 +37,7 @@ NSString *
NSStringFromProtocol(Protocol *aProtocol) NSStringFromProtocol(Protocol *aProtocol)
{ {
if (aProtocol != (Protocol*)0) if (aProtocol != (Protocol*)0)
return [NSString stringWithUTF8String: (const char*)[aProtocol name]]; return [NSString stringWithUTF8String: protocol_getName(aProtocol)];
return nil; return nil;
} }

View file

@ -25,6 +25,10 @@
$Date$ $Revision$ $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 /* On some versions of mingw we need to work around bad function declarations
* by defining them away and doing the declarations ourself later. * by defining them away and doing the declarations ourself later.
*/ */
@ -101,7 +105,6 @@ static Class NSConstantStringClass;
Class isa; Class isa;
} }
- (Class) class; - (Class) class;
- (retval_t) forward:(SEL)aSel :(arglist_t)argFrame;
- (void) forwardInvocation: (NSInvocation*)anInvocation; - (void) forwardInvocation: (NSInvocation*)anInvocation;
- (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector; - (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector;
@end @end
@ -589,7 +592,7 @@ NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone)
int size; int size;
GC_descr gc_type; 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; gc_type = (GC_descr)aClass->gc_object_type;
size = class_getInstanceSize(aClass) + extraBytes; size = class_getInstanceSize(aClass) + extraBytes;
if (size % sizeof(void*) != 0) if (size % sizeof(void*) != 0)
@ -649,7 +652,7 @@ NSAllocateObject (Class aClass, NSUInteger extraBytes, NSZone *zone)
id new; id new;
int size; 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); size = class_getInstanceSize(aClass) + extraBytes + sizeof(struct obj_layout);
if (zone == 0) if (zone == 0)
{ {
@ -670,7 +673,7 @@ NSAllocateObject (Class aClass, NSUInteger extraBytes, NSZone *zone)
inline void inline void
NSDeallocateObject(id anObject) 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]; obj o = &((obj)anObject)[-1];
NSZone *z = o->zone; 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
/** /**
* <p> * <p>
@ -1202,7 +1110,7 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak));
*/ */
- (Class) class - (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); mth = GSGetMethod(self, aSelector, YES, YES);
if (mth == 0) if (mth == 0)
return nil; 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 * used by the Distributed Objects system, which the
* runtime does not maintain in classes. * 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; struct objc_method_description mth;
BOOL found = NO; for (int i=0 ; i<count ; i++)
{
mth = GSProtocolGetMethodDescriptionRecursive(protocols[i],
aSelector, YES, YES);
if (NULL == mth.types)
{
// Search for class method
mth = GSProtocolGetMethodDescriptionRecursive(protocols[i],
aSelector, YES, NO);
// FIXME: We should probably search optional methods here too.
}
while (found == NO && protocols != 0) if (NULL != mth.types) { break; }
{ }
NSUInteger i = 0; free(protocols);
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) if (types == 0)
@ -1590,20 +1487,6 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak));
aSelector ? sel_getName(aSelector) : "(null)"]; 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 * This method is called automatically to handle a message sent to
* the receiver for which the receivers class has no method.<br /> * the receiver for which the receivers class has no method.<br />
@ -2062,7 +1945,7 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak));
[NSException raise: NSInvalidArgumentException [NSException raise: NSInvalidArgumentException
format: @"%s +setVersion: may not set a negative version", format: @"%s +setVersion: may not set a negative version",
GSClassNameFromObject(self)]; GSClassNameFromObject(self)];
class_set_version(self, aVersion); class_setVersion(self, aVersion);
return self; return self;
} }
@ -2073,7 +1956,7 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak));
*/ */
+ (NSInteger) version + (NSInteger) version
{ {
return class_get_version(self); return class_getVersion(self);
} }
- (id) autoContentAccessingProxy - (id) autoContentAccessingProxy
@ -2155,15 +2038,6 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak));
return [self conformsToProtocol: aProtocol]; 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 + (IMP) instanceMethodFor: (SEL)aSel
{ {
return [self instanceMethodForSelector: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); mth = GSGetMethod(self, aSelector, YES, YES);
if (mth == 0) if (mth == 0)
return nil; return nil;
return [NSMethodSignature signatureWithObjCTypes:mth->method_types]; return [NSMethodSignature signatureWithObjCTypes: method_getTypeEncoding(mth)];
} }
- (IMP) methodFor: (SEL)aSel - (IMP) methodFor: (SEL)aSel
@ -2328,7 +2202,7 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak));
+ (NSInteger) streamVersion: (void*)aStream + (NSInteger) streamVersion: (void*)aStream
{ {
GSOnceMLog(@"[NSObject+streamVersion:] is deprecated ... do not use"); GSOnceMLog(@"[NSObject+streamVersion:] is deprecated ... do not use");
return class_get_version (self); return class_getVersion (self);
} }
- (id) read: (void*)aStream - (id) read: (void*)aStream
{ {
@ -2359,15 +2233,6 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak));
{ {
return NSMapGet(zombieMap, (void*)self); 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 - (void) forwardInvocation: (NSInvocation*)anInvocation
{ {
NSUInteger size = [[anInvocation methodSignature] methodReturnLength]; NSUInteger size = [[anInvocation methodSignature] methodReturnLength];

View file

@ -72,48 +72,15 @@
[super dealloc]; [super dealloc];
} }
- (struct objc_method_description*) _methodDescription: (SEL)aSelector - (const char *) _protocolTypeForSelector: (SEL)aSel
{ {
extern struct objc_method_description struct objc_method_description desc;
*GSDescriptionForInstanceMethod(Protocol *self, SEL aSel); desc = GSProtocolGetMethodDescriptionRecursive(_myProtocol, aSel, YES, YES);
extern struct objc_method_description if (desc.name == NULL && desc.types == NULL)
*GSDescriptionForClassMethod(Protocol *self, SEL aSel);
if (_myProtocol != nil && _myTarget != nil)
{ {
struct objc_method_description* mth; desc = GSProtocolGetMethodDescriptionRecursive(_myProtocol, aSel, 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 (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;
} }
return 0; return desc.types;
} }
/** /**
@ -125,7 +92,7 @@
{ {
const char *type; const char *type;
if ([self _methodDescription: [anInvocation selector]] == 0) if ([self _protocolTypeForSelector: [anInvocation selector]] == NULL)
{ {
if (GSObjCIsInstance(_myTarget)) if (GSObjCIsInstance(_myTarget))
{ {
@ -184,105 +151,17 @@
- (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector - (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) if (_myProtocol != nil)
{ {
const char *types = 0; const char *types = [self _protocolTypeForSelector: aSelector];
struct objc_method_description *desc; if (types == NULL)
desc = [self _methodDescription: aSelector];
if (desc != 0)
{
types = desc->types;
}
if (types == 0)
{ {
return nil; return nil;
} }
return [NSMethodSignature signatureWithObjCTypes: types]; return [NSMethodSignature signatureWithObjCTypes: types];
} }
c = object_getClass(self); return [super methodSignatureForSelector: aSelector];
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];
} }
/** /**

View file

@ -154,7 +154,7 @@ extern BOOL __objc_responds_to(id, SEL);
mth = GSGetMethod(self, aSelector, NO, YES); mth = GSGetMethod(self, aSelector, NO, YES);
if (mth != 0) if (mth != 0)
{ {
const char *types = mth->method_types; const char *types = method_getTypeEncoding(mth);
if (types != 0) if (types != 0)
{ {
@ -231,7 +231,7 @@ extern BOOL __objc_responds_to(id, SEL);
*/ */
- (Class) class - (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]; 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];
}
/** <override-subclass /> /** <override-subclass />
* Raises an <code>NSInvalidArgumentException</code>. * Raises an <code>NSInvalidArgumentException</code>.
*/ */
@ -400,7 +387,7 @@ extern BOOL __objc_responds_to(id, SEL);
mth = GSGetMethod(object_getClass(self), aSelector, YES, YES); mth = GSGetMethod(object_getClass(self), aSelector, YES, YES);
if (mth != 0) if (mth != 0)
{ {
const char *types = mth->method_types; const char *types = method_getTypeEncoding(mth);
if (types != 0) if (types != 0)
{ {
@ -561,7 +548,7 @@ extern BOOL __objc_responds_to(id, SEL);
*/ */
- (Class) superclass - (Class) superclass
{ {
return object_get_super_class(self); return class_getSuperclass(isa);
} }
/** /**

View file

@ -137,11 +137,6 @@ static SEL lenSel;
static SEL serSel; static SEL serSel;
static SEL setSel; static SEL setSel;
/* Compatibility methods from NEXTSTEP (Implemented in NSObject) */
@interface NSObject (Serializer)
- (retval_t) performv: (SEL)aSel :(arglist_t)argFrame;
@end
static void static void
initSerializerInfo(_NSSerializerInfo* info, NSMutableData *d, BOOL u) initSerializerInfo(_NSSerializerInfo* info, NSMutableData *d, BOOL u)
{ {
@ -793,17 +788,6 @@ deserializeFromInfo(_NSDeserializerInfo* info)
[super dealloc]; [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 - (BOOL) isEqual: (id)other
{ {
if (other == self) if (other == self)