associationForbidden.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "testroot.i"
  2. @interface Normal : TestRoot
  3. @end
  4. @implementation Normal
  5. @end
  6. @interface Forbidden : TestRoot
  7. @end
  8. @implementation Forbidden
  9. @end
  10. struct minimal_unrealized_class {
  11. void *isa;
  12. void *superclass;
  13. void *cachePtr;
  14. uintptr_t maskAndOccupied;
  15. struct minimal_class_ro *ro;
  16. };
  17. struct minimal_class_ro {
  18. uint32_t flags;
  19. };
  20. extern struct minimal_unrealized_class OBJC_CLASS_$_Forbidden;
  21. #define RO_FORBIDS_ASSOCIATED_OBJECTS (1<<10)
  22. static void *key = &key;
  23. static void test(void);
  24. int main()
  25. {
  26. struct minimal_unrealized_class *localForbidden = &OBJC_CLASS_$_Forbidden;
  27. localForbidden->ro->flags |= RO_FORBIDS_ASSOCIATED_OBJECTS;
  28. test();
  29. }
  30. static inline void ShouldSucceed(id obj) {
  31. objc_setAssociatedObject(obj, key, obj, OBJC_ASSOCIATION_ASSIGN);
  32. id assoc = objc_getAssociatedObject(obj, key);
  33. fprintf(stderr, "Associated object is %p\n", assoc);
  34. testassert(obj == assoc);
  35. }
  36. static inline void ShouldFail(id obj) {
  37. objc_setAssociatedObject(obj, key, obj, OBJC_ASSOCIATION_ASSIGN);
  38. fail("should have crashed trying to set the associated object");
  39. }