Replace old code directly referencing class_pointer ivar with calls to the new runtime API treating objects as opaque pointers.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32243 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2011-02-20 12:28:12 +00:00
parent 0cb48d516b
commit 4ed081d410
4 changed files with 28 additions and 26 deletions

View file

@ -1,3 +1,11 @@
2011-02-20 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSFFIInvocation.m:
* Source/NSCopyObject.m:
* Source/NSObject.m:
Replace old code directly referencing class_pointer ivar with calls
to the new runtime API treating objects as opaque pointers.
2011-02-20 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSPortCoder.m:

View file

@ -22,8 +22,6 @@
Boston, MA 02111 USA.
*/
#define class_pointer isa
#import "common.h"
#define EXPOSE_NSInvocation_IVARS 1
#import "Foundation/NSException.h"
@ -266,7 +264,7 @@ static id gs_objc_proxy_lookup(id receiver, SEL op)
}
else
{
if (class_respondsToSelector(cls->class_pointer,
if (class_respondsToSelector(object_getClass(cls),
@selector(resolveInstanceMethod:)))
{
resolved = [cls resolveInstanceMethod: op];
@ -537,7 +535,7 @@ GSFFIInvocationCallback(ffi_cif *cif, void *retp, void **args, void *user)
obj = *(id *)args[0];
selector = *(SEL *)args[1];
if (!class_respondsToSelector(obj->class_pointer,
if (!class_respondsToSelector(object_getClass(obj),
@selector(forwardInvocation:)))
{
[NSException raise: NSInvalidArgumentException

View file

@ -29,11 +29,9 @@
NSObject *NSCopyObject(NSObject *anObject, NSUInteger extraBytes, NSZone *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);
Class c = object_getClass(anObject);
id copy = NSAllocateObject(c, extraBytes, zone);
memcpy(copy, anObject, class_getInstanceSize(c) + extraBytes);
return copy;
}

View file

@ -25,10 +25,6 @@
$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.
*/
@ -579,8 +575,8 @@ static void
GSFinalize(void* object, void* data)
{
[(id)object finalize];
AREM(((id)object)->class_pointer, (id)object);
((id)object)->class_pointer = (void*)0xdeadface;
AREM(object_getClass((id)object), (id)object);
object_setClass((id)object, (Classa)(void*)0xdeadface);
}
static BOOL
@ -622,7 +618,7 @@ NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone)
if (new != nil)
{
new->class_pointer = aClass;
object_setClass(new, aClass);
if (GSIsFinalizable(aClass))
{
/* We only do allocation counting for objects that can be
@ -670,7 +666,7 @@ NSAllocateObject (Class aClass, NSUInteger extraBytes, NSZone *zone)
memset (new, 0, size);
((obj)new)->zone = zone;
new = (id)&((obj)new)[1];
new->class_pointer = aClass;
object_setClass(new, aClass);
AADD(aClass, new);
}
return new;
@ -679,12 +675,12 @@ NSAllocateObject (Class aClass, NSUInteger extraBytes, NSZone *zone)
inline void
NSDeallocateObject(id anObject)
{
if ((anObject!=nil) && !class_isMetaClass(((id)anObject)->class_pointer))
if ((anObject!=nil) && !class_isMetaClass(object_getClass((id)anObject)))
{
obj o = &((obj)anObject)[-1];
NSZone *z = o->zone;
AREM(((id)anObject)->class_pointer, (id)anObject);
AREM(object_getClass((id)anObject), (id)anObject);
if (NSZombieEnabled == YES)
{
GSMakeZombie(anObject);
@ -695,7 +691,7 @@ NSDeallocateObject(id anObject)
}
else
{
((id)anObject)->class_pointer = (void*) 0xdeadface;
object_setClass((id)anObject, (Class)(void*)0xdeadface);
NSZoneFree(z, o);
}
}
@ -708,19 +704,21 @@ NSDeallocateObject(id anObject)
void
GSPrivateSwizzle(id o, Class c)
{
if ((Class)o->class_pointer != c)
Class oc = object_getClass(o);
if (oc != c)
{
#if GS_WITH_GC
/* We only do allocation counting for objects that can be
* finalised - for other objects we have no way of decrementing
* the count when the object is collected.
*/
if (GSIsFinalizable(o->class_pointer))
if (GSIsFinalizable(oc))
{
/* Already finalizable, so we just need to do any allocation
* accounting.
*/
AREM(o->class_pointer, o);
AREM(oc, o);
AADD(c, o);
}
else if (GSIsFinalizable(c))
@ -732,10 +730,10 @@ GSPrivateSwizzle(id o, Class c)
GC_REGISTER_FINALIZER (o, GSFinalize, NULL, NULL, NULL);
}
#else
AREM(o->class_pointer, o);
AREM(oc, o);
AADD(c, o);
#endif /* GS_WITH_GC */
o->class_pointer = c;
object_setClass(o, c);
}
}