load-reentrant.m 723 B

123456789101112131415161718192021222324252627282930313233343536
  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. #include "test.h"
  8. #include <dlfcn.h>
  9. int state1 = 0;
  10. int *state2_p;
  11. OBJC_ROOT_CLASS
  12. @interface One @end
  13. @implementation One
  14. +(void)load
  15. {
  16. state1 = 111;
  17. // Re-entrant +load doesn't get to complete until we do
  18. void *dlh = dlopen("libload-reentrant2.dylib", RTLD_LAZY);
  19. testassert(dlh);
  20. state2_p = (int *)dlsym(dlh, "state2");
  21. testassert(state2_p);
  22. testassert(*state2_p == 0);
  23. state1 = 1;
  24. }
  25. @end
  26. int main()
  27. {
  28. testassert(state1 == 1 && state2_p && *state2_p == 2);
  29. succeed(__FILE__);
  30. }