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
This commit is contained in:
David Chisnall 2013-05-08 10:40:23 +00:00
parent c3a9c60b14
commit 8078bd8bee

View file

@ -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