]> git.saurik.com Git - apple/objc4.git/blob - test/badCache2.m
objc4-646.tar.gz
[apple/objc4.git] / test / badCache2.m
1 /*
2 TEST_CRASHES
3 TEST_RUN_OUTPUT
4 objc1
5 OK: badCache2.m
6 OR
7 crash now
8 objc\[\d+\]: Method cache corrupted.*
9 objc\[\d+\]: .*
10 objc\[\d+\]: .*
11 objc\[\d+\]: .*
12 objc\[\d+\]: .*
13 objc\[\d+\]: Method cache corrupted\.
14 CRASHED: SIG(ILL|TRAP)
15 END
16 */
17
18
19 #include "test.h"
20
21 #if !__OBJC2__ || __arm__
22
23 int main()
24 {
25 fprintf(stderr, "objc1\n");
26 succeed(__FILE__);
27 }
28
29 #else
30
31 #include "testroot.i"
32
33 #if __LP64__
34 typedef uint32_t mask_t;
35 #else
36 typedef uint16_t mask_t;
37 #endif
38
39 struct bucket_t {
40 void *sel;
41 void *imp;
42 };
43
44 struct cache_t {
45 struct bucket_t *buckets;
46 mask_t mask;
47 mask_t occupied;
48 };
49
50 struct class_t {
51 void *isa;
52 void *supercls;
53 struct cache_t cache;
54 };
55
56 @interface Subclass : TestRoot @end
57 @implementation Subclass @end
58
59 int main()
60 {
61 Class cls = [TestRoot class];
62 id obj = [cls new];
63 [obj self];
64
65 // Test cache::find by clobbering the cache and then adding a method
66 struct cache_t *cache = &((__bridge struct class_t *)cls)->cache;
67 cache->mask = 0;
68 cache->buckets[0].sel = (void*)~0;
69 cache->buckets[0].imp = (void*)~0;
70
71 fprintf(stderr, "crash now\n");
72 class_addMethod(cls, @selector(fake:o:rama:), nil, nil);
73
74 fail("should have crashed");
75 }
76
77 #endif