From ceba92a2653b8464a6e73bf7e545d11a91559eb8 Mon Sep 17 00:00:00 2001 From: theraven Date: Sun, 24 Jul 2011 13:09:22 +0000 Subject: [PATCH] Lots of little fixes to make -base compile with -Werror (now builds without warnings). Richard: I'm unsure about three of these, which were fixes in memset() calls in: - NSConcreteMapTable.m - NSConcreteHashTable.m - Additions/NSData+GNUstepBase.m Please can you check them? I think they are intended to zero the entire object (rather than the first word), but the lack of comments makes me unsure. Most changes were just tweaks to variable types. I've also removed some dead code from NSInvocation. This was small group of things that were marked for internal use only, but not actually referenced in the code anywhere. Other improvements: - NSArray / NSDictionary fixed up to use the 10.7 (ARC-friendly) prototypes. - getObjects:andKeys: implemented for NSDictionary (10.5 method) - NSPointerArray and NSHashTable now properly support weak objects. - Tests for weak objects in collections. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@33621 72102866-910b-0410-8b05-ffd578937521 --- Headers/Foundation/NSArray.h | 4 +- Headers/Foundation/NSDictionary.h | 10 ++-- Headers/Foundation/NSEnumerator.h | 2 +- Headers/Foundation/NSInvocation.h | 8 --- Headers/GNUstepBase/GSFileHandle.h | 1 + Headers/GNUstepBase/GSIMap.h | 27 +++++++++ Headers/GNUstepBase/preface.h.in | 8 +++ Source/Additions/GCDictionary.m | 6 +- Source/Additions/GSInsensitiveDictionary.m | 3 +- Source/Additions/GSLock.m | 4 +- Source/Additions/NSData+GNUstepBase.m | 2 +- Source/GSArray.m | 8 +-- Source/GSDictionary.m | 9 ++- Source/GSInvocation.h | 5 ++ Source/NSArray.m | 6 +- Source/NSAssertionHandler.m | 3 + Source/NSCharacterSet.m | 4 +- Source/NSConcreteHashTable.m | 15 ++++- Source/NSConcreteMapTable.m | 10 ++-- Source/NSConcretePointerFunctions.h | 30 ++++++---- Source/NSConnection.m | 2 +- Source/NSCountedSet.m | 4 +- Source/NSData.m | 12 ++-- Source/NSDate.m | 4 +- Source/NSDebug.m | 2 +- Source/NSDictionary.m | 24 +++++--- Source/NSDistantObject.m | 2 +- Source/NSHost.m | 2 +- Source/NSIndexPath.m | 2 +- Source/NSInvocation.m | 65 ---------------------- Source/NSKeyValueObserving.m | 2 +- Source/NSPointerArray.m | 10 ++-- Source/NSProcessInfo.m | 2 +- Source/NSPropertyList.m | 2 +- Source/NSTimeZone.m | 4 +- Source/NSValue.m | 2 +- Source/unix/NSStream.m | 12 ++-- Tests/base/NSHashTable/weak.m | 18 ++++++ Tests/base/NSPointerArray/weak.m | 15 +++++ 39 files changed, 196 insertions(+), 155 deletions(-) create mode 100644 Tests/base/NSHashTable/weak.m create mode 100644 Tests/base/NSPointerArray/weak.m diff --git a/Headers/Foundation/NSArray.h b/Headers/Foundation/NSArray.h index 96628d9de..42e6dcfce 100644 --- a/Headers/Foundation/NSArray.h +++ b/Headers/Foundation/NSArray.h @@ -55,8 +55,8 @@ extern "C" { - (NSArray*) arrayByAddingObjectsFromArray: (NSArray*)anotherArray; - (BOOL) containsObject: anObject; - (NSUInteger) count; // Primitive -- (void) getObjects: (id[])aBuffer; -- (void) getObjects: (id[])aBuffer range: (NSRange)aRange; +- (void) getObjects: (__unsafe_unretained id[])aBuffer; +- (void) getObjects: (__unsafe_unretained id[])aBuffer range: (NSRange)aRange; - (NSUInteger) indexOfObject: (id)anObject; - (NSUInteger) indexOfObject: (id)anObject inRange: (NSRange)aRange; - (NSUInteger) indexOfObjectIdenticalTo: (id)anObject; diff --git a/Headers/Foundation/NSDictionary.h b/Headers/Foundation/NSDictionary.h index 47ae5503f..02d3c8b76 100644 --- a/Headers/Foundation/NSDictionary.h +++ b/Headers/Foundation/NSDictionary.h @@ -44,8 +44,8 @@ extern "C" { + (id) dictionaryWithDictionary: (NSDictionary*)otherDictionary; + (id) dictionaryWithObject: (id)object forKey: (id)key; + (id) dictionaryWithObjects: (NSArray*)objects forKeys: (NSArray*)keys; -+ (id) dictionaryWithObjects: (id*)objects - forKeys: (id*)keys ++ (id) dictionaryWithObjects: (const id[])objects + forKeys: (const id[])keys count: (NSUInteger)count; + (id) dictionaryWithObjectsAndKeys: (id)firstObject, ...; @@ -68,8 +68,8 @@ extern "C" { - (id) initWithDictionary: (NSDictionary*)other copyItems: (BOOL)shouldCopy; - (id) initWithObjects: (NSArray*)objects forKeys: (NSArray*)keys; - (id) initWithObjectsAndKeys: (id)firstObject, ...; -- (id) initWithObjects: (id*)objects - forKeys: (id*)keys +- (id) initWithObjects: (const id[])objects + forKeys: (const id[])keys count: (NSUInteger)count; // Primitive - (BOOL) isEqualToDictionary: (NSDictionary*)other; @@ -78,6 +78,8 @@ extern "C" { - (NSEnumerator*) objectEnumerator; // Primitive - (id) objectForKey: (id)aKey; // Primitive - (NSArray*) objectsForKeys: (NSArray*)keys notFoundMarker: (id)marker; +- (void)getObjects: (__unsafe_unretained id[])objects + andKeys: (__unsafe_unretained id[])keys; - (BOOL) writeToFile: (NSString*)path atomically: (BOOL)useAuxiliaryFile; #if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST) diff --git a/Headers/Foundation/NSEnumerator.h b/Headers/Foundation/NSEnumerator.h index c9694f532..91a8cf4f1 100644 --- a/Headers/Foundation/NSEnumerator.h +++ b/Headers/Foundation/NSEnumerator.h @@ -44,7 +44,7 @@ typedef struct @protocol NSFastEnumeration - (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState *)state - objects: (id *)stackbuf + objects: (__unsafe_unretained id[])stackbuf count: (NSUInteger)len; @end diff --git a/Headers/Foundation/NSInvocation.h b/Headers/Foundation/NSInvocation.h index b68ddcc45..6a828db14 100644 --- a/Headers/Foundation/NSInvocation.h +++ b/Headers/Foundation/NSInvocation.h @@ -121,14 +121,6 @@ extern "C" { @end #endif -/* Do NOT use these methods ... internal use only ... not public API */ -@interface NSInvocation (MacroSetup) -+ (id) _newProxyForInvocation: (id)target; -+ (id) _newProxyForMessage: (id)target; -+ (NSInvocation*) _returnInvocationAndDestroyProxy: (id)proxy; -- (id) initWithMethodSignature: (NSMethodSignature*)aSignature; -@end - /** * Creates and returns an autoreleased invocation containing a * message to an instance of the class. The 'message' consists diff --git a/Headers/GNUstepBase/GSFileHandle.h b/Headers/GNUstepBase/GSFileHandle.h index 72730e845..1980759b1 100644 --- a/Headers/GNUstepBase/GSFileHandle.h +++ b/Headers/GNUstepBase/GSFileHandle.h @@ -36,6 +36,7 @@ #include #endif +struct sockaddr_in; /** * DO NOT USE ... this header is here only for the SSL file handle support diff --git a/Headers/GNUstepBase/GSIMap.h b/Headers/GNUstepBase/GSIMap.h index 86c27d1bc..bf9a2af15 100644 --- a/Headers/GNUstepBase/GSIMap.h +++ b/Headers/GNUstepBase/GSIMap.h @@ -481,6 +481,33 @@ GSIMapRemoveAndFreeNode(GSIMapTable map, uintptr_t bkt, GSIMapNode node) return next; } +static INLINE void +GSIMapRemoveWeak(GSIMapTable map) +{ + uintptr_t bucketCount = map->bucketCount; + GSIMapBucket bucket = map->buckets; + if (GSI_MAP_ZEROED(map)) + { + while (bucketCount-- > 0) + { + GSIMapNode node = bucket->firstNode; + + while (node != 0) + { + GSIMapNode next = node->nextInBucket; + if (GSI_MAP_NODE_IS_EMPTY(map, node)) + { + GSIMapRemoveNodeFromMap(map, bucket, node); + GSIMapFreeNode(map, node); + } + node = next; + } + bucket++; + } + return; + } +} + static INLINE void GSIMapRemangleBuckets(GSIMapTable map, GSIMapBucket old_buckets, uintptr_t old_bucketCount, diff --git a/Headers/GNUstepBase/preface.h.in b/Headers/GNUstepBase/preface.h.in index 75f1ece14..d3484d8c4 100644 --- a/Headers/GNUstepBase/preface.h.in +++ b/Headers/GNUstepBase/preface.h.in @@ -49,6 +49,9 @@ #ifndef __has_feature # define __has_feature(x) 0 #endif +#ifndef __has_builtin +# define __has_builtin(x) 0 +#endif #if defined(__WIN32__) #include @@ -268,5 +271,10 @@ # endif #endif +#if __has_builtin(__builtin_unreachable) +# define GS_UNREACHABLE() __builtin_unreachable() +#else +# define GS_UNREACHABLE() abort() +#endif #endif /* __preface_h_OBJECTS_INCLUDE */ diff --git a/Source/Additions/GCDictionary.m b/Source/Additions/GCDictionary.m index 0ca320a3e..092393c67 100644 --- a/Source/Additions/GCDictionary.m +++ b/Source/Additions/GCDictionary.m @@ -37,7 +37,7 @@ typedef struct { BOOL isGCObject; } GCInfo; -@interface _GCDictionaryKeyEnumerator : NSObject +@interface _GCDictionaryKeyEnumerator : NSEnumerator { @public GCDictionary *dict; @@ -260,8 +260,8 @@ static Class gcClass = 0; return self; } -- (id) initWithObjects: (id*)objects - forKeys: (id*)keys +- (id) initWithObjects: (const id[])objects + forKeys: (const id[])keys count: (NSUInteger)count { NSUInteger size = (count * 4) / 3; diff --git a/Source/Additions/GSInsensitiveDictionary.m b/Source/Additions/GSInsensitiveDictionary.m index 2ed92fa94..022523620 100644 --- a/Source/Additions/GSInsensitiveDictionary.m +++ b/Source/Additions/GSInsensitiveDictionary.m @@ -69,6 +69,7 @@ _GSInsensitiveDictionary *dictionary; GSIMapEnumerator_t enumerator; } +- (id) initWithDictionary: (NSDictionary*)d; @end @interface _GSInsensitiveDictionaryObjectEnumerator : _GSInsensitiveDictionaryKeyEnumerator @@ -169,7 +170,7 @@ static SEL objSel; } /* Designated initialiser */ -- (id) initWithObjects: (id*)objs forKeys: (id*)keys count: (NSUInteger)c +- (id) initWithObjects: (const id[])objs forKeys: (const id[])keys count: (NSUInteger)c { NSUInteger i; diff --git a/Source/Additions/GSLock.m b/Source/Additions/GSLock.m index da90421ad..e6034f725 100644 --- a/Source/Additions/GSLock.m +++ b/Source/Additions/GSLock.m @@ -93,7 +93,7 @@ if ([NSThread isMultiThreaded] == YES) { DESTROY(self); - self = [NSLock new]; + return (GSLazyLock*)[NSLock new]; } else if (self != nil) { @@ -246,7 +246,7 @@ if ([NSThread isMultiThreaded] == YES) { DESTROY(self); - self = [NSRecursiveLock new]; + return (GSLazyRecursiveLock*)[NSRecursiveLock new]; } else { diff --git a/Source/Additions/NSData+GNUstepBase.m b/Source/Additions/NSData+GNUstepBase.m index 903541b7a..a4a4b8739 100644 --- a/Source/Additions/NSData+GNUstepBase.m +++ b/Source/Additions/NSData+GNUstepBase.m @@ -331,7 +331,7 @@ static void MD5Final (unsigned char digest[16], struct MD5Context *ctx) MD5Transform (ctx->buf, (uint32_t *) ctx->in); littleEndian ((unsigned char *) ctx->buf, 4); memcpy (digest, ctx->buf, 16); - memset (ctx, 0, sizeof (ctx)); /* In case it's sensitive */ + memset (ctx, 0, sizeof (*ctx)); /* In case it's sensitive */ } /* The four core functions - F1 is optimized somewhat */ diff --git a/Source/GSArray.m b/Source/GSArray.m index 70f19473a..5f25a0cb4 100644 --- a/Source/GSArray.m +++ b/Source/GSArray.m @@ -353,7 +353,7 @@ static Class GSInlineArrayClass; } } -- (void) getObjects: (id[])aBuffer +- (void) getObjects: (__unsafe_unretained id[])aBuffer { NSUInteger i; @@ -363,7 +363,7 @@ static Class GSInlineArrayClass; } } -- (void) getObjects: (id[])aBuffer range: (NSRange)aRange +- (void) getObjects: (__unsafe_unretained id[])aBuffer range: (NSRange)aRange { NSUInteger i, j = 0, e = aRange.location + aRange.length; @@ -376,7 +376,7 @@ static Class GSInlineArrayClass; } - (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState*)state - objects: (id*)stackbuf + objects: (__unsafe_unretained id[])stackbuf count: (NSUInteger)len { /* For immutable arrays we can return the contents pointer directly. */ @@ -886,7 +886,7 @@ static Class GSInlineArrayClass; } - (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState*)state - objects: (id*)stackbuf + objects: (__unsafe_unretained id[])stackbuf count: (NSUInteger)len { NSInteger count; diff --git a/Source/GSDictionary.m b/Source/GSDictionary.m index b8d61740d..87ec82ab0 100644 --- a/Source/GSDictionary.m +++ b/Source/GSDictionary.m @@ -74,6 +74,7 @@ static GC_descr nodeDesc; // Type descriptor for map node. GSDictionary *dictionary; GSIMapEnumerator_t enumerator; } +- (id) initWithDictionary: (NSDictionary*)d; @end @interface GSDictionaryObjectEnumerator : GSDictionaryKeyEnumerator @@ -183,7 +184,9 @@ static SEL objSel; } /* Designated initialiser */ -- (id) initWithObjects: (id*)objs forKeys: (id*)keys count: (NSUInteger)c +- (id) initWithObjects: (const id[])objs + forKeys: (const id[])keys + count: (NSUInteger)c { NSUInteger i; @@ -354,7 +357,7 @@ static SEL objSel; } - (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState*)state - objects: (id*)stackbuf + objects: (__unsafe_unretained id[])stackbuf count: (NSUInteger)len { state->mutationsPtr = (unsigned long *)self; @@ -458,7 +461,7 @@ static SEL objSel; } - (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState*)state - objects: (id*)stackbuf + objects: (__unsafe_unretained id[])stackbuf count: (NSUInteger)len { state->mutationsPtr = (unsigned long *)&_version; diff --git a/Source/GSInvocation.h b/Source/GSInvocation.h index 40534864d..90bee043a 100644 --- a/Source/GSInvocation.h +++ b/Source/GSInvocation.h @@ -39,6 +39,11 @@ typedef struct { BOOL isReg; } NSArgumentInfo; +@interface NSInvocation (MacroSetup) +- (id) initWithMethodSignature: (NSMethodSignature*)aSignature; +@end + + @interface GSFFIInvocation : NSInvocation { @public diff --git a/Source/NSArray.m b/Source/NSArray.m index 4607d7caa..4c266ccbb 100644 --- a/Source/NSArray.m +++ b/Source/NSArray.m @@ -389,7 +389,7 @@ static SEL rlSel; } - (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState*)state - objects: (id*)stackbuf + objects: (__unsafe_unretained id[])stackbuf count: (NSUInteger)len { NSUInteger size = [self count]; @@ -479,7 +479,7 @@ static SEL rlSel; * Copies the objects from the receiver to aBuffer, which must be * an area of memory large enough to hold them. */ -- (void) getObjects: (id[])aBuffer +- (void) getObjects: (__unsafe_unretained id[])aBuffer { unsigned i, c = [self count]; IMP get = [self methodForSelector: oaiSel]; @@ -492,7 +492,7 @@ static SEL rlSel; * Copies the objects from the range aRange of the receiver to aBuffer, * which must be an area of memory large enough to hold them. */ -- (void) getObjects: (id[])aBuffer range: (NSRange)aRange +- (void) getObjects: (__unsafe_unretained id[])aBuffer range: (NSRange)aRange { unsigned i, j = 0, c = [self count], e = aRange.location + aRange.length; IMP get = [self methodForSelector: oaiSel]; diff --git a/Source/NSAssertionHandler.m b/Source/NSAssertionHandler.m index 898ea586a..55c513083 100644 --- a/Source/NSAssertionHandler.m +++ b/Source/NSAssertionHandler.m @@ -26,6 +26,7 @@ */ #import "common.h" +#import "GNUstepBase/preface.h" #import "Foundation/NSException.h" #import "Foundation/NSDictionary.h" #import "Foundation/NSThread.h" @@ -103,6 +104,7 @@ NSString *const NSAssertionHandlerKey = @"NSAssertionHandler"; [NSException raise: NSInternalInconsistencyException format: message arguments: ap]; va_end(ap); + GS_UNREACHABLE(); /* NOT REACHED */ } @@ -133,6 +135,7 @@ NSString *const NSAssertionHandlerKey = @"NSAssertionHandler"; format: message arguments: ap]; va_end(ap); /* NOT REACHED */ + GS_UNREACHABLE(); } @end diff --git a/Source/NSCharacterSet.m b/Source/NSCharacterSet.m index 5243170b8..5e1c5c992 100644 --- a/Source/NSCharacterSet.m +++ b/Source/NSCharacterSet.m @@ -76,7 +76,7 @@ } @end -@interface NSDataStatic : NSObject // Help the compiler +@interface NSDataStatic : NSData // Help the compiler @end /* Private class from NSIndexSet.m @@ -620,7 +620,7 @@ static Class concreteMutableClass = nil; - (id) initWithBitmap: (NSData*)bitmap number: (int)number { - if ((self = [(NSBitmapCharSet*)self initWithBitmap: bitmap]) != nil) + if ((self = (_GSStaticCharSet*)[(NSBitmapCharSet*)self initWithBitmap: bitmap]) != nil) { _index = number; } diff --git a/Source/NSConcreteHashTable.m b/Source/NSConcreteHashTable.m index f36a486f5..254488642 100644 --- a/Source/NSConcreteHashTable.m +++ b/Source/NSConcreteHashTable.m @@ -90,6 +90,18 @@ typedef GSIMapNode_t *GSIMapNode; (M->legacy ? 0 \ : ((M->cb.pf.options & NSPointerFunctionsZeroingWeakMemory) ? YES : NO)) +#define GSI_MAP_WRITE_KEY(M, addr, x) \ + if (M->legacy) \ + *(addr) = x;\ + else\ + pointerFunctionsAssign(&M->cb.pf, (void**)addr, (x).obj); +#define GSI_MAP_READ_KEY(M,addr) \ + (M->legacy ? *(addr) :\ + (typeof(*addr))pointerFunctionsRead(&M->cb.pf, (void**)addr)) +#define GSI_MAP_ZEROED(M)\ + (M->legacy ? 0 \ + : ((M->cb.pf.options & NSPointerFunctionsZeroingWeakMemory) ? YES : NO)) + #define GSI_MAP_ENUMERATOR NSHashEnumerator #if GS_WITH_GC @@ -353,7 +365,7 @@ NSEndHashTableEnumeration(NSHashEnumerator *enumerator) * in the 'node' field. */ [(id)enumerator->node release]; - memset(enumerator, '\0', sizeof(GSIMapEnumerator)); + memset(enumerator, '\0', sizeof(NSHashEnumerator)); } } @@ -914,6 +926,7 @@ const NSHashTableCallBacks NSPointerToStructHashCallBacks = - (NSUInteger) count { + GSIMapRemoveWeak(self); return (NSUInteger)nodeCount; } diff --git a/Source/NSConcreteMapTable.m b/Source/NSConcreteMapTable.m index 8fd05808b..035117602 100644 --- a/Source/NSConcreteMapTable.m +++ b/Source/NSConcreteMapTable.m @@ -116,7 +116,8 @@ typedef GSIMapNode_t *GSIMapNode; (typeof(*addr))pointerFunctionsRead(&M->cb.pf.v, (void**)addr)) #define GSI_MAP_ZEROED(M)\ (M->legacy ? 0 \ - : ((M->cb.pf.k.options & NSPointerFunctionsZeroingWeakMemory) ? YES : NO)) + : (((M->cb.pf.k.options | M->cb.pf.v.options) & NSPointerFunctionsZeroingWeakMemory) ?\ + YES : NO)) #define GSI_MAP_ENUMERATOR NSMapEnumerator @@ -518,7 +519,7 @@ NSEndMapTableEnumeration(NSMapEnumerator *enumerator) * 'bucket' field. */ [(id)enumerator->node release]; - memset(enumerator, '\0', sizeof(GSIMapEnumerator)); + memset(enumerator, '\0', sizeof(NSMapEnumerator)); } } @@ -1201,10 +1202,7 @@ const NSMapTableValueCallBacks NSOwnedPointerMapValueCallBacks = - (NSUInteger) count { - if (!legacy && (cb.pf.k.options | cb.pf.v.options) & NSPointerFunctionsZeroingWeakMemory) - { - GSIMapCleanMap(self); - } + GSIMapRemoveWeak(self); return (NSUInteger)nodeCount; } diff --git a/Source/NSConcretePointerFunctions.h b/Source/NSConcretePointerFunctions.h index 03b496e7d..4d7be30a7 100644 --- a/Source/NSConcretePointerFunctions.h +++ b/Source/NSConcretePointerFunctions.h @@ -94,17 +94,6 @@ typedef struct /* Wrapper functions to make use of the pointer functions. */ -/* Acquire the pointer value to store for the specified item. - */ -static inline void * -pointerFunctionsAcquire(PFInfo *PF, void **dst, void *src) -{ - if (PF->acquireFunction != 0) - src = (*PF->acquireFunction)(src, PF->sizeFunction, - PF->options & NSPointerFunctionsCopyIn ? YES : NO); - return src; -} - /** * Reads the pointer from the specified address, inserting a read barrier if * required. @@ -115,6 +104,8 @@ static inline void *pointerFunctionsRead(PFInfo *PF, void **addr) { return WEAK_READ((id*)addr); } + NSLog(@"Reading from %p", addr); + NSLog(@"Value: %p", *addr); return *addr; } @@ -137,6 +128,23 @@ static inline void pointerFunctionsAssign(PFInfo *PF, void **addr, void *value) } } +/* Acquire the pointer value to store for the specified item. + */ +static inline void * +pointerFunctionsAcquire(PFInfo *PF, void **dst, void *src) +{ + if (PF->acquireFunction != 0) + src = (*PF->acquireFunction)(src, PF->sizeFunction, + PF->options & NSPointerFunctionsCopyIn ? YES : NO); + // FIXME: This shouldn't be here. Acquire and assign are separate + // operations. Acquire is for copy-in operations (i.e. retain / copy), + // assign is for move operations of already-owned pointers. Combining them + // like this is Just Plain Wrong™ + pointerFunctionsAssign(PF, dst, src); + return src; +} + + /** * Moves a pointer from location to another. */ diff --git a/Source/NSConnection.m b/Source/NSConnection.m index 03f2fe597..a7bd76123 100644 --- a/Source/NSConnection.m +++ b/Source/NSConnection.m @@ -365,7 +365,7 @@ static BOOL cacheCoders = NO; static int debug_connection = 0; static NSHashTable *connection_table; -static NSLock *connection_table_gate = nil; +static GSLazyRecursiveLock *connection_table_gate = nil; /* * Locate an existing connection with the specified send and receive ports. diff --git a/Source/NSCountedSet.m b/Source/NSCountedSet.m index 6b451f1bd..5e7b3a60f 100644 --- a/Source/NSCountedSet.m +++ b/Source/NSCountedSet.m @@ -43,7 +43,7 @@ /* * Class variables for uniquing objects; */ -static NSRecursiveLock *uniqueLock = nil; +static GSLazyRecursiveLock *uniqueLock = nil; static NSCountedSet *uniqueSet = nil; static IMP uniqueImp = 0; static IMP lockImp = 0; @@ -73,7 +73,7 @@ static Class NSCountedSet_concrete_class; { NSCountedSet_abstract_class = self; NSCountedSet_concrete_class = [GSCountedSet class]; - uniqueLock = [GSLazyLock new]; + uniqueLock = [GSLazyRecursiveLock new]; lockImp = [uniqueLock methodForSelector: @selector(lock)]; unlockImp = [uniqueLock methodForSelector: @selector(unlock)]; } diff --git a/Source/NSData.m b/Source/NSData.m index 1c242fb1d..85c6bc074 100644 --- a/Source/NSData.m +++ b/Source/NSData.m @@ -2389,7 +2389,7 @@ failure: + (id) dataWithShmID: (int)anID length: (NSUInteger)length { #ifdef HAVE_SHMCTL - NSDataShared *d; + NSMutableDataShared *d; d = [NSMutableDataShared allocWithZone: NSDefaultMallocZone()]; d = [d initWithShmID: anID length: length]; @@ -2502,7 +2502,7 @@ failure: + (id) allocWithZone: (NSZone*)z { - return (NSData*)NSAllocateObject(self, 0, z); + return NSAllocateObject(self, 0, z); } /* Creation and Destruction of objects. */ @@ -2979,7 +2979,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos) @implementation NSDataMappedFile + (id) allocWithZone: (NSZone*)z { - return (NSData*)NSAllocateObject([NSDataMappedFile class], 0, z); + return NSAllocateObject([NSDataMappedFile class], 0, z); } - (void) dealloc @@ -3070,7 +3070,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos) @implementation NSDataShared + (id) allocWithZone: (NSZone*)z { - return (NSData*)NSAllocateObject([NSDataShared class], 0, z); + return NSAllocateObject([NSDataShared class], 0, z); } - (void) dealloc @@ -3184,7 +3184,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos) + (id) allocWithZone: (NSZone*)z { - return (NSData*)NSAllocateObject(mutableDataMalloc, 0, z); + return NSAllocateObject(mutableDataMalloc, 0, z); } - (Class) classForCoder @@ -3797,7 +3797,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos) @implementation NSMutableDataShared + (id) allocWithZone: (NSZone*)z { - return (NSData*)NSAllocateObject([NSMutableDataShared class], 0, z); + return NSAllocateObject([NSMutableDataShared class], 0, z); } - (void) dealloc diff --git a/Source/NSDate.m b/Source/NSDate.m index e013e68b7..4ac5cbb9b 100644 --- a/Source/NSDate.m +++ b/Source/NSDate.m @@ -78,8 +78,8 @@ static Class calendarClass = nil; @interface GSDateFuture : GSDateSingle @end -static NSDate *_distantPast = nil; -static NSDate *_distantFuture = nil; +static id _distantPast = nil; +static id _distantFuture = nil; static NSString* diff --git a/Source/NSDebug.m b/Source/NSDebug.m index 008bb4f2b..899b769d1 100644 --- a/Source/NSDebug.m +++ b/Source/NSDebug.m @@ -66,7 +66,7 @@ static table_entry* the_table = 0; static BOOL debug_allocation = NO; -static NSLock *uniqueLock = nil; +static GSLazyRecursiveLock *uniqueLock = nil; static const char* _GSDebugAllocationList(BOOL difference); static const char* _GSDebugAllocationListAll(void); diff --git a/Source/NSDictionary.m b/Source/NSDictionary.m index 760685d1e..f3848a8d7 100644 --- a/Source/NSDictionary.m +++ b/Source/NSDictionary.m @@ -41,6 +41,7 @@ #import "Foundation/NSKeyedArchiver.h" #import "GNUstepBase/NSObject+GNUstepBase.h" #import "GSPrivate.h" +#import "GSFastEnumeration.h" static BOOL GSMacOSXCompatiblePropertyLists(void) { @@ -165,8 +166,8 @@ static SEL appSel; * and needs to be re-implemented in subclasses in order to have all * other initialisers work. */ -- (id) initWithObjects: (id*)objects - forKeys: (id*)keys +- (id) initWithObjects: (const id[])objects + forKeys: (const id[])keys count: (NSUInteger)count { self = [self init]; @@ -396,8 +397,8 @@ static SEL appSel; * The n th element of the objects array is associated with the n th * element of the keys array. */ -+ (id) dictionaryWithObjects: (id*)objects - forKeys: (id*)keys ++ (id) dictionaryWithObjects: (const id[])objects + forKeys: (const id[])keys count: (NSUInteger)count { return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()] @@ -814,6 +815,15 @@ static SEL appSel; return AUTORELEASE(result); } } +- (void)getObjects: (__unsafe_unretained id[])objects + andKeys: (__unsafe_unretained id[])keys +{ + int i=0; + FOR_IN(id, key, self) + keys[i] = key; + objects[i] = [self objectForKey: key]; + END_FOR_IN(self) +} /** * Returns an array containing all the dictionary's keys that are @@ -1103,7 +1113,7 @@ compareIt(id o1, id o2, void* context) return o; } - (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState*)state - objects: (id*)stackbuf + objects: (__unsafe_unretained id[])stackbuf count: (NSUInteger)len { [self subclassResponsibility: _cmd]; @@ -1231,8 +1241,8 @@ compareIt(id o1, id o2, void* context) * The n th element of the objects array is associated with the n th * element of the keys array. */ -- (id) initWithObjects: (id*)objects - forKeys: (id*)keys +- (id) initWithObjects: (const id[])objects + forKeys: (const id[])keys count: (NSUInteger)count { self = [self initWithCapacity: count]; diff --git a/Source/NSDistantObject.m b/Source/NSDistantObject.m index b48ba5fe7..112e70457 100644 --- a/Source/NSDistantObject.m +++ b/Source/NSDistantObject.m @@ -407,7 +407,7 @@ enum proxyLocation + (id) allocWithZone: (NSZone*)z { - return placeHolder; + return (NSDistantObject*)placeHolder; } /** diff --git a/Source/NSHost.m b/Source/NSHost.m index 7cd54543a..80d0922a5 100644 --- a/Source/NSHost.m +++ b/Source/NSHost.m @@ -56,7 +56,7 @@ static NSString *localHostName = @"GNUstep local host"; static Class hostClass; -static NSLock *_hostCacheLock = nil; +static NSRecursiveLock *_hostCacheLock = nil; static BOOL _hostCacheEnabled = YES; static NSMutableDictionary *_hostCache = nil; diff --git a/Source/NSIndexPath.m b/Source/NSIndexPath.m index ebb1a9161..aa22124bc 100644 --- a/Source/NSIndexPath.m +++ b/Source/NSIndexPath.m @@ -34,7 +34,7 @@ #import "Foundation/NSLock.h" #import "GNUstepBase/GSLock.h" -static NSLock *lock = nil; +static GSLazyRecursiveLock *lock = nil; static NSHashTable *shared = 0; static Class myClass = 0; static NSIndexPath *empty = nil; diff --git a/Source/NSInvocation.m b/Source/NSInvocation.m index 7449dd61c..15bd51ddb 100644 --- a/Source/NSInvocation.m +++ b/Source/NSInvocation.m @@ -153,20 +153,6 @@ static Class NSInvocation_abstract_class; static Class NSInvocation_concrete_class; -@interface GSInvocationProxy -{ -@public - Class isa; - id target; - NSInvocation *invocation; -} -+ (id) _newWithTarget: (id)t; -- (NSInvocation*) _invocation; -- (void) forwardInvocation: (NSInvocation*)anInvocation; -- (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector; -@end -@interface GSMessageProxy : GSInvocationProxy -@end @@ -788,26 +774,6 @@ _arg_addr(NSInvocation *inv, int index) return nil; } -/** - * Internal use.
- * Provides a return frame that the ObjectiveC runtime can use to - * return the result of an invocation to a calling function. - */ - -+ (id) _newProxyForInvocation: (id)target -{ - return [GSInvocationProxy _newWithTarget: target]; -} -+ (id) _newProxyForMessage: (id)target -{ - return [GSMessageProxy _newWithTarget: target]; -} -+ (NSInvocation*) _returnInvocationAndDestroyProxy: (id)proxy -{ - NSInvocation *inv = [proxy _invocation]; - NSDeallocateObject(proxy); - return inv; -} @end @implementation NSInvocation (BackwardCompatibility) @@ -849,34 +815,3 @@ _arg_addr(NSInvocation *inv, int index) @end #endif - -@implementation GSInvocationProxy -+ (id) _newWithTarget: (id)t -{ - GSInvocationProxy *o; - o = (GSInvocationProxy*) NSAllocateObject(self, 0, NSDefaultMallocZone()); - o->target = RETAIN(t); - return o; -} -- (NSInvocation*) _invocation -{ - return invocation; -} -- (void) forwardInvocation: (NSInvocation*)anInvocation -{ - invocation = anInvocation; -} -- (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector -{ - return [target methodSignatureForSelector: aSelector]; -} -@end - -@implementation GSMessageProxy -- (NSInvocation*) _invocation -{ - [invocation setTarget: target]; - return invocation; -} -@end - diff --git a/Source/NSKeyValueObserving.m b/Source/NSKeyValueObserving.m index c060e2b24..dd2406ae7 100644 --- a/Source/NSKeyValueObserving.m +++ b/Source/NSKeyValueObserving.m @@ -174,7 +174,7 @@ setup() @interface GSKVOInfo : NSObject { NSObject *instance; // Not retained. - NSLock *iLock; + GSLazyRecursiveLock *iLock; NSMapTable *paths; } - (GSKVOPathInfo *) lockReturningPathInfoForKey: (NSString *)key; diff --git a/Source/NSPointerArray.m b/Source/NSPointerArray.m index 9358ee153..9d9dd38b3 100644 --- a/Source/NSPointerArray.m +++ b/Source/NSPointerArray.m @@ -240,7 +240,7 @@ static Class concreteClass = Nil; for (i = 0; i < _count; i++) { - if (pointerFunctionsRead(&_pf, _contents[i]) != 0) + if (pointerFunctionsRead(&_pf, &_contents[i]) != 0) { c++; } @@ -256,7 +256,7 @@ static Class concreteClass = Nil; for (i = 0; i < _count; i++) { - id obj = pointerFunctionsRead(&_pf, _contents[i]); + id obj = pointerFunctionsRead(&_pf, &_contents[i]); if (obj != 0) { [a addObject: obj]; @@ -309,8 +309,9 @@ static Class concreteClass = Nil; #endif for (i = 0; i < _count; i++) { + NSLog(@"Copying %d, %p", i, _contents[i]); pointerFunctionsAcquire(&_pf, &c->_contents[i], - pointerFunctionsRead(&_pf, _contents[i])); + pointerFunctionsRead(&_pf, &_contents[i])); } return c; } @@ -432,6 +433,7 @@ static Class concreteClass = Nil; - (void) insertPointer: (void*)pointer atIndex: (NSUInteger)index { NSUInteger i; + if (index > _count) { @@ -467,7 +469,7 @@ static Class concreteClass = Nil; while (count-- > 0) { if (pointerFunctionsEqual(&_pf, - pointerFunctionsRead(&_pf, _contents[count]), + pointerFunctionsRead(&_pf, &_contents[count]), [other pointerAtIndex: count]) == NO) return NO; } diff --git a/Source/NSProcessInfo.m b/Source/NSProcessInfo.m index bdf882ac2..6e91adcd1 100644 --- a/Source/NSProcessInfo.m +++ b/Source/NSProcessInfo.m @@ -211,7 +211,7 @@ static NSString *_gnu_processName = nil; static NSArray *_gnu_arguments = nil; // Dictionary of environment vars and their values -static NSMutableDictionary *_gnu_environment = nil; +static NSDictionary *_gnu_environment = nil; // The operating system we are using. static unsigned int _operatingSystem = 0; diff --git a/Source/NSPropertyList.m b/Source/NSPropertyList.m index 5e873a783..f77706d06 100644 --- a/Source/NSPropertyList.m +++ b/Source/NSPropertyList.m @@ -86,7 +86,7 @@ extern BOOL GSScanDouble(unichar*, unsigned, double*); NSXMLParser *theParser; NSMutableString *value; NSMutableArray *stack; - NSString *key; + id key; BOOL inArray; BOOL inDictionary; BOOL inString; diff --git a/Source/NSTimeZone.m b/Source/NSTimeZone.m index 07babd42e..962b26656 100644 --- a/Source/NSTimeZone.m +++ b/Source/NSTimeZone.m @@ -408,7 +408,7 @@ static NSString *_time_zone_path(NSString *subpath, NSString *type) { zone = RETAIN(localTimeZone); DESTROY(self); - return zone; + return (GSPlaceholderTimeZone*)zone; } /* @@ -557,7 +557,7 @@ static NSString *_time_zone_path(NSString *subpath, NSString *type) } } DESTROY(self); - return zone; + return (GSPlaceholderTimeZone*)zone; } - (void) release diff --git a/Source/NSValue.m b/Source/NSValue.m index ea1752878..18f1e9dd1 100644 --- a/Source/NSValue.m +++ b/Source/NSValue.m @@ -62,7 +62,7 @@ @interface GSSizeValue : NSObject // Help the compiler @end @class NSDataStatic; // Needed for decoding. -@interface NSDataStatic : NSObject // Help the compiler +@interface NSDataStatic : NSData // Help the compiler @end diff --git a/Source/unix/NSStream.m b/Source/unix/NSStream.m index b2e85c80a..f6c3c1a1f 100644 --- a/Source/unix/NSStream.m +++ b/Source/unix/NSStream.m @@ -354,8 +354,8 @@ outputStream: (NSOutputStream **)outputStream { NSString *address = host ? (id)[host address] : (id)@"127.0.0.1"; - GSSocketStream *ins = nil; - GSSocketStream *outs = nil; + id ins = nil; + id outs = nil; // try ipv4 first ins = AUTORELEASE([[GSInetInputStream alloc] @@ -388,8 +388,8 @@ inputStream: (NSInputStream **)inputStream outputStream: (NSOutputStream **)outputStream { - GSSocketStream *ins = nil; - GSSocketStream *outs = nil; + id ins = nil; + id outs = nil; ins = AUTORELEASE([[GSLocalInputStream alloc] initToAddr: path]); outs = AUTORELEASE([[GSLocalOutputStream alloc] initToAddr: path]); @@ -409,8 +409,8 @@ + (void) pipeWithInputStream: (NSInputStream **)inputStream outputStream: (NSOutputStream **)outputStream { - GSSocketStream *ins = nil; - GSSocketStream *outs = nil; + id ins = nil; + id outs = nil; int fds[2]; int pipeReturn; diff --git a/Tests/base/NSHashTable/weak.m b/Tests/base/NSHashTable/weak.m new file mode 100644 index 000000000..6911bf64f --- /dev/null +++ b/Tests/base/NSHashTable/weak.m @@ -0,0 +1,18 @@ +#import "ObjectTesting.h" +#import +#import + +int main() +{ + [NSAutoreleasePool new]; + NSHashTable *ht = [NSHashTable hashTableWithWeakObjects]; + id obj = [NSObject new]; + [ht addObject: obj]; + PASS([ht containsObject: obj], "Added object to weak hash table"); + PASS(1 == [ht count], "Weak hash table contains one object"); + PASS([ht containsObject: obj], "Added object to weak hash table"); + [obj release]; + PASS(0 == [ht count], "Weak hash table contains no objects"); + PASS(0 == [[ht allObjects] count], "Weak hash table contains no objects"); + return 0; +} diff --git a/Tests/base/NSPointerArray/weak.m b/Tests/base/NSPointerArray/weak.m new file mode 100644 index 000000000..e52eb28ef --- /dev/null +++ b/Tests/base/NSPointerArray/weak.m @@ -0,0 +1,15 @@ +#import "ObjectTesting.h" +#import + +int main(void) +{ + [NSAutoreleasePool new]; + NSPointerArray *pa = [NSPointerArray pointerArrayWithWeakObjects]; + id obj = [NSObject new]; + [pa addPointer: obj]; + PASS([pa count] == 1, "Added object to weak array"); + [obj release]; + [pa compact]; + PASS([pa count] == 0, "Removed object to weak array"); + return 0; +}