Retain count fixes

This commit is contained in:
rfm 2024-11-10 14:14:42 +00:00
parent 44222342b0
commit 544dcce482
6 changed files with 111 additions and 21 deletions

View file

@ -87,18 +87,16 @@ typedef GSIMapNode_t *GSIMapNode;
(M->legacy ? M->cb.old.release(M, X.ptr) \
: IS_WEAK(M) ? nil : pointerFunctionsRelinquish(&M->cb.pf, &X.ptr))
#define GSI_MAP_RETAIN_KEY(M, X)\
(M->legacy ? M->cb.old.retain(M, X.ptr) \
: IS_WEAK(M) ? nil : pointerFunctionsAssign(\
&M->cb.pf, &X.ptr, pointerFunctionsAcquire(&M->cb.pf, X.ptr)))
(M->legacy ? M->cb.old.retain(M, X.ptr) : (IS_WEAK(M) ? nil : X.ptr))
#define GSI_MAP_ZEROED(M)\
(M->legacy ? 0 \
: (IS_WEAK(M) ? YES : NO))
#define GSI_MAP_WRITE_KEY(M, addr, x) \
if (M->legacy) \
*(addr) = x;\
else\
pointerFunctionsAssign(&M->cb.pf, (void**)addr, (x).obj);
if (M->legacy) \
*(addr) = x;\
else\
pointerFunctionsReplace(&M->cb.pf, (void**)addr, (x).obj);
#define GSI_MAP_READ_KEY(M,addr) \
(M->legacy ? *(addr) :\
(__typeof__(*addr))pointerFunctionsRead(&M->cb.pf, (void**)addr))

View file

@ -94,16 +94,12 @@ typedef GSIMapNode_t *GSIMapNode;
(M->legacy ? M->cb.old.k.release(M, X.ptr) \
: IS_WEAK_KEY(M) ? nil : pointerFunctionsRelinquish(&M->cb.pf.k, &X.ptr))
#define GSI_MAP_RETAIN_KEY(M, X)\
(M->legacy ? M->cb.old.k.retain(M, X.ptr) \
: IS_WEAK_KEY(M) ? nil : pointerFunctionsAssign(&M->cb.pf.k, &X.ptr,\
pointerFunctionsAcquire(&M->cb.pf.k, X.ptr)))
(M->legacy ? M->cb.old.k.retain(M, X.ptr) : (IS_WEAK_KEY(M) ? nil : X.ptr))
#define GSI_MAP_RELEASE_VAL(M, X)\
(M->legacy ? M->cb.old.v.release(M, X.ptr) \
: IS_WEAK_VALUE(M) ? nil : pointerFunctionsRelinquish(&M->cb.pf.v, &X.ptr))
#define GSI_MAP_RETAIN_VAL(M, X)\
(M->legacy ? M->cb.old.v.retain(M, X.ptr) \
: IS_WEAK_VALUE(M) ? nil : pointerFunctionsAssign(&M->cb.pf.v, &X.ptr,\
pointerFunctionsAcquire(&M->cb.pf.v, X.ptr)))
(M->legacy ? M->cb.old.v.retain(M, X.ptr) : (IS_WEAK_VALUE(M) ? nil : &X.ptr))
/* The GSI_MAP_WRITE_KEY() and GSI_MAP_WRITE_VAL() macros are expectd to
* write without retain (GSI_MAP RETAIN macros are executed separately)
@ -114,14 +110,12 @@ typedef GSIMapNode_t *GSIMapNode;
if (M->legacy) \
*(addr) = x;\
else\
(IS_WEAK_KEY(M) ? pointerFunctionsAssign(&M->cb.pf.k, (void**)addr,\
(x).obj) : (*(id*)(addr) = (x).obj));
pointerFunctionsReplace(&M->cb.pf.k, (void**)addr, (x).obj);
#define GSI_MAP_WRITE_VAL(M, addr, x) \
if (M->legacy) \
*(addr) = x;\
else\
(IS_WEAK_VALUE(M) ? pointerFunctionsAssign(&M->cb.pf.v, (void**)addr,\
(x).obj) : (*(id*)(addr) = (x).obj));
pointerFunctionsReplace(&M->cb.pf.v, (void**)addr, (x).obj);
#define GSI_MAP_READ_KEY(M,addr) \
(M->legacy ? *(addr)\
: (__typeof__(*addr))pointerFunctionsRead(&M->cb.pf.k, (void**)addr))

View file

@ -187,6 +187,8 @@ pointerFunctionsRelinquish(PFInfo *PF, void **itemptr)
(*PF->relinquishFunction)(*itemptr, PF->sizeFunction);
if (memoryType(PF->options, NSPointerFunctionsWeakMemory))
WEAK_WRITE(itemptr, 0);
else if (memoryType(PF->options, NSPointerFunctionsStrongMemory))
STRONG_WRITE(itemptr, 0);
else
*itemptr = 0;
}
@ -203,7 +205,7 @@ pointerFunctionsReplace(PFInfo *PF, void **dst, void *src)
if (PF->relinquishFunction != 0)
(*PF->relinquishFunction)(*dst, PF->sizeFunction);
if (memoryType(PF->options, NSPointerFunctionsWeakMemory))
WEAK_WRITE(dst, 0);
WEAK_WRITE(dst, src);
else
*dst = src;
}