diff --git a/Test/AssociatedObject.m b/Test/AssociatedObject.m index e41da6f..f3a50e1 100644 --- a/Test/AssociatedObject.m +++ b/Test/AssociatedObject.m @@ -1,4 +1,6 @@ #include "Test.h" +#include +#include static BOOL deallocCalled = NO; static const char* objc_setAssociatedObjectKey = "objc_setAssociatedObjectKey"; @@ -36,4 +38,24 @@ int main(void) [holder release]; assert(deallocCalled); + + object = [Associated new]; + holder = [Test new]; + for (uintptr_t i = 1; i <= 20; ++i) + { + objc_setAssociatedObject(holder, (void*)i, object, OBJC_ASSOCIATION_RETAIN); + } + int lost = 0; + for (uintptr_t i = 1; i <= 20; ++i) + { + if (object != objc_getAssociatedObject(holder, (void*)i)) + { + fprintf(stderr, "lost object %" PRIuPTR "\n", i); + ++lost; + } + } + [holder release]; + [object release]; + assert(0 == lost); + return 0; } diff --git a/associate.m b/associate.m index d3ab8a9..8f9d7ab 100644 --- a/associate.m +++ b/associate.m @@ -75,14 +75,16 @@ static BOOL isAtomic(uintptr_t policy) static struct reference* findReference(struct reference_list *list, void *key) { - if (NULL == list) { return NULL; } - - for (int i=0 ; ilist[i].key == key) + for (int i=0 ; ilist[i]; + if (list->list[i].key == key) + { + return &list->list[i]; + } } + list = list->next; } return NULL; }