]> git.saurik.com Git - apple/objc4.git/blob - test/weak2.m
objc4-781.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 void *retain_fn(void *self, SEL _cmd __unused) {
13 void * (*fn)(void *) = (typeof(fn))_objc_rootRetain;
14 return fn(self);
15 }
16 static void release_fn(void *self, SEL _cmd __unused) {
17 void (*fn)(void *) = (typeof(fn))_objc_rootRelease;
18 fn(self);
19 }
20 static void *autorelease_fn(void *self, SEL _cmd __unused) {
21 void * (*fn)(void *) = (typeof(fn))_objc_rootAutorelease;
22 return fn(self);
23 }
24
25 #if !defined(EMPTY)
26
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; }
35 +(void) load {
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, "");
39
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, "");
43
44 state++;
45 }
46 @end
47
48 @implementation MissingSuper
49 +(int) method { return 1+[super method]; }
50 -(id) init { self = [super init]; ivar = 100; return self; }
51 +(void) load { state++; }
52 @end
53
54 #endif
55
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; }
64 +(void) load {
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, "");
68
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, "");
72
73 state++;
74 }
75 @end
76
77 @implementation NotMissingSuper
78 +(int) method { return 1+[super method]; }
79 -(id) init { self = [super init]; ivar = 200; return self; }
80 +(void) load { state++; }
81 @end
82