mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 08:41:03 +00:00
Add methods from 10.8 for using zeroing weak references in collections.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@35877 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0fd06dc66f
commit
38c34ba6ea
8 changed files with 110 additions and 10 deletions
|
@ -40,13 +40,8 @@
|
|||
# define STRONG_ACQUIRE(x) x
|
||||
#elif defined(OBJC_CAP_ARC)
|
||||
# include <objc/objc-arc.h>
|
||||
/*
|
||||
* OS X 10.7 uses weak to mean unsafe unretained, which is stupid and wrong,
|
||||
* but we should probably do the same thing for now. Uncomment this when Apple
|
||||
* fixes their implementation.
|
||||
# define WEAK_READ(x) objc_loadWeak((id*)x)
|
||||
# define WEAK_WRITE(addr, x) objc_storeWeak((id*)addr, (id)x)
|
||||
*/
|
||||
# define ARC_WEAK_READ(x) objc_loadWeak((id*)x)
|
||||
# define ARC_WEAK_WRITE(addr, x) objc_storeWeak((id*)addr, (id)x)
|
||||
# define WEAK_READ(x) (*x)
|
||||
# define WEAK_WRITE(addr, x) (*(addr) = x)
|
||||
# define STRONG_WRITE(addr, x) objc_storeStrong((id*)addr, (id)x)
|
||||
|
@ -61,6 +56,12 @@
|
|||
# define STRONG_WRITE(addr, x) ASSIGN(*((id*)addr), ((id)x))
|
||||
# define STRONG_ACQUIRE(x) RETAIN(((id)x))
|
||||
#endif
|
||||
#ifndef ARC_WEAK_WRITE
|
||||
# define ARC_WEAK_WRITE(addr, x) WEAK_WRITE(addr, x)
|
||||
#endif
|
||||
#ifndef ARC_WEAK_READ
|
||||
# define ARC_WEAK_READ(x) WEAK_READ(x)
|
||||
#endif
|
||||
|
||||
|
||||
/* Declare a structure type to copy pointer functions information
|
||||
|
@ -107,7 +108,11 @@ typedef struct
|
|||
*/
|
||||
static inline void *pointerFunctionsRead(PFInfo *PF, void **addr)
|
||||
{
|
||||
if (PF->options & NSPointerFunctionsZeroingWeakMemory)
|
||||
if (PF->options & NSPointerFunctionsWeakMemory)
|
||||
{
|
||||
return ARC_WEAK_READ((id*)addr);
|
||||
}
|
||||
else if (PF->options & NSPointerFunctionsZeroingWeakMemory)
|
||||
{
|
||||
return WEAK_READ((id*)addr);
|
||||
}
|
||||
|
@ -119,6 +124,10 @@ static inline void *pointerFunctionsRead(PFInfo *PF, void **addr)
|
|||
*/
|
||||
static inline void pointerFunctionsAssign(PFInfo *PF, void **addr, void *value)
|
||||
{
|
||||
if (PF->options & NSPointerFunctionsWeakMemory)
|
||||
{
|
||||
ARC_WEAK_WRITE(addr, value);
|
||||
}
|
||||
if (PF->options & NSPointerFunctionsZeroingWeakMemory)
|
||||
{
|
||||
WEAK_WRITE(addr, value);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue