1 // See instructions in weak.h
5 #include <objc/objc-internal.h>
9 static void *noop_fn(void *self, SEL _cmd __unused) {
12 static void *retain_fn(void *self, SEL _cmd __unused) {
13 void * (*fn)(void *) = (typeof(fn))_objc_rootRetain;
16 static void release_fn(void *self, SEL _cmd __unused) {
17 void (*fn)(void *) = (typeof(fn))_objc_rootRelease;
20 static void *autorelease_fn(void *self, SEL _cmd __unused) {
21 void * (*fn)(void *) = (typeof(fn))_objc_rootAutorelease;
27 @implementation MissingRoot
28 +(void) initialize { }
29 +(Class) class { return self; }
30 +(id) alloc { return _objc_rootAlloc(self); }
31 +(id) allocWithZone:(void*)zone { return _objc_rootAllocWithZone(self, (malloc_zone_t *)zone); }
32 -(id) init { return self; }
33 -(void) dealloc { _objc_rootDealloc(self); }
34 +(int) method { return 10; }
36 class_addMethod(self, sel_registerName("retain"), (IMP)retain_fn, "");
37 class_addMethod(self, sel_registerName("release"), (IMP)release_fn, "");
38 class_addMethod(self, sel_registerName("autorelease"), (IMP)autorelease_fn, "");
40 class_addMethod(object_getClass(self), sel_registerName("retain"), (IMP)noop_fn, "");
41 class_addMethod(object_getClass(self), sel_registerName("release"), (IMP)noop_fn, "");
42 class_addMethod(object_getClass(self), sel_registerName("autorelease"), (IMP)noop_fn, "");
48 @implementation MissingSuper
49 +(int) method { return 1+[super method]; }
50 -(id) init { self = [super init]; ivar = 100; return self; }
51 +(void) load { state++; }
56 @implementation NotMissingRoot
57 +(void) initialize { }
58 +(Class) class { return self; }
59 +(id) alloc { return _objc_rootAlloc(self); }
60 +(id) allocWithZone:(void*)zone { return _objc_rootAllocWithZone(self, (malloc_zone_t *)zone); }
61 -(id) init { return self; }
62 -(void) dealloc { _objc_rootDealloc(self); }
63 +(int) method { return 20; }
65 class_addMethod(self, sel_registerName("retain"), (IMP)retain_fn, "");
66 class_addMethod(self, sel_registerName("release"), (IMP)release_fn, "");
67 class_addMethod(self, sel_registerName("autorelease"), (IMP)autorelease_fn, "");
69 class_addMethod(object_getClass(self), sel_registerName("retain"), (IMP)noop_fn, "");
70 class_addMethod(object_getClass(self), sel_registerName("release"), (IMP)noop_fn, "");
71 class_addMethod(object_getClass(self), sel_registerName("autorelease"), (IMP)noop_fn, "");
77 @implementation NotMissingSuper
78 +(int) method { return 1+[super method]; }
79 -(id) init { self = [super init]; ivar = 200; return self; }
80 +(void) load { state++; }