diff --git a/ChangeLog b/ChangeLog index c2eb41fa2..4cbab7a8b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,10 @@ * Headers/Foundation/NSGarbageCollector.h: Improve documentation. * Source/NSAutoreleasePool.m: ([-drain[) Implemented. * Headers/Foundation/NSAutoreleasePool.m: ([-drain]) fix comment. + * Source/NSPointerFunctions.m: New class implementation + * Headers/Foundation/NSPointerFunctions.h: Fix some declarations + * Headers/Foundation/Foundation.h: Include NSPointerFunctions.h + * Source/GNUmakefile: Build and install NSPointerFunctions 2009-01-21 Richard Frith-Macdonald diff --git a/Headers/Foundation/Foundation.h b/Headers/Foundation/Foundation.h index 276b77738..9e487c823 100644 --- a/Headers/Foundation/Foundation.h +++ b/Headers/Foundation/Foundation.h @@ -85,6 +85,7 @@ #import #import #import +#import #import #import #import diff --git a/Headers/Foundation/NSPointerFunctions.h b/Headers/Foundation/NSPointerFunctions.h index 919255581..1608f9a7f 100644 --- a/Headers/Foundation/NSPointerFunctions.h +++ b/Headers/Foundation/NSPointerFunctions.h @@ -45,7 +45,7 @@ enum { NSPointerFunctionsStrongMemory = (0<<0), /** Garbage collected weak references */ - NSPointerFunctionsZeroingWeakgMemory = (1<<0), + NSPointerFunctionsZeroingWeakMemory = (1<<0), /** Non-GC memory */ NSPointerFunctionsOpaqueMemory = (2<<0), @@ -86,7 +86,7 @@ enum { NSPointerFunctionsIntegerPersonality = (5<<8), - /** Request the memory aquire function to allocate/copy items. + /** Request the memory acquire function to allocate/copy items. */ NSPointerFunctionsCopyIn = (1<<16) }; @@ -103,7 +103,7 @@ typedef NSUInteger NSPointerFunctionsOptions; - (id) initWithOptions: (NSPointerFunctionsOptions)options; - (void* (*)(const void *item, - NSUInteger (*size)(const void *item), BOOL shouldCopy)) aquireFunction; + NSUInteger (*size)(const void *item), BOOL shouldCopy)) acquireFunction; - (NSString (*)(const void *item)) descriptionFunction; @@ -127,8 +127,8 @@ typedef NSUInteger NSPointerFunctionsOptions; - (void) setIsEqualFunction: (BOOL (*)(const void *item1, const void *item2, NSUInteger (*size)(const void *item)))func; -- (void) setRelinquishFunction: (NSUInteger (*)(const void *item, - NSUInteger (*size)(const void *item)))func; +- (void) setRelinquishFunction: (void (*)(const void *item, + NSUInteger (*size)(const void *item))) func; - (void) setSizeFunction: (NSUInteger (*)(const void *item))func; @@ -140,7 +140,7 @@ typedef NSUInteger NSPointerFunctionsOptions; - (BOOL) usesStrongWriteBarrier; -- (BOOL) usesWeak ReadAndWriteBarriers; +- (BOOL) usesWeakReadAndWriteBarriers; @end diff --git a/Source/GNUmakefile b/Source/GNUmakefile index eb79ab7f8..2af7195c1 100644 --- a/Source/GNUmakefile +++ b/Source/GNUmakefile @@ -223,6 +223,7 @@ NSObject+NSComparisonMethods.m \ NSPage.m \ NSPathUtilities.m \ NSPipe.m \ +NSPointerFunctions.m \ NSPort.m \ NSPortCoder.m \ NSPortMessage.m \ @@ -360,6 +361,7 @@ NSNumberFormatter.h \ NSObjCRuntime.h \ NSObject.h \ NSPathUtilities.h \ +NSPointerFunctions.h \ NSPortCoder.h \ NSPort.h \ NSPortMessage.h \ diff --git a/Source/NSPointerFunctions.m b/Source/NSPointerFunctions.m new file mode 100644 index 000000000..5692a5c76 --- /dev/null +++ b/Source/NSPointerFunctions.m @@ -0,0 +1,175 @@ +/**Implementation for NSPointerFunctions for GNUStep + Copyright (C) 2009 Free Software Foundation, Inc. + + Written by: Richard Frith-Macdonald + Date: 2009 + + This file is part of the GNUstep Base Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02111 USA. + + */ + +#import "Foundation/NSPointerFunctions.h" + +typedef struct { + NSUInteger options; + + void* (*acquireFunction)(const void *item, + NSUInteger (*size)(const void *item), BOOL shouldCopy); + + NSString (*descriptionFunction)(const void *item); + + NSUInteger (*hashFunction)(const void *item, + NSUInteger (*size)(const void *item)); + + BOOL (*isEqualFunction)(const void *item1, const void *item2, + NSUInteger (*size)(const void *item)); + + void (*relinquishFunction)(const void *item, + NSUInteger (*size)(const void *item)); + + NSUInteger (*sizeFunction)(const void *item); + + BOOL usesStrongWriteBarrier; + + BOOL usesWeakReadAndWriteBarriers; +} _internal; + +#define _options ((_internal*)(self+1))->options +#define _acquireFunction ((_internal*)(self+1))->acquireFunction +#define _descriptionFunction ((_internal*)(self+1))->descriptionFunction +#define _hashFunction ((_internal*)(self+1))->hashFunction +#define _isEqualFunction ((_internal*)(self+1))->isEqualFunction +#define _relinquishFunction ((_internal*)(self+1))->relinquishFunction +#define _sizeFunction ((_internal*)(self+1))->sizeFunction +#define _usesStrongWriteBarrier ((_internal*)(self+1))->usesStrongWriteBarrier +#define _usesWeakReadAndWriteBarriers ((_internal*)(self+1))->usesWeakReadAndWriteBarriers + + +@implementation NSPointerFunctions + ++ (id) allocWithZone: (NSZone*)zone +{ + return (id) NSAllocateObject(self, sizeof(_internal), zone); +} + ++ (id) pointerFunctionsWithOptions: (NSPointerFunctionsOptions)options +{ + return AUTORELEASE([[self alloc] initWithOptions: options]); +} + +- (id) copyWithZone: (NSZone*)zone +{ + return NSCopyObject(self, sizeof(_internal), zone); +} + +- (id) initWithOptions: (NSPointerFunctionsOptions)options +{ + _options = options; + return self; +} + +- (void* (*)(const void *item, + NSUInteger (*size)(const void *item), BOOL shouldCopy)) acquireFunction +{ + return _acquireFunction; +} + +- (NSString (*)(const void *item)) descriptionFunction +{ + return _descriptionFunction; +} + +- (NSUInteger (*)(const void *item, + NSUInteger (*size)(const void *item))) hashFunction +{ + return _hashFunction; +} + +- (BOOL (*)(const void *item1, const void *item2, + NSUInteger (*size)(const void *item))) isEqualFunction +{ + return _isEqualFunction; +} + +- (void (*)(const void *item, + NSUInteger (*size)(const void *item))) relinquishFunction +{ + return _relinquishFunction; +} + +- (void) setAcquireFunction: (void* (*)(const void *item, + NSUInteger (*size)(const void *item), BOOL shouldCopy))func +{ + _acquireFunction = func; +} + +- (void) setDescriptionFunction: (NSString (*)(const void *item))func +{ + _descriptionFunction = func; +} + +- (void) setHashFunction: (NSUInteger (*)(const void *item, + NSUInteger (*size)(const void *item)))func +{ + _hashFunction = func; +} + +- (void) setIsEqualFunction: (BOOL (*)(const void *item1, const void *item2, + NSUInteger (*size)(const void *item)))func +{ + _isEqualFunction = func; +} + +- (void) setRelinquishFunction: (void (*)(const void *item, + NSUInteger (*size)(const void *item))) func +{ + _relinquishFunction = func; +} + +- (void) setSizeFunction: (NSUInteger (*)(const void *item))func +{ + _sizeFunction = func; +} + +- (void) setUsesStrongWriteBarrier: (BOOL)flag +{ + _usesStrongWriteBarrier = flag; +} + +- (void) setUsesWeakReadAndWriteBarriers: (BOOL)flag +{ + _usesWeakReadAndWriteBarriers = flag; +} + +- (NSUInteger (*)(const void *item)) sizeFunction +{ + return _sizeFunction; +} + +- (BOOL) usesStrongWriteBarrier +{ + return _usesStrongWriteBarrier; +} + +- (BOOL) usesWeakReadAndWriteBarriers +{ + return _usesStrongWriteBarrier; +} + +@end +