Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to address issue of treating pointer function values as bitfield #314

Merged
merged 3 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 6 additions & 1 deletion Source/NSConcretePointerFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
Loading