]> git.saurik.com Git - apple/objc4.git/blob - test/load-noobjc.m
objc4-781.2.tar.gz
[apple/objc4.git] / test / load-noobjc.m
1 /*
2 TEST_BUILD
3 $C{COMPILE} $DIR/load-noobjc.m -o load-noobjc.exe
4 $C{COMPILE} $DIR/load-noobjc2.m -o libload-noobjc2.dylib -bundle -bundle_loader load-noobjc.exe
5 $C{COMPILE} $DIR/load-noobjc3.m -o libload-noobjc3.dylib -bundle -bundle_loader load-noobjc.exe
6 END
7 */
8
9 #include "test.h"
10 #include <dlfcn.h>
11
12 int state = 0;
13 semaphore_t go;
14
15 void *thread(void *arg __unused)
16 {
17 dlopen("libload-noobjc2.dylib", RTLD_LAZY);
18 fail("dlopen should not have returned");
19 }
20
21 int main()
22 {
23 semaphore_create(mach_task_self(), &go, SYNC_POLICY_FIFO, 0);
24
25 pthread_t th;
26 pthread_create(&th, nil, &thread, nil);
27
28 // Wait for thread to stop in libload-noobjc2's +load method.
29 semaphore_wait(go);
30
31 // run nooobjc3's constructor function.
32 // There's no objc code here so it shouldn't require the +load lock.
33 void *dlh = dlopen("libload-noobjc3.dylib", RTLD_LAZY);
34 testassert(dlh);
35 testassert(state == 1);
36
37 succeed(__FILE__);
38 }