mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +00:00
hash/map table and pointer functions fixups
This commit is contained in:
parent
c981920679
commit
b78b2e2030
8 changed files with 290 additions and 89 deletions
|
@ -83,22 +83,27 @@ typedef GSIMapNode_t *GSIMapNode;
|
|||
#define GSI_MAP_EQUAL(M, X, Y)\
|
||||
(M->legacy ? M->cb.old.isEqual(M, X.ptr, Y.ptr) \
|
||||
: pointerFunctionsEqual(&M->cb.pf, X.ptr, Y.ptr))
|
||||
#define GSI_MAP_RELEASE_KEY(M, X)\
|
||||
(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)))
|
||||
#define GSI_MAP_ZEROED(M)\
|
||||
(M->legacy ? 0 \
|
||||
: (IS_WEAK(M) ? YES : NO))
|
||||
(M->legacy ? 0 : (IS_WEAK(M) ? YES : NO))
|
||||
|
||||
/* NSPointerFunctions provides functions which combine the actions of
|
||||
* memory allocation/deallocation with those of assignment, so we make
|
||||
* the separete retain/release macros a no-op nd do all the work in the
|
||||
* store/clear macros.
|
||||
*/
|
||||
#define GSI_MAP_RELEASE_KEY(M, X)
|
||||
#define GSI_MAP_RETAIN_KEY(M, X) nil
|
||||
#define GSI_MAP_CLEAR_KEY(M, addr)\
|
||||
if (M->legacy) \
|
||||
{ M->cb.old.release(M, (*addr).ptr); (*addr).ptr = 0; }\
|
||||
else\
|
||||
pointerFunctionsRelinquish(&M->cb.pf, (void**)addr);
|
||||
#define GSI_MAP_STORE_KEY(M, addr, x)\
|
||||
if (M->legacy)\
|
||||
{ *(addr) = x; M->cb.old.retain(M, (*addr).ptr); }\
|
||||
else\
|
||||
pointerFunctionsReplace(&M->cb.pf, (void**)addr, (x).obj);
|
||||
|
||||
#define GSI_MAP_WRITE_KEY(M, addr, x) \
|
||||
if (M->legacy) \
|
||||
*(addr) = x;\
|
||||
else\
|
||||
pointerFunctionsAssign(&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))
|
||||
|
|
|
@ -90,38 +90,39 @@ typedef GSIMapNode_t *GSIMapNode;
|
|||
#define GSI_MAP_EQUAL(M, X, Y)\
|
||||
(M->legacy ? M->cb.old.k.isEqual(M, X.ptr, Y.ptr) \
|
||||
: pointerFunctionsEqual(&M->cb.pf.k, X.ptr, Y.ptr))
|
||||
#define GSI_MAP_RELEASE_KEY(M, X)\
|
||||
(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)))
|
||||
#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)))
|
||||
|
||||
/* The GSI_MAP_WRITE_KEY() and GSI_MAP_WRITE_VAL() macros are expectd to
|
||||
* write without retain (GSI_MAP RETAIN macros are executed separately)
|
||||
* so they can't use pointerFunctionsAssign() unless working with weak
|
||||
* references.
|
||||
/* NSPointerFunctions provides functions which combine the actions of
|
||||
* memory allocation/deallocation with those of assignment, so we make
|
||||
* the separete retain/release macros a no-op nd do all the work in the
|
||||
* store/clear macros.
|
||||
*/
|
||||
#define GSI_MAP_WRITE_KEY(M, addr, x) \
|
||||
|
||||
#define GSI_MAP_RELEASE_KEY(M, X)
|
||||
#define GSI_MAP_RETAIN_KEY(M, X) nil
|
||||
#define GSI_MAP_CLEAR_KEY(M, addr)\
|
||||
if (M->legacy) \
|
||||
*(addr) = x;\
|
||||
{ M->cb.old.k.release(M, (*addr).ptr); (*addr).ptr = 0; }\
|
||||
else\
|
||||
(IS_WEAK_KEY(M) ? pointerFunctionsAssign(&M->cb.pf.k, (void**)addr,\
|
||||
(x).obj) : (*(id*)(addr) = (x).obj));
|
||||
#define GSI_MAP_WRITE_VAL(M, addr, x) \
|
||||
pointerFunctionsRelinquish(&M->cb.pf.k, (void**)addr);
|
||||
#define GSI_MAP_STORE_KEY(M, addr, x)\
|
||||
if (M->legacy)\
|
||||
{ *(addr) = x; M->cb.old.k.retain(M, (*addr).ptr); }\
|
||||
else\
|
||||
pointerFunctionsReplace(&M->cb.pf.k, (void**)addr, (x).obj);
|
||||
|
||||
#define GSI_MAP_RELEASE_VALUE(M, X)
|
||||
#define GSI_MAP_RETAIN_VALUE(M, X) nil
|
||||
#define GSI_MAP_CLEAR_VALUE(M, addr)\
|
||||
if (M->legacy) \
|
||||
*(addr) = x;\
|
||||
{ M->cb.old.v.release(M, (*addr).ptr); (*addr).ptr = 0; }\
|
||||
else\
|
||||
(IS_WEAK_VALUE(M) ? pointerFunctionsAssign(&M->cb.pf.v, (void**)addr,\
|
||||
(x).obj) : (*(id*)(addr) = (x).obj));
|
||||
pointerFunctionsRelinquish(&M->cb.pf.v, (void**)addr);
|
||||
#define GSI_MAP_STORE_VALUE(M, addr, x)\
|
||||
if (M->legacy)\
|
||||
{ *(addr) = x; M->cb.old.v.retain(M, (*addr).ptr); }\
|
||||
else\
|
||||
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))
|
||||
|
@ -638,13 +639,9 @@ NSMapInsert(NSMapTable *table, const void *key, const void *value)
|
|||
GSIMapAddPair(t, (GSIMapKey)key, (GSIMapVal)value);
|
||||
t->version++;
|
||||
}
|
||||
else if (n->value.ptr != value)
|
||||
else if (GSI_MAP_READ_VALUE(t, &n->value).ptr != value)
|
||||
{
|
||||
GSIMapVal tmp = n->value;
|
||||
|
||||
n->value = (GSIMapVal)value;
|
||||
GSI_MAP_RETAIN_VAL(t, n->value);
|
||||
GSI_MAP_RELEASE_VAL(t, tmp);
|
||||
GSI_MAP_STORE_VALUE(t, &n->value, (GSIMapVal)value);
|
||||
t->version++;
|
||||
}
|
||||
}
|
||||
|
@ -1383,9 +1380,7 @@ const NSMapTableValueCallBacks NSOwnedPointerMapValueCallBacks =
|
|||
{
|
||||
if (GSI_MAP_READ_VALUE(self, &node->value).obj != anObject)
|
||||
{
|
||||
GSI_MAP_RELEASE_VAL(self, node->value);
|
||||
GSI_MAP_WRITE_VAL(self, &node->value, (GSIMapVal)anObject);
|
||||
GSI_MAP_RETAIN_VAL(self, node->value);
|
||||
GSI_MAP_STORE_VALUE(self, &node->value, (GSIMapVal)anObject);
|
||||
version++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -182,7 +182,6 @@ pointerFunctionsEqual(PFInfo *PF, void *item1, void *item2)
|
|||
static inline void
|
||||
pointerFunctionsRelinquish(PFInfo *PF, void **itemptr)
|
||||
{
|
||||
|
||||
if (PF->relinquishFunction != 0)
|
||||
(*PF->relinquishFunction)(*itemptr, PF->sizeFunction);
|
||||
if (memoryType(PF->options, NSPointerFunctionsWeakMemory))
|
||||
|
@ -203,7 +202,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;
|
||||
}
|
||||
|
|
|
@ -300,7 +300,7 @@ relinquishRetainedMemory(const void *item,
|
|||
else
|
||||
{
|
||||
_x.acquireFunction = acquireRetainedObject;
|
||||
_x.relinquishFunction = 0;
|
||||
_x.relinquishFunction = relinquishRetainedMemory;
|
||||
}
|
||||
_x.descriptionFunction = describeObject;
|
||||
_x.hashFunction = hashShifted;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue