More pointer function tweaks

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@27862 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2009-02-14 16:38:59 +00:00
parent c6257091ce
commit b96f176cbc
5 changed files with 111 additions and 18 deletions

View file

@ -1,3 +1,8 @@
2009-02-14 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSPointerFunctions.m: Add some more functions to be set by
options.
2009-02-12 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSPortCoder.m: Use scanned memory to hold array

View file

@ -55,3 +55,39 @@
@end
/* Macros to make use of the pointer functions.
*/
/* Acquire the pointer value to store for the specified item.
*/
#define GSPFAcquire(PF,Item) \
(*(PF)->_acquireFunction)(Item, (PF)->_sizeFunction, (PF)->shouldCopyIn)
/* Generate an NSString description of the item
*/
#define GSPFDescribe(PF,Item) (*(PF)->_acquireFunction)(Item)
/* Generate the hash of the item
*/
#define GSPFHash(PF,Item) (*(PF)->_hashFunction)(Item, (PF)->_sizeFunction)
/* Compare two items for equality
*/
#define GSPFIsEqual(PF,Item1, Item2) \
(*(PF)->_isEqualFunction)(Item1, Item2, (PF)->_sizeFunction)
/* Relinquish the specified item and set it to zero.
*/
#define GSPFRelinquish(PF,Item) ({ \
if ((PF)->_relinquishFunction != 0) \
(*(PF)->_relinquishFunction)(Item, (PF)->_sizeFunction); \
if ((PF)->usesWeakReadAndWriteBarriers) \
GSAssignZeroingWeakPointer((void**)&Item, (void*)0); \
else \
Item = 0; \
})

View file

@ -23,6 +23,7 @@
*/
#import "Foundation/NSString.h"
#import "NSConcretePointerFunctions.h"
static void*
@ -58,6 +59,61 @@ acquireExistingMemory(const void *item,
return (void*)item;
}
static NSString*
describeString(const void *item)
{
return AUTORELEASE([[NSString alloc] initWithUTF8String: item]);
}
static NSString*
describeInteger(const void *item)
{
return [NSString stringWithFormat: @"%ld", (long)(intptr_t)item];
}
static NSString*
describeObject(const void *item)
{
return [(NSObject*)item description];
}
static NSString*
describePointer(const void *item)
{
return [NSString stringWithFormat: @"%p", item];
}
static BOOL
equalDirect(const void *item1, const void *item2,
NSUInteger (*size)(const void *item))
{
return (item1 == item2) ? YES : NO;
}
static BOOL
equalObject(const void *item1, const void *item2,
NSUInteger (*size)(const void *item))
{
return [(NSObject*)item1 isEqual: (NSObject*)item2];
}
static BOOL
equalMemory(const void *item1, const void *item2,
NSUInteger (*size)(const void *item))
{
NSUInteger s1 = (*size)(item1);
NSUInteger s2 = (*size)(item2);
return (s1 == s2 && memcmp(item1, item2, s1) == 0) ? YES : NO;
}
static BOOL
equalString(const void *item1, const void *item2,
NSUInteger (*size)(const void *item))
{
return (strcmp((const char*)item1, (const char*)item2) == 0) ? YES : NO;
}
static NSUInteger
hashDirect(const void *item, NSUInteger (*size)(const void *item))
{
@ -117,15 +173,6 @@ relinquishRetainedMemory(const void *item,
#endif
}
static void
relinquishZeroingWeakMemory(const void *item,
NSUInteger (*size)(const void *item))
{
#if GS_WITH_GC
GSAssignZeroingWeakPointer((void**)&item, 0);
#endif
}
@implementation NSConcretePointerFunctions
+ (id) allocWithZone: (NSZone*)zone
@ -146,10 +193,10 @@ relinquishZeroingWeakMemory(const void *item,
* should be used to relinquish contents of a container with these
* options.
*/
_usesWeakReadAndWriteBarriers = YES;
if (options & NSPointerFunctionsZeroingWeakMemory)
{
_relinquishFunction = relinquishZeroingWeakMemory;
_relinquishFunction = 0;
_usesWeakReadAndWriteBarriers = YES;
}
else if (options & NSPointerFunctionsOpaqueMemory)
{
@ -170,7 +217,6 @@ relinquishZeroingWeakMemory(const void *item,
* containers to allocate scanned memory.
*/
_usesStrongWriteBarrier = YES;
_usesWeakReadAndWriteBarriers = NO;
_relinquishFunction = relinquishRetainedMemory;
}
@ -184,32 +230,44 @@ relinquishZeroingWeakMemory(const void *item,
if (options & NSPointerFunctionsOpaquePersonality)
{
_acquireFunction = acquireExistingMemory;
_descriptionFunction = describePointer;
_hashFunction = hashShifted;
_isEqualFunction = equalDirect;
}
else if (options & NSPointerFunctionsObjectPointerPersonality)
{
_acquireFunction = acquireRetainedObject;
_descriptionFunction = describeObject;
_hashFunction = hashShifted;
_isEqualFunction = equalDirect;
}
else if (options & NSPointerFunctionsCStringPersonality)
{
_acquireFunction = acquireMallocMemory;
_descriptionFunction = describeString;
_hashFunction = hashString;
_isEqualFunction = equalString;
}
else if (options & NSPointerFunctionsStructPersonality)
{
_acquireFunction = acquireMallocMemory;
_descriptionFunction = describePointer;
_hashFunction = hashMemory;
_isEqualFunction = equalMemory;
}
else if (options & NSPointerFunctionsIntegerPersonality)
{
_acquireFunction = acquireExistingMemory;
_descriptionFunction = describeInteger;
_hashFunction = hashDirect;
_isEqualFunction = equalDirect;
}
else /* objects */
{
_acquireFunction = acquireRetainedObject;
_descriptionFunction = describeObject;
_hashFunction = hashObject;
_isEqualFunction = equalObject;
}
return self;

View file

@ -30,7 +30,6 @@
#include "Foundation/NSZone.h"
#define GSI_ARRAY_TYPE NSRange
#define GSI_ARRAY_TYPES GSI_ARRAY_EXTRA
#define GSI_ARRAY_NO_RELEASE 1
#define GSI_ARRAY_NO_RETAIN 1

View file

@ -47,11 +47,6 @@
// For pow()
#include <math.h>
#define NIMP [NSException raise: NSGenericException \
format: @"%s(%s) has not implemented %s",\
GSClassNameFromObject(self), GSObjCIsInstance(self) ? "instance" : "class",\
GSNameFromSelector(_cmd)]
@interface GSPredicateScanner : NSScanner
{
NSEnumerator *_args; // Not retained.