4 #include "swift-class-def.m"
7 SWIFT_CLASS(SwiftSuper, NSObject, initSuper);
8 SWIFT_CLASS(SwiftSub, SwiftSuper, initSub);
10 // _objc_swiftMetadataInitializer hooks for the fake Swift classes
12 Class initSuper(Class cls __unused, void *arg __unused)
14 // This test provokes objc's callback out of superclass order.
15 // SwiftSub's init is first. SwiftSuper's init is never called.
17 fail("SwiftSuper's init should not have been called");
20 bool isRealized(Class cls)
22 // check the is-realized bits directly
25 # define mask (~(uintptr_t)7)
27 # define mask (~(uintptr_t)3)
29 #define RW_REALIZED (1<<31)
31 uintptr_t rw = ((uintptr_t *)cls)[4] & mask; // class_t->data
32 return ((uint32_t *)rw)[0] & RW_REALIZED; // class_rw_t->flags
35 static int SubInits = 0;
36 Class initSub(Class cls, void *arg)
38 testprintf("initSub callback\n");
40 testassert(SubInits == 0);
42 testassert(arg == nil);
43 testassert(0 == strcmp(class_getName(cls), "SwiftSub"));
44 testassert(cls == RawSwiftSub);
45 testassert(!isRealized(RawSwiftSuper));
46 testassert(!isRealized(RawSwiftSub));
48 testprintf("initSub beginning _objc_realizeClassFromSwift\n");
49 _objc_realizeClassFromSwift(cls, cls);
50 testprintf("initSub finished _objc_realizeClassFromSwift\n");
52 testassert(isRealized(RawSwiftSuper));
53 testassert(isRealized(RawSwiftSub));
61 testassert(SubInits == 0);
62 testprintf("calling [SwiftSub class]\n");
64 testprintf("finished [SwiftSub class]\n");
65 testassert(SubInits == 1);