swiftMetadataInitializerRealloc-dylib1.m 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "test.h"
  2. #include "swift-class-def.m"
  3. SWIFT_CLASS(RealSwiftDylib1A, NSObject, nop);
  4. SWIFT_STUB_CLASS(SwiftDylib1A, initSwiftDylib1A);
  5. SWIFT_CLASS(RealSwiftDylib1B, NSObject, nop);
  6. SWIFT_STUB_CLASS(SwiftDylib1B, initSwiftDylib1B);
  7. int Dylib1AInits = 0;
  8. @interface SwiftDylib1A: NSObject @end
  9. @interface SwiftDylib1B: NSObject @end
  10. @implementation SwiftDylib1A (Category)
  11. - (const char *)dylib1ACategoryInSameDylib { return "dylib1ACategoryInSameDylib"; }
  12. @end
  13. @implementation SwiftDylib1B (Category)
  14. - (const char *)dylib1BCategoryInSameDylib { return "dylib1BCategoryInSameDylib"; }
  15. @end
  16. EXTERN_C Class initSwiftDylib1A(Class cls, void *arg)
  17. {
  18. Dylib1AInits++;
  19. testassert(arg == nil);
  20. testassert(cls == RawSwiftDylib1A);
  21. if (Dylib1AInits == 1)
  22. _objc_realizeClassFromSwift(RawRealSwiftDylib1A, cls);
  23. return RawRealSwiftDylib1A;
  24. }
  25. int Dylib1BInits = 0;
  26. EXTERN_C Class initSwiftDylib1B(Class cls, void *arg)
  27. {
  28. Dylib1BInits++;
  29. testassert(arg == nil);
  30. testassert(cls == RawSwiftDylib1B);
  31. if (Dylib1BInits == 1)
  32. _objc_realizeClassFromSwift(RawRealSwiftDylib1B, cls);
  33. return RawRealSwiftDylib1B;
  34. }
  35. EXTERN_C Class objc_loadClassref(_Nullable Class * _Nonnull clsref);
  36. void Dylib1Test(void) {
  37. testassert((uintptr_t)SwiftDylib1AClassref & 1);
  38. Class SwiftDylib1A = objc_loadClassref(&SwiftDylib1AClassref);
  39. testassert(((uintptr_t)SwiftDylib1AClassref & 1) == 0);
  40. testassert(SwiftDylib1A == [SwiftDylib1A class]);
  41. testassert(SwiftDylib1A == SwiftDylib1AClassref);
  42. testassert(Dylib1AInits == 2);
  43. testassert((uintptr_t)SwiftDylib1BClassref & 1);
  44. Class SwiftDylib1B = objc_loadClassref(&SwiftDylib1BClassref);
  45. testassert(((uintptr_t)SwiftDylib1BClassref & 1) == 0);
  46. testassert(SwiftDylib1B == [SwiftDylib1B class]);
  47. testassert(SwiftDylib1B == SwiftDylib1BClassref);
  48. testassert(Dylib1BInits == 2);
  49. }