diff --git a/Source/NSConcreteHashTable.m b/Source/NSConcreteHashTable.m index 0d3a10872..39f5c75b4 100644 --- a/Source/NSConcreteHashTable.m +++ b/Source/NSConcreteHashTable.m @@ -77,7 +77,7 @@ @interface NSConcreteHashTable : NSHashTable #define GSI_MAP_TABLE_S instanceSize #define IS_WEAK(M) \ - M->cb.pf.options & (NSPointerFunctionsZeroingWeakMemory | NSPointerFunctionsWeakMemory) + memoryType(M->cb.pf.options, NSPointerFunctionsZeroingWeakMemory) || memoryType(M->cb.pf.options, NSPointerFunctionsWeakMemory) #define GSI_MAP_HASH(M, X)\ (M->legacy ? M->cb.old.hash(M, X.ptr) \ : pointerFunctionsHash(&M->cb.pf, X.ptr)) diff --git a/Source/NSConcretePointerFunctions.h b/Source/NSConcretePointerFunctions.h index c3a5f0d99..94cd365b1 100644 --- a/Source/NSConcretePointerFunctions.h +++ b/Source/NSConcretePointerFunctions.h @@ -78,7 +78,12 @@ typedef struct inline static BOOL memoryType(int options, int flag) { - return (options & 0xff) == flag; + return ((options & 0xff) == flag) ? YES : NO; +} + +inline static BOOL personalityType(int options, int flag) +{ + return ((options & 0xff00) == flag) ? YES : NO; } /* Declare the concrete pointer functions class as a wrapper around diff --git a/Source/NSConcretePointerFunctions.m b/Source/NSConcretePointerFunctions.m index b2c28d930..6304f9e55 100644 --- a/Source/NSConcretePointerFunctions.m +++ b/Source/NSConcretePointerFunctions.m @@ -191,19 +191,19 @@ - (id) initWithOptions: (NSPointerFunctionsOptions)options * should be used to relinquish contents of a container with these * options. */ - if (options & NSPointerFunctionsZeroingWeakMemory) + if (memoryType(options, NSPointerFunctionsZeroingWeakMemory)) { _x.relinquishFunction = 0; } - else if (options & NSPointerFunctionsOpaqueMemory) + else if (memoryType(options, NSPointerFunctionsOpaqueMemory)) { _x.relinquishFunction = 0; } - else if (options & NSPointerFunctionsMallocMemory) + else if (memoryType(options, NSPointerFunctionsMallocMemory)) { _x.relinquishFunction = relinquishMallocMemory; } - else if (options & NSPointerFunctionsMachVirtualMemory) + else if (memoryType(options, NSPointerFunctionsMachVirtualMemory)) { _x.relinquishFunction = relinquishMallocMemory; } @@ -214,16 +214,16 @@ - (id) initWithOptions: (NSPointerFunctionsOptions)options /* Now we look at the personality options to determine other functions. */ - if (options & NSPointerFunctionsOpaquePersonality) + if (personalityType(options, NSPointerFunctionsOpaquePersonality)) { _x.acquireFunction = acquireExistingMemory; _x.descriptionFunction = describePointer; _x.hashFunction = hashShifted; _x.isEqualFunction = equalDirect; } - else if (options & NSPointerFunctionsObjectPointerPersonality) + else if (personalityType(options, NSPointerFunctionsObjectPointerPersonality)) { - if (options & NSPointerFunctionsZeroingWeakMemory) + if (memoryType(options, NSPointerFunctionsZeroingWeakMemory)) { _x.acquireFunction = acquireExistingMemory; } @@ -235,21 +235,21 @@ - (id) initWithOptions: (NSPointerFunctionsOptions)options _x.hashFunction = hashShifted; _x.isEqualFunction = equalDirect; } - else if (options & NSPointerFunctionsCStringPersonality) + else if (personalityType(options, NSPointerFunctionsCStringPersonality)) { _x.acquireFunction = acquireMallocMemory; _x.descriptionFunction = describeString; _x.hashFunction = hashString; _x.isEqualFunction = equalString; } - else if (options & NSPointerFunctionsStructPersonality) + else if (personalityType(options, NSPointerFunctionsStructPersonality)) { _x.acquireFunction = acquireMallocMemory; _x.descriptionFunction = describePointer; _x.hashFunction = hashMemory; _x.isEqualFunction = equalMemory; } - else if (options & NSPointerFunctionsIntegerPersonality) + else if (personalityType(options, NSPointerFunctionsIntegerPersonality)) { _x.acquireFunction = acquireExistingMemory; _x.descriptionFunction = describeInteger; @@ -258,7 +258,7 @@ - (id) initWithOptions: (NSPointerFunctionsOptions)options } else /* objects */ { - if (options & NSPointerFunctionsZeroingWeakMemory) + if (memoryType(options, NSPointerFunctionsZeroingWeakMemory)) { _x.acquireFunction = acquireExistingMemory; } @@ -344,16 +344,18 @@ - (void) setUsesStrongWriteBarrier: (BOOL)flag ~(NSPointerFunctionsZeroingWeakMemory |NSPointerFunctionsOpaqueMemory |NSPointerFunctionsMallocMemory - |NSPointerFunctionsMachVirtualMemory); + |NSPointerFunctionsMachVirtualMemory + |NSPointerFunctionsWeakMemory); } - (void) setUsesWeakReadAndWriteBarriers: (BOOL)flag { - _x.options |= NSPointerFunctionsZeroingWeakMemory; _x.options &= ~(NSPointerFunctionsOpaqueMemory |NSPointerFunctionsMallocMemory - |NSPointerFunctionsMachVirtualMemory); + |NSPointerFunctionsMachVirtualMemory + |NSPointerFunctionsWeakMemory); + _x.options |= NSPointerFunctionsZeroingWeakMemory; } - (NSUInteger (*)(const void *item)) sizeFunction @@ -363,20 +365,12 @@ - (void) setUsesWeakReadAndWriteBarriers: (BOOL)flag - (BOOL) usesStrongWriteBarrier { - if ((_x.options & - (NSPointerFunctionsZeroingWeakMemory - |NSPointerFunctionsOpaqueMemory - |NSPointerFunctionsMallocMemory - |NSPointerFunctionsMachVirtualMemory)) == NSPointerFunctionsStrongMemory) - return YES; - return NO; + return memoryType(_x.options, NSPointerFunctionsStrongMemory); } - (BOOL) usesWeakReadAndWriteBarriers { - if (_x.options & NSPointerFunctionsZeroingWeakMemory) - return YES; - return NO; + return memoryType(_x.options, NSPointerFunctionsZeroingWeakMemory); } @end diff --git a/Source/NSPointerArray.m b/Source/NSPointerArray.m index e01da5228..a6ecbc252 100644 --- a/Source/NSPointerArray.m +++ b/Source/NSPointerArray.m @@ -534,7 +534,7 @@ - (void) setCount: (NSUInteger)count new_gf = new_cap / 2; if (_contents == 0) { - if (_pf.options & NSPointerFunctionsZeroingWeakMemory) + if (memoryType(_pf.options, NSPointerFunctionsZeroingWeakMemory)) { ptr = (void**)NSAllocateCollectable(size, 0); } @@ -545,7 +545,7 @@ - (void) setCount: (NSUInteger)count } else { - if (_pf.options & NSPointerFunctionsZeroingWeakMemory) + if (memoryType(_pf.options, NSPointerFunctionsZeroingWeakMemory)) { ptr = (void**)NSReallocateCollectable( _contents, size, 0);