Repository navigation
Attempt to fix bugs introduced in #442 - #443
Merged
Merged
Conversation
Member
Author
|
Trying to work on this code while unwell was a mistake. The original contained a fix to work around an observed problem and not the root cause. This should fix it. Please test! |
|
Hi @davidchisnall, The following test case is the source of the output above. #ifdef __APPLE__
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#include <assert.h>
#define RootObject NSObject
#define RUNTIME "Apple"
#else
#import "Test.h"
#define RootObject Test
#define RUNTIME "libobjc2"
#endif
#include <stdio.h>
static char key;
@interface Observed : RootObject
@end
@implementation Observed
@end
static BOOL metaclassChainEnds(Class cls)
{
Class seen[32];
int count = 0;
for (Class meta = object_getClass(cls) ; meta != Nil ; meta = class_getSuperclass(meta))
{
for (int i = 0 ; i < count ; i++)
{
if (seen[i] == meta)
{
return NO;
}
}
if (count == 32)
{
return NO;
}
seen[count++] = meta;
}
return YES;
}
static void check(const char *when, Class observedMeta, Class subclassMeta, Class subclass)
{
fprintf(stderr, RUNTIME ": %s: superclass of Observed's metaclass: %s, of ObservedSubclass's metaclass: %s\n",
when, class_getName(class_getSuperclass(observedMeta)), class_getName(class_getSuperclass(subclassMeta)));
assert(class_getSuperclass(observedMeta) == object_getClass([RootObject class]));
assert(class_getSuperclass(subclassMeta) == observedMeta);
assert(metaclassChainEnds([Observed class]));
assert(metaclassChainEnds(subclass));
}
int main(void)
{
Class subclass = objc_allocateClassPair([Observed class], "ObservedSubclass", 0);
objc_registerClassPair(subclass);
Class observedMeta = object_getClass([Observed class]);
Class subclassMeta = object_getClass(subclass);
check("before", observedMeta, subclassMeta, subclass);
@autoreleasepool
{
Observed *object = [Observed new];
Observed *value = [Observed new];
objc_setAssociatedObject(object, &key, value, OBJC_ASSOCIATION_RETAIN);
[value release];
object_setClass(object, subclass);
assert(object_getClass(object) == subclass);
check("after object_setClass to the subclass", observedMeta, subclassMeta, subclass);
object_setClass(object, [Observed class]);
assert(object_getClass(object) == [Observed class]);
check("after object_setClass back", observedMeta, subclassMeta, subclass);
[object release];
}
return 0;
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.