Repository navigation
Fix object_setClass with hidden classes. - #442
Conversation
The original implementation just pivoted the `isa` pointer. This causes hidden classes to leak and also causes any state associated with them (in particular, things like associated objects and `@synchronise` locks) to lose their attachment to the object. The correct thing is to change the superclass of the hidden class to be the new class. This is a bit more annoying because it also requires recomputing dtables and so on. Fixes #441
Ubuntu got upgraded and embeds version numbers in some of the cross-compile packages. The newer images also have newer LLVM versions (and don't have the older ones).
55708d2 to
959408f
Compare
|
This seems to be causing multiple test failures in libs-base: https://github.com/gnustep/libs-base/actions/runs/44330864867 I think the issue is that hidden classes share their superclass's metaclass, so The diff --git a/Test/AssociateSetClass.m b/Test/AssociateSetClass.m
index bd11450..acbdf27 100644
--- a/Test/AssociateSetClass.m
+++ b/Test/AssociateSetClass.m
@@ -5,9 +5,13 @@ BOOL deallocCalled = NO;
static char key;
@interface Observed : Test
+- (void)ping;
@end
@implementation Observed
+- (void)ping
+{
+}
@end
@interface Associated : Test
@@ -32,15 +36,20 @@ int main(int argc, const char * argv[]) {
objc_setAssociatedObject(object, &key, value, OBJC_ASSOCIATION_RETAIN);
[value release];
assert(objc_getAssociatedObject(object, &key) == value);
+ [object ping];
object_setClass(object, subclass);
assert(object_getClass(object) == subclass);
+ assert(class_getSuperclass(object_getClass([Observed class])) ==
+ object_getClass([Test class]));
fprintf(stderr, "Association after object_setClass: %p (expected %p)\n",
objc_getAssociatedObject(object, &key), value);
assert(objc_getAssociatedObject(object, &key) == value);
object_setClass(object, [Observed class]);
+ assert(class_getSuperclass(object_getClass([Observed class])) ==
+ object_getClass([Test class]));
fprintf(stderr, "Association after object_setClass: %p (expected %p)\n",
objc_getAssociatedObject(object, &key), value);
assert(objc_getAssociatedObject(object, &key) == value);Do we need to set the isa to the new superclass's metaclass when the class is a hidden class in |
|
As a temporary workaround for this object_setClass() issue, I modified base to copy the class pointer directly to the address of the start of the instance. Ugly/fragile, but I guess it will do until object_setClass() is working or we have some other alternative. |
|
I'm still recovering from a cold and my head is too full of cotton wool to fix this. Happy to review a PR if someone else wants to try though... |
The original implementation just pivoted the
isapointer. This causes hidden classes to leak and also causes any state associated with them (in particular, things like associated objects and@synchroniselocks) to lose their attachment to the object. The correct thing is to change the superclass of the hidden class to be the new class. This is a bit more annoying because it also requires recomputing dtables and so on.Fixes #441