Sun 05 Jan 2014 06:30:36 PM UTC, original submission:
NSObject -finalize method does not call C++ destructors correctly in every case. This breaks libobjc2's objc_setAssociatedObject retain policy. I've attached a GNUStep style test that fails to demonstrate this.
The problem looks like it was this optimization:
/* 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
* get to the root class. As a small optimisation, we don't bother
* visiting any classes that don't have an implementation of this method
* (including one inherited from a superclass).
*
* Care must be taken not to call inherited .cxx_destruct methods.
*/
while (class_respondsToSelector(destructorClass, cxx_destruct))
{
IMP newDestructor;
newDestructor
= class_getMethodImplementation(destructorClass, cxx_destruct);
destructorClass = class_getSuperclass(destructorClass);
if (newDestructor != destructor)
{
newDestructor(self, cxx_destruct);
destructor = newDestructor;
}
}
In my local tree I've replaced it with:
while (destructorClass)
{
if (class_respondsToSelector(destructorClass, cxx_destruct))
{
IMP newDestructor = class_getMethodImplementation(destructorClass, cxx_destruct);
destructorClass = class_getSuperclass(destructorClass);
if (newDestructor != destructor)
{
newDestructor(self, cxx_destruct);
destructor = newDestructor;
}
}
else
{
destructorClass = class_getSuperclass(destructorClass);
}
}
And I've been using it for about a month now with no ill effect.
|