diff --git a/arc.m b/arc.m index 397265e..4775beb 100644 --- a/arc.m +++ b/arc.m @@ -175,6 +175,13 @@ static const long weak_mask = ((size_t)1)<<((sizeof(size_t)*8)-1); */ static const long refcount_mask = ~weak_mask; +size_t object_getRetainCount_np(id obj) +{ + uintptr_t *refCount = ((uintptr_t*)obj) - 1; + uintptr_t refCountVal = __sync_fetch_and_add(refCount, 0); + return (((size_t)refCountVal) & refcount_mask) + 1; +} + id objc_retain_fast_np(id obj) { uintptr_t *refCount = ((uintptr_t*)obj) - 1; diff --git a/objc/objc-arc.h b/objc/objc-arc.h index 75dde84..32ecb7a 100644 --- a/objc/objc-arc.h +++ b/objc/objc-arc.h @@ -111,6 +111,10 @@ void objc_release_fast_np(id obj) OBJC_NONPORTABLE; * ARC-compatible classes. */ BOOL objc_release_fast_no_destroy_np(id obj) OBJC_NONPORTABLE; +/** + * Returns the retain count of an object. + */ +size_t object_getRetainCount_np(id obj) OBJC_NONPORTABLE; /** * Releases an object. Equivalent to [obj release]. */