From 2a206b02c25069a3db434a72094caada7e34004a Mon Sep 17 00:00:00 2001 From: theraven Date: Wed, 8 May 2013 10:40:23 +0000 Subject: [PATCH] Fix -finalize to correctly call the C++ destructors even for hidden classes. Since we're emulating the runtime here rather than calling it, we need to ensure that we emulate it correctly. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@36601 72102866-910b-0410-8b05-ffd578937521 --- Source/NSObject.m | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Source/NSObject.m b/Source/NSObject.m index 1f028ffb5..848054da8 100644 --- a/Source/NSObject.m +++ b/Source/NSObject.m @@ -1388,11 +1388,31 @@ static id gs_weak_load(id obj) - (void) finalize { Class destructorClass = Nil; - IMP destructor = 0; + IMP destructor = 0; + /* + * We're pretending to be the Objective-C runtime here, so we have to do some + * unsafe things (i.e. access the class directly, and not via the + * object_getClass() so that hidden classes get their destructors called. If + * the runtime supports small objects (those embedded in a pointer), then we + * must use object_getClass() for them, because they do not have an isa + * pointer (but can not have a hidden class interposed). + */ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-objc-pointer-introspection" +#pragma clang diagnostic ignored "-Wdeprecated-objc-isa-usage" #ifdef OBJC_SMALL_OBJECT_MASK if (((NSUInteger)self & OBJC_SMALL_OBJECT_MASK) == 0) + { + destructorClass = object_getClass(self); + } + else + { + destructorClass = isa; + } +#else + destructorClass = isa; #endif - destructorClass = object_getClass(self); +#pragma clang diagnostic pop /* C++ destructors must be called in the opposite order to their * creators, so start at the leaf class and then go up the tree until we