OSX fixes

This commit is contained in:
Richard Frith-Macdonald 2025-03-09 15:39:21 +00:00
parent 667260aa26
commit 6655f4e00d
2 changed files with 19 additions and 13 deletions

View file

@ -69,15 +69,22 @@
#if defined(OBJC_CAP_ARC)
# include <objc/objc-arc.h>
#else
#elif !defined(__APPLE__)
GS_EXPORT void objc_copyWeak(id *dest, id *src);
GS_EXPORT void objc_destroyWeak(id *obj);
GS_EXPORT id objc_initWeak(id *addr, id obj);
GS_EXPORT id objc_loadWeak(id *object);
GS_EXPORT id objc_loadWeakRetained(id *addr);
GS_EXPORT void objc_moveWeak(id *dest, id *src);
GS_EXPORT id objc_loadWeak(id *object);
GS_EXPORT id objc_storeWeak(id *addr, id obj);
GS_EXPORT id objc_getAssociatedObject(id object, const void *key);
GS_EXPORT void objc_removeAssociatedObjects(id object);
GS_EXPORT void objc_setAssociatedObject(id object, const void *key,
id value, objc_AssociationPolicy policy);
/** objc_AssociationPolicy acts like a bitfield, but
* only specific combinations of flags are permitted.
*/
@ -105,12 +112,6 @@ typedef enum uintptr_t {
*/
OBJC_ASSOCIATION_COPY = 0x303
} objc_AssociationPolicy;
GS_EXPORT id objc_getAssociatedObject(id object, const void *key);
GS_EXPORT void objc_removeAssociatedObjects(id object);
GS_EXPORT void objc_setAssociatedObject(id object, const void *key,
id value, objc_AssociationPolicy policy);
#endif
/*
@ -124,9 +125,11 @@ GS_EXPORT void objc_setAssociatedObject(id object, const void *key,
#define _C_ULNG_LNG 'Q'
#endif
#if OBJC2RUNTIME
/* We have a real ObjC2 runtime.
*/
#if OBJC2RUNTIME
#include <objc/runtime.h>
#elif defined(__APPLE__)
#include <objc/runtime.h>
#else
/* We emulate an ObjC2 runtime.

View file

@ -336,12 +336,15 @@ main(int argc, char *argv[])
objc_storeWeak(&ref, obj);
PASS(ref != obj, "object is stored as weak reference")
rc = [obj retainCount];
got = objc_loadWeakRetained(&ref);
ENTER_POOL
got = objc_loadWeak(&ref);
PASS(got == obj && [obj retainCount] == rc + 1,
"objc_loadWeakRetained() returns original retained")
RELEASE(got);
"objc_loadWeak() returns original retained + 1")
LEAVE_POOL
PASS([obj retainCount] == rc, "objc_loadWeak() retan was autoreleased")
RELEASE(obj);
got = objc_loadWeakRetained(&ref);
got = objc_loadWeak(&ref);
PASS(got == nil, "load of deallocated object returns nil")
END_SET("weakref")