]> git.saurik.com Git - apple/objc4.git/blob - test/weak2.m
objc4-532.2.tar.gz
[apple/objc4.git] / test / weak2.m
1 // See instructions in weak.h
2
3 #include "test.h"
4 #include "weak.h"
5 #include <objc/objc-internal.h>
6
7 int state = 0;
8
9 static void *noop_fn(void *self, SEL _cmd __unused) {
10 return self;
11 }
12 static id __unsafe_unretained retain_fn(id __unsafe_unretained self, SEL _cmd __unused) {
13 return _objc_rootRetain(self);
14 }
15 static void release_fn(id __unsafe_unretained self, SEL _cmd __unused) {
16 _objc_rootRelease(self);
17 }
18 static void autorelease_fn(id __unsafe_unretained self, SEL _cmd __unused) {
19 _objc_rootAutorelease(self);
20 }
21
22 #if !defined(EMPTY)
23
24 @implementation MissingRoot
25 +(void) initialize { }
26 +(Class) class { return self; }
27 +(id) alloc { return _objc_rootAlloc(self); }
28 +(id) allocWithZone:(void*)zone { return _objc_rootAllocWithZone(self, (malloc_zone_t *)zone); }
29 -(id) init { return self; }
30 -(void) dealloc { _objc_rootDealloc(self); }
31 +(int) method { return 10; }
32 +(void) load {
33 class_addMethod(self, sel_registerName("retain"), (IMP)retain_fn, "");
34 class_addMethod(self, sel_registerName("release"), (IMP)release_fn, "");
35 class_addMethod(self, sel_registerName("autorelease"), (IMP)autorelease_fn, "");
36
37 class_addMethod(object_getClass(self), sel_registerName("retain"), (IMP)noop_fn, "");
38 class_addMethod(object_getClass(self), sel_registerName("release"), (IMP)noop_fn, "");
39 class_addMethod(object_getClass(self), sel_registerName("autorelease"), (IMP)noop_fn, "");
40
41 state++;
42 }
43 @end
44
45 @implementation MissingSuper
46 +(int) method { return 1+[super method]; }
47 -(id) init { self = [super init]; ivar = 100; return self; }
48 +(void) load { state++; }
49 @end
50
51 #endif
52
53 @implementation NotMissingRoot
54 +(void) initialize { }
55 +(Class) class { return self; }
56 +(id) alloc { return _objc_rootAlloc(self); }
57 +(id) allocWithZone:(void*)zone { return _objc_rootAllocWithZone(self, (malloc_zone_t *)zone); }
58 -(id) init { return self; }
59 -(void) dealloc { _objc_rootDealloc(self); }
60 +(int) method { return 20; }
61 +(void) load {
62 class_addMethod(self, sel_registerName("retain"), (IMP)retain_fn, "");
63 class_addMethod(self, sel_registerName("release"), (IMP)release_fn, "");
64 class_addMethod(self, sel_registerName("autorelease"), (IMP)autorelease_fn, "");
65
66 class_addMethod(object_getClass(self), sel_registerName("retain"), (IMP)noop_fn, "");
67 class_addMethod(object_getClass(self), sel_registerName("release"), (IMP)noop_fn, "");
68 class_addMethod(object_getClass(self), sel_registerName("autorelease"), (IMP)noop_fn, "");
69
70 state++;
71 }
72 @end
73
74 @implementation NotMissingSuper
75 +(int) method { return 1+[super method]; }
76 -(id) init { self = [super init]; ivar = 200; return self; }
77 +(void) load { state++; }
78 @end
79