]> git.saurik.com Git - apple/objc4.git/blob - test/load-reentrant.m
objc4-818.2.tar.gz
[apple/objc4.git] / test / load-reentrant.m
1 /*
2 TEST_BUILD
3 $C{COMPILE} $DIR/load-reentrant.m -o load-reentrant.exe
4 $C{COMPILE} $DIR/load-reentrant2.m -o libload-reentrant2.dylib -bundle -bundle_loader load-reentrant.exe
5 END
6 */
7
8 #include "test.h"
9 #include <dlfcn.h>
10
11 int state1 = 0;
12 int *state2_p;
13
14 OBJC_ROOT_CLASS
15 @interface One @end
16 @implementation One
17 +(void)load
18 {
19 state1 = 111;
20
21 // Re-entrant +load doesn't get to complete until we do
22 void *dlh = dlopen("libload-reentrant2.dylib", RTLD_LAZY);
23 testassert(dlh);
24 state2_p = (int *)dlsym(dlh, "state2");
25 testassert(state2_p);
26 testassert(*state2_p == 0);
27
28 state1 = 1;
29 }
30 @end
31
32 int main()
33 {
34 testassert(state1 == 1 && state2_p && *state2_p == 2);
35 succeed(__FILE__);
36 }