Skip to content

Commit

Permalink
Try to address issue of treating pointer function values as bitmap.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredkiefer committed Aug 18, 2023
1 parent c1833e1 commit b0263ae
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Source/NSConcreteHashTable.m
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 5 additions & 0 deletions Source/NSConcretePointerFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ inline static BOOL memoryType(int options, int flag)
return (options & 0xff) == flag;
}

inline static BOOL personalityType(int options, int flag)
{
return (options & 0xff00) == flag;
}

/* Declare the concrete pointer functions class as a wrapper around
* an instance of the PFInfo structure.
*/
Expand Down
42 changes: 18 additions & 24 deletions Source/NSConcretePointerFunctions.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -258,7 +258,7 @@ - (id) initWithOptions: (NSPointerFunctionsOptions)options
}
else /* objects */
{
if (options & NSPointerFunctionsZeroingWeakMemory)
if (memoryType(options, NSPointerFunctionsZeroingWeakMemory))
{
_x.acquireFunction = acquireExistingMemory;
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Source/NSPointerArray.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -545,7 +545,7 @@ - (void) setCount: (NSUInteger)count
}
else
{
if (_pf.options & NSPointerFunctionsZeroingWeakMemory)
if (memoryType(_pf.options, NSPointerFunctionsZeroingWeakMemory))
{
ptr = (void**)NSReallocateCollectable(
_contents, size, 0);
Expand Down

0 comments on commit b0263ae

Please sign in to comment.