Modify the interfaces of all collection classes to be compatible with the

new lightweight generics implemenation. (Newer MacOS X/iOS code assuming 
the presence of the generics annotations can otherwise not be compiled with
GNUstep). This should be well-behaved under clang and gcc both. 

Fix NSCache which was copying the cache keys when it really shouldn't
have. Added a few test cases for eviction behaviour.

Few smaller tweaks to avoid compiler warnings.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@39406 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Niels Grewe 2016-02-22 21:04:18 +00:00
parent 4851131f49
commit 28c824a78a
14 changed files with 541 additions and 273 deletions

View file

@ -3,24 +3,24 @@
Written by: David Chisnall <csdavec@swan.ac.uk>
Created: 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 "common.h"
@ -28,7 +28,7 @@
#import "Foundation/NSArray.h"
#import "Foundation/NSCache.h"
#import "Foundation/NSDictionary.h"
#import "Foundation/NSMapTable.h"
#import "Foundation/NSEnumerator.h"
/**
@ -60,7 +60,7 @@
{
return nil;
}
_objects = [NSMutableDictionary new];
ASSIGN(_objects,[NSMapTable strongToStrongObjectsMapTable]);
_accesses = [NSMutableArray new];
return self;
}

View file

@ -103,15 +103,15 @@ skip_argspec(const char *ptr)
*/
#define GSI_MAP_KTYPES GSUNION_PTR | GSUNION_OBJ | GSUNION_NSINT
#define GSI_MAP_VTYPES GSUNION_PTR | GSUNION_OBJ
#define GSI_MAP_RETAIN_KEY(M, X)
#define GSI_MAP_RELEASE_KEY(M, X)
#define GSI_MAP_RETAIN_VAL(M, X)
#define GSI_MAP_RELEASE_VAL(M, X)
#define GSI_MAP_RETAIN_KEY(M, X)
#define GSI_MAP_RELEASE_KEY(M, X)
#define GSI_MAP_RETAIN_VAL(M, X)
#define GSI_MAP_RELEASE_VAL(M, X)
#define GSI_MAP_HASH(M, X) ((X).nsu ^ ((X).nsu >> 3))
#define GSI_MAP_EQUAL(M, X,Y) ((X).ptr == (Y).ptr)
#define GSI_MAP_NOCLEAN 1
#if GS_WITH_GC
// FIXME ...
// FIXME ...
#include <gc/gc_typed.h>
static GC_descr nodeDesc; // Type descriptor for map node.
#define GSI_MAP_NODES(M, X) \
@ -174,7 +174,7 @@ GSRunLoopForThread(NSThread *aThread)
@interface NSConnection (GNUstepExtensions)
- (void) finalize;
- (void) forwardInvocation: (NSInvocation *)inv
- (void) forwardInvocation: (NSInvocation *)inv
forProxy: (NSDistantObject*)object;
- (const char *) typeForSelector: (SEL)sel remoteTarget: (unsigned)target;
@end
@ -765,7 +765,7 @@ static NSLock *cached_proxies_gate = nil;
return AUTORELEASE(proxy);
}
+ (id) serviceConnectionWithName: (NSString *)name
+ (id) serviceConnectionWithName: (NSString *)name
rootObject: (id)root
{
return [self serviceConnectionWithName: name
@ -773,7 +773,7 @@ static NSLock *cached_proxies_gate = nil;
usingNameServer: [NSPortNameServer systemDefaultPortNameServer]];
}
+ (id) serviceConnectionWithName: (NSString *)name
+ (id) serviceConnectionWithName: (NSString *)name
rootObject: (id)root
usingNameServer: (NSPortNameServer *)server
{
@ -1421,31 +1421,34 @@ static NSLock *cached_proxies_gate = nil;
*/
- (NSArray*) localObjects
{
NSMutableArray *c;
NSArray *a;
/* Don't assert (IisValid); */
GS_M_LOCK(IrefGate);
if (IlocalObjects != 0)
{
GSIMapEnumerator_t enumerator;
GSIMapNode node;
enumerator = GSIMapEnumeratorForMap(IlocalObjects);
node = GSIMapEnumeratorNextNode(&enumerator);
c = [NSMutableArray arrayWithCapacity: IlocalObjects->nodeCount];
NSMutableArray *c =
[NSMutableArray arrayWithCapacity: IlocalObjects->nodeCount];
while (node != 0)
{
[c addObject: node->key.obj];
node = GSIMapEnumeratorNextNode(&enumerator);
}
a = c;
}
else
{
c = [NSArray array];
a = [NSArray array];
}
GSM_UNLOCK(IrefGate);
return c;
return a;
}
/**
@ -2105,7 +2108,7 @@ static NSLock *cached_proxies_gate = nil;
format: @"connection waiting for request was shut down"];
}
aRmc = [self _getReplyRmc: seq];
/*
* Find out if the server is returning an exception instead
* of the return values.
@ -2136,7 +2139,7 @@ static NSLock *cached_proxies_gate = nil;
/* If there is a return value, decode it, and put it in datum. */
if (*tmptype != _C_VOID || (flags & _F_ONEWAY) == 0)
{
{
switch (*tmptype)
{
case _C_ID:
@ -2586,7 +2589,7 @@ static NSLock *cached_proxies_gate = nil;
*/
object = [decoder decodeObject];
/* Decode the selector, (which is the second argument to a method). */
/* Decode the selector, (which is the second argument to a method). */
/* xxx @encode(SEL) produces "^v" in gcc 2.5.8. It should be ":" */
[decoder decodeValueOfObjCType: @encode(SEL) at: &selector];
@ -2606,14 +2609,14 @@ static NSLock *cached_proxies_gate = nil;
object, sel_getName(selector)];
}
type = [sig methodType];
/* Make sure we successfully got the method type, and that its
types match the ENCODED_TYPES. */
NSCParameterAssert (type);
if (GSSelectorTypesMatch(encoded_types, type) == NO)
{
[NSException raise: NSInvalidArgumentException
format: @"NSConection types (%s / %s) missmatch for %s",
format: @"NSConection types (%s / %s) missmatch for %s",
encoded_types, type, sel_getName(selector)];
}
@ -3394,7 +3397,7 @@ static NSLock *cached_proxies_gate = nil;
sendPort:IsendPort
components: nil];
[coder encodeValueOfObjCType: @encode(int) at: &sno];
NSDebugMLLog(@"NSConnection",
NSDebugMLLog(@"NSConnection",
@"Make out RMC %u on %@", sno, self);
return coder;
}
@ -3441,7 +3444,7 @@ static NSLock *cached_proxies_gate = nil;
break;
}
NSDebugMLLog(@"NSConnection",
NSDebugMLLog(@"NSConnection",
@"Sending %@ on %@", stringFromMsgType(msgid), self);
limit = [dateClass dateWithTimeIntervalSinceNow: IrequestTimeout];
@ -4035,7 +4038,7 @@ static NSLock *cached_proxies_gate = nil;
* We enumerate an array copy of the contents of the hash table
* as we know we can do that safely outside the locked region.
* The temporary array and the enumerator are autoreleased and
* will be deallocated with the threads autorelease pool.
* will be deallocated with the threads autorelease pool.
*/
while ((c = [enumerator nextObject]) != nil)
{
@ -4044,4 +4047,3 @@ static NSLock *cached_proxies_gate = nil;
}
}
@end

View file

@ -64,7 +64,7 @@
* Since all the other subclasses are based on NSDataMalloc or
* NSMutableDataMalloc, we can put most methods in here and not
* bother with duplicating them in the other classes.
*
*
*/
#import "common.h"
@ -166,7 +166,7 @@ encodebase64(unsigned char **dstRef,
NSUInteger lineLength;
NSUInteger destLen;
lineLength = 0;
lineLength = 0;
if (options & NSDataBase64Encoding64CharacterLineLength)
lineLength = 64;
else if (options & NSDataBase64Encoding76CharacterLineLength)
@ -243,28 +243,28 @@ readContentsOfFile(NSString* path, void** buf, off_t* len, NSZone* zone)
const unichar *thePath = 0;
#else
const char *thePath = 0;
#endif
#endif
FILE *theFile = 0;
void *tmp = 0;
int c;
off_t fileLength;
#if defined(__MINGW__)
thePath = (const unichar*)[path fileSystemRepresentation];
#else
thePath = [path fileSystemRepresentation];
#endif
#endif
if (thePath == 0)
{
NSWarnFLog(@"Open (%@) attempt failed - bad path", path);
return NO;
}
#if defined(__MINGW__)
theFile = _wfopen(thePath, L"rb");
#else
theFile = fopen(thePath, "rb");
#endif
#endif
if (theFile == 0) /* We failed to open the file. */
{
@ -282,7 +282,7 @@ readContentsOfFile(NSString* path, void** buf, off_t* len, NSZone* zone)
[NSError _last]);
goto failure;
}
/*
* Determine the length of the file (having seeked to the end of the
* file) by calling ftello().
@ -293,7 +293,7 @@ readContentsOfFile(NSString* path, void** buf, off_t* len, NSZone* zone)
NSWarnFLog(@"Ftell on %@ failed - %@", path, [NSError _last]);
goto failure;
}
/*
* Rewind the file pointer to the beginning, preparing to read in
* the file.
@ -310,7 +310,7 @@ readContentsOfFile(NSString* path, void** buf, off_t* len, NSZone* zone)
if (fileLength == 0)
{
unsigned char buf[BUFSIZ];
/*
* Special case ... a file of length zero may be a named pipe or some
* file in the /proc filesystem, which will return us data if we read
@ -362,7 +362,7 @@ readContentsOfFile(NSString* path, void** buf, off_t* len, NSZone* zone)
(intmax_t)fileLength, [NSError _last]);
goto failure;
}
while (offset < fileLength
&& (c = fread(tmp + offset, 1, fileLength - offset, theFile)) != 0)
{
@ -389,7 +389,7 @@ readContentsOfFile(NSString* path, void** buf, off_t* len, NSZone* zone)
*len = fileLength;
fclose(theFile);
return YES;
/*
* Just in case the failure action needs to be changed.
*/
@ -1736,7 +1736,7 @@ failure:
{
c = 0;
// Delete the old file if possible
DeleteFileW(secondaryFile);
DeleteFileW(secondaryFile);
}
else
{
@ -1814,15 +1814,15 @@ failure:
useAuxiliaryFile = YES;
}
if ([path canBeConvertedToEncoding: [NSString defaultCStringEncoding]])
{
{
const char *local_c_path = [path cString];
if (local_c_path != 0 && strlen(local_c_path) < (BUFSIZ*2))
{
{
strncpy(theRealPath, local_c_path, sizeof(theRealPath) - 1);
theRealPath[sizeof(theRealPath) - 1] = '\0';
error_BadPath = NO;
}
}
}
if (error_BadPath)
{
@ -1918,13 +1918,11 @@ failure:
if (useAuxiliaryFile)
{
NSFileManager *mgr = [NSFileManager defaultManager];
NSMutableDictionary *att = nil;
NSDictionary *att = nil;
if ([mgr fileExistsAtPath: path])
{
att = [[mgr fileAttributesAtPath: path
traverseLink: YES] mutableCopy];
IF_NO_GC(AUTORELEASE(att));
att = [mgr fileAttributesAtPath: path traverseLink: YES];
}
c = rename(thePath, theRealPath);
@ -1937,18 +1935,20 @@ failure:
if (att != nil)
{
NSMutableDictionary *mAtt = [att mutableCopy];
IF_NO_GC(AUTORELEASE(mAtt));
/*
* We have created a new file - so we attempt to make it's
* attributes match that of the original.
*/
[att removeObjectForKey: NSFileSize];
[att removeObjectForKey: NSFileModificationDate];
[att removeObjectForKey: NSFileReferenceCount];
[att removeObjectForKey: NSFileSystemNumber];
[att removeObjectForKey: NSFileSystemFileNumber];
[att removeObjectForKey: NSFileDeviceIdentifier];
[att removeObjectForKey: NSFileType];
if ([mgr changeFileAttributes: att atPath: path] == NO)
[mAtt removeObjectForKey: NSFileSize];
[mAtt removeObjectForKey: NSFileModificationDate];
[mAtt removeObjectForKey: NSFileReferenceCount];
[mAtt removeObjectForKey: NSFileSystemNumber];
[mAtt removeObjectForKey: NSFileSystemFileNumber];
[mAtt removeObjectForKey: NSFileDeviceIdentifier];
[mAtt removeObjectForKey: NSFileType];
if ([mgr changeFileAttributes: mAtt atPath: path] == NO)
{
NSWarnMLog(@"Unable to correctly set all attributes for '%@'",
path);
@ -2250,10 +2250,10 @@ failure:
{
[aCoder encodeBytes: bytes
length: length
forKey: @"NS.data"];
forKey: @"NS.data"];
}
else
{
{
[aCoder encodeValueOfObjCType: @encode(NSUInteger)
at: &length];
if (length)
@ -2285,18 +2285,18 @@ failure:
data = [aCoder decodeBytesForKey: @"NS.data"
returnedLength: &l];
returnedLength: &l];
self = [self initWithBytes: data length: l];
}
else
{
{
NSUInteger l;
[aCoder decodeValueOfObjCType: @encode(NSUInteger) at: &l];
if (l)
{
void *b;
#if GS_WITH_GC
b = NSAllocateCollectable(l, 0);
#else
@ -3409,7 +3409,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
}
@end
#endif
#ifdef HAVE_MMAP
@implementation NSDataMappedFile
@ -3443,14 +3443,14 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
{
off_t off;
int fd;
#if defined(__MINGW__)
const unichar *thePath = (const unichar*)[path fileSystemRepresentation];
#else
const char *thePath = [path fileSystemRepresentation];
#endif
if (thePath == 0)
if (thePath == 0)
{
NSWarnMLog(@"Open (%@) attempt failed - bad path", path);
DESTROY(self);
@ -4249,7 +4249,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
}
@end
#endif
#ifdef HAVE_SHMCTL
@implementation NSMutableDataShared
@ -4420,4 +4420,3 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
@end
#endif /* HAVE_SHMCTL */

View file

@ -863,7 +863,7 @@ static SEL appSel;
}
- (void)getObjects: (__unsafe_unretained id[])objects
andKeys: (__unsafe_unretained id[])keys
andKeys: (__unsafe_unretained id<NSCopying>[])keys
{
int i=0;
FOR_IN(id, key, self)
@ -1242,7 +1242,7 @@ compareIt(id o1, id o2, void* context)
if (count > 0)
{
NSEnumerator *enumerator = [self keyEnumerator];
NSObject *k;
NSObject<NSCopying> *k = nil;
while ((k = [enumerator nextObject]) != nil)
{