Simplify memory management/initialisation for strings and data.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@7621 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 2000-09-27 15:26:16 +00:00
parent ef6773dfb5
commit bcb5c31bce
12 changed files with 248 additions and 608 deletions

View file

@ -1,5 +1,13 @@
2000-09-27 Richard Frith-Macdonald <rfm@gnu.org> 2000-09-27 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSCompatibility.m: Use OpenStep standard string initialisation.
* Source/NSSerializer.m: Use OpenStep stanrd initializers.
* Source/NSUnarchiver.m: ditto
* Source/NSData.m: Simplify by removing memory management extensions.
* Source/NSGCString.m: ditto
* Source/NSGString.m: ditto
* Source/NSObject.m: ditto
* Source/NSString.m: ditto
* Source/externs.m: Removed unused NXConstantString assignments. * Source/externs.m: Removed unused NXConstantString assignments.
2000-09-26 Lyndon Tremblay <humasect@home.com> 2000-09-26 Lyndon Tremblay <humasect@home.com>

View file

@ -185,35 +185,6 @@
- (void) deserializeTypeTag: (unsigned char*)tag - (void) deserializeTypeTag: (unsigned char*)tag
andCrossRef: (unsigned int*)xref andCrossRef: (unsigned int*)xref
atCursor: (unsigned*)cursor; atCursor: (unsigned*)cursor;
/*
* -initWithBytesNoCopy:length:fromZone:
* The GNUstep designated initialiser for normal data objects - lets
* the class know what zone the data comes from, so we can avoid the
* overhead of an NSZoneFromPointer() call.
* A zone of zero denotes static memory rather than malloced memory.
*/
- (id) initWithBytesNoCopy: (void*)bytes
length: (unsigned)length
fromZone: (NSZone*)zone;
/*
* -relinquishAllocatedBytes
* For an NSData object with a malloced buffer, returns that buffer and
* removes it from the NSData object, otherwise returns a nul pointer.
* Use with care, preferably when no-one else has retained the NSData
* object - or they will find it's buffer disappearing unexpectedly.
* Once you have used this method, you own the malloced data and are
* responsible for freeing it.
* NB. While this buffer is guaranteed to be freeable by NSZoneFree(),
* it's not necessarily safe to pass it to free()/objc_free() and
* friends. If you wish to pass the buffer to code that might use
* free() or realloc(), you should use the
* -relinquishAllocatedBytesFromZone: method instead - this method
* will only relinquich the buffer if it was allocated from the
* specified zone (a zone of 0 disables this checking).
*/
- (void*) relinquishAllocatedBytes;
- (void*) relinquishAllocatedBytesFromZone: (NSZone*)aZone;
@end @end
#endif #endif

View file

@ -274,12 +274,6 @@ enum {
#ifndef NO_GNUSTEP #ifndef NO_GNUSTEP
- (BOOL) boolValue; - (BOOL) boolValue;
- (id) initWithCharactersNoCopy: (unichar*)chars
length: (unsigned int)length
fromZone: (NSZone*)zone;
- (id) initWithCStringNoCopy: (char*)byteString
length: (unsigned int)length
fromZone: (NSZone*)zone;
#endif /* NO_GNUSTEP */ #endif /* NO_GNUSTEP */
@end @end

View file

@ -168,9 +168,7 @@ encodeBase64(NSData *source)
} }
return [[NSGCString allocWithZone: NSDefaultMallocZone()] return [[NSGCString allocWithZone: NSDefaultMallocZone()]
initWithCStringNoCopy: dBuf initWithCStringNoCopy: dBuf length: destlen-1];
length: destlen-1
fromZone: NSDefaultMallocZone()];
} }
static NSString* static NSString*

View file

@ -286,7 +286,6 @@ failure:
@interface NSDataMalloc : NSDataStatic @interface NSDataMalloc : NSDataStatic
{ {
NSZone *zone;
} }
@end @end
@ -425,7 +424,7 @@ failure:
NSData *d; NSData *d;
d = [dataMalloc allocWithZone: NSDefaultMallocZone()]; d = [dataMalloc allocWithZone: NSDefaultMallocZone()];
d = [d initWithBytesNoCopy: 0 length: 0 fromZone: NSDefaultMallocZone()]; d = [d initWithBytesNoCopy: 0 length: 0];
return d; return d;
} }
@ -437,44 +436,72 @@ failure:
- (id) initWithBytes: (const void*)aBuffer - (id) initWithBytes: (const void*)aBuffer
length: (unsigned)bufferSize length: (unsigned)bufferSize
{ {
[self subclassResponsibility: _cmd]; void *ptr = NSZoneMalloc(NSDefaultMallocZone(), bufferSize);
return nil;
memcpy(ptr, aBuffer, bufferSize);
return [self initWithBytesNoCopy: ptr length: bufferSize];
} }
- (id) initWithBytesNoCopy: (void*)aBuffer - (id) initWithBytesNoCopy: (void*)aBuffer
length: (unsigned)bufferSize length: (unsigned)bufferSize
{ {
if (aBuffer) [self subclassResponsibility: _cmd];
return [self initWithBytesNoCopy: aBuffer return nil;
length: bufferSize
fromZone: NSZoneFromPointer(aBuffer)];
else
return [self initWithBytesNoCopy: aBuffer
length: bufferSize
fromZone: [self zone]];
} }
- (id) initWithContentsOfFile: (NSString *)path - (id) initWithContentsOfFile: (NSString *)path
{ {
[self subclassResponsibility: _cmd]; void *fileBytes;
return nil; unsigned fileLength;
NSZone *zone;
#if GS_WITH_GC
zone = GSAtomicMallocZone();
#else
zone = fastZone(self);
#endif
if (readContentsOfFile(path, &fileBytes, &fileLength, zone) == NO)
{
RELEASE(self);
self = nil;
}
else
{
self = [self initWithBytesNoCopy: fileBytes length: fileLength];
}
return self;
} }
- (id) initWithContentsOfMappedFile: (NSString *)path; - (id) initWithContentsOfMappedFile: (NSString *)path;
{ {
[self subclassResponsibility: _cmd]; #if HAVE_MMAP
return nil; RELEASE(self);
self = [NSDataMappedFile allocWithZone: fastZone(self)];
return [self initWithContentsOfMappedFile: path];
#else
return [self initWithContentsOfFile: path];
#endif
} }
- (id) initWithContentsOfURL: (NSURL*)url - (id) initWithContentsOfURL: (NSURL*)url
{ {
NSData *data = [url resourceDataUsingCache: YES]; NSData *data = [url resourceDataUsingCache: YES];
return [self initWithBytes: [data bytes] length: [data length]]; return [self initWithData: data];
} }
- (id) initWithData: (NSData*)data - (id) initWithData: (NSData*)data
{ {
if (data == nil)
{
return [self initWithBytesNoCopy: 0 length: 0];
}
if ([data isKindOfClass: [NSData class]] == NO)
{
NSLog(@"-initWithData: passed a non-data object");
RELEASE(self);
return nil;
}
return [self initWithBytes: [data bytes] length: [data length]]; return [self initWithBytes: [data bytes] length: [data length]];
} }
@ -518,14 +545,9 @@ failure:
} }
dest[j++] = '>'; dest[j++] = '>';
dest[j] = '\0'; dest[j] = '\0';
#if GS_WITH_GC
str = [[NSString allocWithZone: z]
initWithCStringNoCopy: dest length: j fromZone: GSAtomicMallocZone()];
#else
str = [[NSString allocWithZone: z] initWithCStringNoCopy: dest str = [[NSString allocWithZone: z] initWithCStringNoCopy: dest
length: j length: j
fromZone: z]; freeWhenDone: YES];
#endif
return AUTORELEASE(str); return AUTORELEASE(str);
} }
@ -1227,14 +1249,6 @@ failure:
return AUTORELEASE(d); return AUTORELEASE(d);
} }
- (id) initWithBytesNoCopy: (void*)bytes
length: (unsigned)length
fromZone: (NSZone*)zone
{
[self subclassResponsibility: _cmd];
return nil;
}
- (void) deserializeTypeTag: (unsigned char*)tag - (void) deserializeTypeTag: (unsigned char*)tag
andCrossRef: (unsigned int*)ref andCrossRef: (unsigned int*)ref
atCursor: (unsigned*)cursor atCursor: (unsigned*)cursor
@ -1288,15 +1302,6 @@ failure:
} }
} }
- (void*) relinquishAllocatedBytes
{
return [self relinquishAllocatedBytesFromZone: 0];
}
- (void*) relinquishAllocatedBytesFromZone: (NSZone*)aZone;
{
return 0; /* No data from NSZoneMalloc - return nul pointer */
}
@end @end
@ -1436,7 +1441,6 @@ failure:
- (id) initWithCoder: (NSCoder*)aCoder - (id) initWithCoder: (NSCoder*)aCoder
{ {
unsigned l; unsigned l;
void *b;
NSZone *zone; NSZone *zone;
#if GS_WITH_GC #if GS_WITH_GC
@ -1448,7 +1452,8 @@ failure:
[aCoder decodeValueOfObjCType: @encode(unsigned long) at: &l]; [aCoder decodeValueOfObjCType: @encode(unsigned long) at: &l];
if (l) if (l)
{ {
b = NSZoneMalloc(zone, l); void *b = NSZoneMalloc(zone, l);
if (b == 0) if (b == 0)
{ {
NSLog(@"[NSDataMalloc -initWithCoder:] unable to get %lu bytes", l); NSLog(@"[NSDataMalloc -initWithCoder:] unable to get %lu bytes", l);
@ -1456,12 +1461,13 @@ failure:
return nil; return nil;
} }
[aCoder decodeArrayOfObjCType: @encode(unsigned char) count: l at: b]; [aCoder decodeArrayOfObjCType: @encode(unsigned char) count: l at: b];
self = [self initWithBytesNoCopy: b length: l];
} }
else else
{ {
b = 0; self = [self initWithBytesNoCopy: 0 length: 0];
} }
return [self initWithBytesNoCopy: b length: l fromZone: zone]; return self;
} }
- (id) initWithLength: (unsigned)length - (id) initWithLength: (unsigned)length
@ -1895,16 +1901,8 @@ failure:
[super dealloc]; [super dealloc];
} }
- (id) init
{
return [self initWithBytesNoCopy: 0
length: 0
fromZone: [self zone]];
}
- (id) initWithBytesNoCopy: (void*)aBuffer - (id) initWithBytesNoCopy: (void*)aBuffer
length: (unsigned)bufferSize length: (unsigned)bufferSize
fromZone: (NSZone*)aZone
{ {
bytes = aBuffer; bytes = aBuffer;
length = bufferSize; length = bufferSize;
@ -2309,136 +2307,22 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
- (void) dealloc - (void) dealloc
{ {
if (bytes) if (bytes != 0)
{ {
NSZoneFree(zone, bytes); NSZoneFree(NSZoneFromPointer(bytes), bytes);
bytes = 0; bytes = 0;
} }
[super dealloc]; [super dealloc];
} }
- (id) initWithBytes: (const void*)aBuffer length: (unsigned)bufferSize
{
void* tmp = 0;
if (aBuffer != 0 && bufferSize > 0)
{
#if GS_WITH_GC
zone = GSAtomicMallocZone();
#else
zone = [self zone];
#endif
tmp = NSZoneMalloc(zone, bufferSize);
if (tmp == 0)
{
NSLog(@"[NSDataMalloc -initWithBytes:length:] unable to allocate %lu bytes", bufferSize);
RELEASE(self);
return nil;
}
else
{
memcpy(tmp, aBuffer, bufferSize);
}
}
self = [self initWithBytesNoCopy: tmp length: bufferSize fromZone: zone];
return self;
}
- (id) initWithBytesNoCopy: (void*)aBuffer - (id) initWithBytesNoCopy: (void*)aBuffer
length: (unsigned)bufferSize length: (unsigned)bufferSize
{ {
NSZone *z = NSZoneFromPointer(aBuffer);
return [self initWithBytesNoCopy: aBuffer length: bufferSize fromZone: z];
}
- (id) initWithBytesNoCopy: (void*)aBuffer
length: (unsigned)bufferSize
fromZone: (NSZone*)aZone
{
/*
* If the zone is zero, the data we have been given does not belong
* to use so we must create an NSDataStatic object to contain it.
*/
if (aZone == 0)
{
NSData *data;
data = [[NSDataStatic allocWithZone: NSDefaultMallocZone()]
initWithBytesNoCopy: aBuffer length: bufferSize];
RELEASE(self);
return data;
}
#if GS_WITH_GC
zone = GSAtomicMallocZone();
#else
zone = aZone;
#endif
bytes = aBuffer; bytes = aBuffer;
if (bytes)
{
length = bufferSize; length = bufferSize;
}
return self; return self;
} }
- (id) initWithContentsOfFile: (NSString *)path
{
#if GS_WITH_GC
zone = GSAtomicMallocZone();
#else
zone = [self zone];
#endif
if (readContentsOfFile(path, &bytes, &length, zone) == NO)
{
RELEASE(self);
self = nil;
}
return self;
}
- (id) initWithContentsOfMappedFile: (NSString *)path
{
#if HAVE_MMAP
NSZone *z = [self zone];
RELEASE(self);
self = [NSDataMappedFile allocWithZone: z];
return [self initWithContentsOfMappedFile: path];
#else
return [self initWithContentsOfFile: path];
#endif
}
- (id) initWithData: (NSData*)anObject
{
if (anObject == nil)
{
return [self initWithBytesNoCopy: 0 length: 0 fromZone: [self zone]];
}
if ([anObject isKindOfClass: [NSData class]] == NO)
{
NSLog(@"-initWithData: passed a non-data object");
RELEASE(self);
return nil;
}
return [self initWithBytes: [anObject bytes] length: [anObject length]];
}
- (void*) relinquishAllocatedBytesFromZone: (NSZone*)aZone
{
if (aZone == zone || aZone == 0)
{
void *buf = bytes;
bytes = 0;
length = 0;
return buf;
}
return 0;
}
@end @end
#if HAVE_MMAP #if HAVE_MMAP
@ -2450,7 +2334,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
- (void) dealloc - (void) dealloc
{ {
if (bytes) if (bytes != 0)
{ {
munmap(bytes, length); munmap(bytes, length);
bytes = 0; bytes = 0;
@ -2506,10 +2390,6 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
return self; return self;
} }
- (void*) relinquishAllocatedBytesFromZone: (NSZone*)aZone
{
return 0;
}
@end @end
#endif /* HAVE_MMAP */ #endif /* HAVE_MMAP */
@ -2522,7 +2402,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
- (void) dealloc - (void) dealloc
{ {
if (bytes) if (bytes != 0)
{ {
struct shmid_ds buf; struct shmid_ds buf;
@ -2603,11 +2483,6 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
return self; return self;
} }
- (void*) relinquishAllocatedBytesFromZone: (NSZone*)aZone
{
return 0;
}
- (int) shmID - (int) shmID
{ {
return shmid; return shmid;
@ -2675,24 +2550,10 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
- (id) initWithBytesNoCopy: (void*)aBuffer - (id) initWithBytesNoCopy: (void*)aBuffer
length: (unsigned)bufferSize length: (unsigned)bufferSize
{ {
NSZone *aZone = NSZoneFromPointer(aBuffer);
return [self initWithBytesNoCopy: aBuffer length: bufferSize fromZone: aZone];
}
- (id) initWithBytesNoCopy: (void*)aBuffer
length: (unsigned)bufferSize
fromZone: (NSZone*)aZone
{
if (aZone == 0)
{
self = [self initWithBytes: aBuffer length: bufferSize];
return self;
}
if (aBuffer == 0) if (aBuffer == 0)
{ {
self = [self initWithCapacity: bufferSize]; self = [self initWithCapacity: bufferSize];
if (self) if (self != nil)
{ {
[self setLength: bufferSize]; [self setLength: bufferSize];
} }
@ -2704,7 +2565,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
#if GS_WITH_GC #if GS_WITH_GC
zone = GSAtomicMallocZone(); zone = GSAtomicMallocZone();
#else #else
zone = aZone; zone = NSZoneFromPointer(aBuffer);
#endif #endif
bytes = aBuffer; bytes = aBuffer;
length = bufferSize; length = bufferSize;
@ -2726,7 +2587,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
#if GS_WITH_GC #if GS_WITH_GC
zone = GSAtomicMallocZone(); zone = GSAtomicMallocZone();
#else #else
zone = [self zone]; zone = fastZone(self);
#endif #endif
if (size) if (size)
{ {
@ -2780,21 +2641,6 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
return [self initWithContentsOfFile: path]; return [self initWithContentsOfFile: path];
} }
- (id) initWithData: (NSData*)anObject
{
if (anObject == nil)
{
return [self initWithCapacity: 0];
}
if ([anObject isKindOfClass: [NSData class]] == NO)
{
NSLog(@"-initWithData: passed a non-data object");
RELEASE(self);
return nil;
}
return [self initWithBytes: [anObject bytes] length: [anObject length]];
}
- (void) appendBytes: (const void*)aBuffer - (void) appendBytes: (const void*)aBuffer
length: (unsigned)bufferSize length: (unsigned)bufferSize
{ {
@ -2838,18 +2684,6 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
return bytes; return bytes;
} }
- (void*) relinquishAllocatedBytesFromZone: (NSZone*)aZone
{
void *ptr = [super relinquishAllocatedBytesFromZone: aZone];
if (ptr != 0)
{
capacity = 0;
growth = 1;
}
return ptr;
}
- (void) replaceBytesInRange: (NSRange)aRange - (void) replaceBytesInRange: (NSRange)aRange
withBytes: (const void*)moreBytes withBytes: (const void*)moreBytes
{ {
@ -3331,11 +3165,6 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
return self; return self;
} }
- (void*) relinquishAllocatedBytesFromZone: (NSZone*)aZone
{
return 0;
}
- (int) shmID - (int) shmID
{ {
return shmid; return shmid;

View file

@ -69,7 +69,7 @@
#define GSPLUNI 0 #define GSPLUNI 0
#include "propList.h" #include "propList.h"
static SEL csInitSel = @selector(initWithCStringNoCopy: length: fromZone:); static SEL csInitSel = @selector(initWithCStringNoCopy:length:freeWhenDone:);
static SEL msInitSel = @selector(initWithCapacity:); static SEL msInitSel = @selector(initWithCapacity:);
static IMP csInitImp; /* designated initialiser for cString */ static IMP csInitImp; /* designated initialiser for cString */
static IMP msInitImp; /* designated initialiser for mutable */ static IMP msInitImp; /* designated initialiser for mutable */
@ -118,54 +118,26 @@ static IMP msInitImp; /* designated initialiser for mutable */
return _hash; return _hash;
} }
/*
* This is the GNUstep designated initializer for this class.
* NB. this does NOT change the '_hash' instance variable, so the copy
* methods can safely allocate a new object, copy the _hash into place,
* and then invoke this method to complete the copy operation.
*/
- (id) initWithCStringNoCopy: (char*)byteString
length: (unsigned int)length
fromZone: (NSZone*)zone
{
_count = length;
_contents_chars = (unsigned char*)byteString;
#if GS_WITH_GC
_zone = byteString ? GSAtomicMallocZone() : 0;
#else
_zone = byteString ? zone : 0;
#endif
return self;
}
/* This is the OpenStep designated initializer for this class. */ /* This is the OpenStep designated initializer for this class. */
- (id) initWithCStringNoCopy: (char*)byteString - (id) initWithCStringNoCopy: (char*)byteString
length: (unsigned int)length length: (unsigned int)length
freeWhenDone: (BOOL)flag freeWhenDone: (BOOL)flag
{ {
NSZone *z; _count = length;
_contents_chars = (unsigned char*)byteString;
if (flag && byteString) if (flag == NO)
{ {
z = NSZoneFromPointer(byteString); _zone = 0;
} }
else else
{ {
z = 0; #if GS_WITH_GC
_zone = byteString ? GSAtomicMallocZone() : 0;
#else
_zone = byteString ? NSZoneFromPointer(byteString) : 0;
#endif
} }
return (*csInitImp)(self, csInitSel, byteString, length, z); return self;
}
- (id) initWithCharactersNoCopy: (unichar*)chars
length: (unsigned int)length
fromZone: (NSZone*)zone
{
NSZone *z = zone ? zone : fastZone(self);
id a = [[NSGString allocWithZone: z] initWithCharactersNoCopy: chars
length: length
fromZone: z];
RELEASE(self);
return a;
} }
- (id) initWithCharactersNoCopy: (unichar*)chars - (id) initWithCharactersNoCopy: (unichar*)chars
@ -182,21 +154,7 @@ static IMP msInitImp; /* designated initialiser for mutable */
- (id) init - (id) init
{ {
return [self initWithCStringNoCopy: 0 length: 0 fromZone: 0]; return [self initWithCStringNoCopy: 0 length: 0 freeWhenDone: NO];
}
- (void) _collectionReleaseContents
{
return;
}
- (void) _collectionDealloc
{
if (_zone)
{
NSZoneFree(_zone, (void*)_contents_chars);
_zone = 0;
}
} }
- (void) encodeWithCoder: (NSCoder*)aCoder - (void) encodeWithCoder: (NSCoder*)aCoder
@ -236,20 +194,19 @@ static IMP msInitImp; /* designated initialiser for mutable */
if (NSShouldRetainWithZone(self, z) == NO) if (NSShouldRetainWithZone(self, z) == NO)
{ {
NSGCString *obj; NSGCString *obj;
unsigned char *tmp;
obj = (NSGCString*)NSAllocateObject(_fastCls._NSGCString, 0, z); obj = (NSGCString*)NSAllocateObject(_fastCls._NSGCString, 0, z);
if (_count) if (_count > 0)
{ {
tmp = NSZoneMalloc(z, _count); unsigned char *tmp = NSZoneMalloc(z, _count);
memcpy(tmp, _contents_chars, _count); memcpy(tmp, _contents_chars, _count);
obj = (*csInitImp)(obj, csInitSel, tmp, _count, YES);
} }
else else
{ {
tmp = 0; obj = (*csInitImp)(obj, csInitSel, 0, 0, NO);
z = 0;
} }
obj = (*csInitImp)(obj, csInitSel, tmp, _count, z);
if (_hash && obj) if (_hash && obj)
{ {
obj->_hash = _hash; obj->_hash = _hash;
@ -267,20 +224,19 @@ static IMP msInitImp; /* designated initialiser for mutable */
if (NSShouldRetainWithZone(self, z) == NO) if (NSShouldRetainWithZone(self, z) == NO)
{ {
NSGCString *obj; NSGCString *obj;
unsigned char *tmp;
obj = (NSGCString*)NSAllocateObject(_fastCls._NSGCString, 0, z); obj = (NSGCString*)NSAllocateObject(_fastCls._NSGCString, 0, z);
if (_count) if (_count)
{ {
tmp = NSZoneMalloc(z, _count); unsigned char *tmp = NSZoneMalloc(z, _count);
memcpy(tmp, _contents_chars, _count); memcpy(tmp, _contents_chars, _count);
obj = (*csInitImp)(obj, csInitSel, tmp, _count, YES);
} }
else else
{ {
tmp = 0; obj = (*csInitImp)(obj, csInitSel, 0, 0, NO);
z = 0;
} }
obj = (*csInitImp)(obj, csInitSel, tmp, _count, z);
if (_hash && obj) if (_hash && obj)
{ {
obj->_hash = _hash; obj->_hash = _hash;
@ -619,21 +575,20 @@ static IMP msInitImp; /* designated initialiser for mutable */
- (id) initWithString: (NSString*)string - (id) initWithString: (NSString*)string
{ {
unsigned length = [string cStringLength]; unsigned length = [string cStringLength];
NSZone *z;
unsigned char *buf;
if (length > 0) if (length > 0)
{ {
z = fastZone(self); unsigned char *buf = NSZoneMalloc(fastZone(self), length+1);
buf = NSZoneMalloc(z, length+1); // getCString appends a nul.
// getCString appends a nul.
[string getCString: buf]; [string getCString: buf];
self = [self initWithCStringNoCopy: buf length: length freeWhenDone: YES];
} }
else else
{ {
z = 0; return [self initWithCStringNoCopy: 0 length: 0 freeWhenDone: NO];
buf = 0;
} }
return [self initWithCStringNoCopy: buf length: length fromZone: z]; return self;
} }
- (void) descriptionWithLocale: (NSDictionary*)aLocale - (void) descriptionWithLocale: (NSDictionary*)aLocale
@ -745,7 +700,7 @@ static IMP msInitImp; /* designated initialiser for mutable */
NSString *result; NSString *result;
result = [[_fastCls._NSGCString allocWithZone: z] result = [[_fastCls._NSGCString allocWithZone: z]
initWithCStringNoCopy: buf length: length fromZone: z]; initWithCStringNoCopy: buf length: length freeWhenDone: YES];
[output appendString: result]; [output appendString: result];
RELEASE(result); RELEASE(result);
} }
@ -1029,33 +984,28 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
- (id) initWithCStringNoCopy: (char*)byteString - (id) initWithCStringNoCopy: (char*)byteString
length: (unsigned int)length length: (unsigned int)length
fromZone: (NSZone*)zone freeWhenDone: (BOOL)flag
{ {
self = (*msInitImp)(self, msInitSel, 0); self = (*msInitImp)(self, msInitSel, 0);
if (self) if (self != nil)
{ {
_count = length; _count = length;
_capacity = length; _capacity = length;
_contents_chars = (unsigned char*)byteString; _contents_chars = (unsigned char*)byteString;
if (flag == YES)
{
#if GS_WITH_GC #if GS_WITH_GC
_zone = byteString ? GSAtomicMallocZone() : 0; _zone = (byteString != 0) ? GSAtomicMallocZone() : 0;
#else #else
_zone = byteString ? zone : 0; _zone = (byteString != 0) ? NSZoneFromPointer(byteString) : 0;
#endif #endif
} }
return self; else
}
- (id) initWithCharactersNoCopy: (unichar*)chars
length: (unsigned int)length
fromZone: (NSZone*)zone
{ {
NSZone *z = zone ? zone : fastZone(self); _zone = 0;
id a = [[NSGMutableString allocWithZone: z] initWithCharactersNoCopy: chars }
length: length }
fromZone: z]; return self;
RELEASE(self);
return a;
} }
- (id) initWithCharactersNoCopy: (unichar*)chars - (id) initWithCharactersNoCopy: (unichar*)chars
@ -1072,22 +1022,21 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
- (id) copy - (id) copy
{ {
unsigned char *tmp;
NSGCString *obj; NSGCString *obj;
NSZone *z = NSDefaultMallocZone(); NSZone *z = NSDefaultMallocZone();
obj = (NSGCString*)NSAllocateObject(_fastCls._NSGCString, 0, z); obj = (NSGCString*)NSAllocateObject(_fastCls._NSGCString, 0, z);
if (_count) if (_count)
{ {
tmp = NSZoneMalloc(z, _count); unsigned char *tmp = NSZoneMalloc(z, _count);
memcpy(tmp, _contents_chars, _count); memcpy(tmp, _contents_chars, _count);
obj = (*csInitImp)(obj, csInitSel, tmp, _count, YES);
} }
else else
{ {
tmp = 0; obj = (*csInitImp)(obj, csInitSel, 0, 0, NO);
z = 0;
} }
obj = (*csInitImp)(obj, csInitSel, tmp, _count, z);
if (_hash && obj) if (_hash && obj)
{ {
NSGMutableCString *tmp = (NSGMutableCString*)obj; // Same ivar layout NSGMutableCString *tmp = (NSGMutableCString*)obj; // Same ivar layout
@ -1099,21 +1048,20 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
- (id) copyWithZone: (NSZone*)z - (id) copyWithZone: (NSZone*)z
{ {
unsigned char *tmp;
NSGCString *obj; NSGCString *obj;
obj = (NSGCString*)NSAllocateObject(_fastCls._NSGCString, 0, z); obj = (NSGCString*)NSAllocateObject(_fastCls._NSGCString, 0, z);
if (_count) if (_count)
{ {
tmp = NSZoneMalloc(z, _count); unsigned char *tmp = NSZoneMalloc(z, _count);
memcpy(tmp, _contents_chars, _count); memcpy(tmp, _contents_chars, _count);
obj = (*csInitImp)(obj, csInitSel, tmp, _count, YES);
} }
else else
{ {
tmp = 0; obj = (*csInitImp)(obj, csInitSel, 0, 0, NO);
z = 0;
} }
obj = (*csInitImp)(obj, csInitSel, tmp, _count, z);
if (_hash && obj) if (_hash && obj)
{ {
NSGMutableCString *tmp = (NSGMutableCString*)obj; // Same ivar layout NSGMutableCString *tmp = (NSGMutableCString*)obj; // Same ivar layout
@ -1279,7 +1227,7 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
- (id) init - (id) init
{ {
return [self initWithCStringNoCopy: 0 length: 0 fromZone: 0]; return [self initWithCStringNoCopy: 0 length: 0 freeWhenDone: NO];
} }
- (id) initWithCoder: (NSCoder*)aCoder - (id) initWithCoder: (NSCoder*)aCoder
@ -1330,7 +1278,7 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
- (id) initWithCStringNoCopy: (char*)byteString - (id) initWithCStringNoCopy: (char*)byteString
length: (unsigned int)length length: (unsigned int)length
fromZone: (NSZone*)zone freeWhenDone: (BOOL)flag
{ {
[NSException raise: NSGenericException [NSException raise: NSGenericException
format: @"Attempt to init an NXConstantString"]; format: @"Attempt to init an NXConstantString"];

View file

@ -174,32 +174,13 @@
// Initializing Newly Allocated Strings // Initializing Newly Allocated Strings
/* This is the GNUstep designated initializer for this class. */
- (id) initWithCharactersNoCopy: (unichar*)chars
length: (unsigned int)length
fromZone: (NSZone*)zone
{
self = [super init];
if (self)
{
_count = length;
_contents_chars = chars;
#if GS_WITH_GC
_zone = chars ? GSAtomicMallocZone() : 0;
#else
_zone = chars ? zone : 0;
#endif
}
return self;
}
/* This is the OpenStep designated initializer for this class. */ /* This is the OpenStep designated initializer for this class. */
- (id) initWithCharactersNoCopy: (unichar*)chars - (id) initWithCharactersNoCopy: (unichar*)chars
length: (unsigned int)length length: (unsigned int)length
freeWhenDone: (BOOL)flag freeWhenDone: (BOOL)flag
{ {
self = [super init]; self = [super init];
if (self) if (self != nil)
{ {
_count = length; _count = length;
_contents_chars = chars; _contents_chars = chars;
@ -222,30 +203,21 @@
- (id) initWithCharacters: (const unichar*)chars - (id) initWithCharacters: (const unichar*)chars
length: (unsigned int)length length: (unsigned int)length
{ {
NSZone *z = fastZone(self); if (length > 0)
unichar *s;
if (length)
{ {
s = NSZoneMalloc(z, length*sizeof(unichar)); unichar *s = NSZoneMalloc(fastZone(self), length*sizeof(unichar));
if (chars)
if (chars != 0)
memcpy(s, chars, sizeof(unichar)*length); memcpy(s, chars, sizeof(unichar)*length);
self = [self initWithCharactersNoCopy: s
length: length
freeWhenDone: YES];
} }
else else
{ {
s = 0; self = [self initWithCharactersNoCopy: 0 length: 0 freeWhenDone: NO];
} }
return [self initWithCharactersNoCopy:s length:length fromZone:z]; return self;
}
- (id) initWithCStringNoCopy: (char*)byteString
length: (unsigned int)length
fromZone: (NSZone*)zone
{
id a = [[NSGCString allocWithZone: zone]
initWithCStringNoCopy: byteString length: length fromZone: zone];
[self release];
return a;
} }
- (id) initWithCStringNoCopy: (char*)byteString - (id) initWithCStringNoCopy: (char*)byteString
@ -254,13 +226,13 @@
{ {
id a = [[NSGCString allocWithZone: fastZone(self)] id a = [[NSGCString allocWithZone: fastZone(self)]
initWithCStringNoCopy: byteString length: length freeWhenDone: flag]; initWithCStringNoCopy: byteString length: length freeWhenDone: flag];
[self release]; RELEASE(self);
return a; return a;
} }
- (id) init - (id) init
{ {
return [self initWithCharactersNoCopy:0 length:0 fromZone: fastZone(self)]; return [self initWithCharactersNoCopy:0 length:0 freeWhenDone: 0];
} }
// Getting a String's Length // Getting a String's Length
@ -412,23 +384,6 @@
} }
// ******* Stuff from NSGCString *********
// Do we need this ???
- (void) _collectionReleaseContents
{
return;
}
- (void) _collectionDealloc
{
if (_zone)
{
NSZoneFree(_zone, _contents_chars);
_zone = 0;
}
}
- (id) propertyList - (id) propertyList
{ {
id result; id result;
@ -704,32 +659,12 @@ stringDecrementCountAndFillHoleAt(NSGMutableStringStruct *self,
return [self initWithCapacity: 0]; return [self initWithCapacity: 0];
} }
/* This is the GNUstep designated initializer for this class. */
- (id) initWithCharactersNoCopy: (unichar*)chars
length: (unsigned int)length
fromZone: (NSZone*)zone
{
self = [super init];
if (self)
{
_count = length;
_capacity = length;
_contents_chars = chars;
#if GS_WITH_GC
_zone = _zone ? GSAtomicMallocZone() : 0;
#else
_zone = zone;
#endif
}
return self;
}
- (id) initWithCharactersNoCopy: (unichar*)chars - (id) initWithCharactersNoCopy: (unichar*)chars
length: (unsigned int)length length: (unsigned int)length
freeWhenDone: (BOOL)flag freeWhenDone: (BOOL)flag
{ {
self = [super init]; self = [super init];
if (self) if (self != nil)
{ {
_count = length; _count = length;
_capacity = length; _capacity = length;
@ -771,23 +706,13 @@ stringDecrementCountAndFillHoleAt(NSGMutableStringStruct *self,
return self; return self;
} }
- (id) initWithCStringNoCopy: (char*)byteString
length: (unsigned int)length
fromZone: (NSZone*)zone
{
id a = [[NSGMutableCString allocWithZone: zone]
initWithCStringNoCopy: byteString length: length fromZone: zone];
[self release];
return a;
}
- (id) initWithCStringNoCopy: (char*)byteString - (id) initWithCStringNoCopy: (char*)byteString
length: (unsigned int)length length: (unsigned int)length
freeWhenDone: (BOOL)flag freeWhenDone: (BOOL)flag
{ {
id a = [[NSGMutableCString allocWithZone: fastZone(self)] id a = [[NSGMutableCString allocWithZone: fastZone(self)]
initWithCStringNoCopy: byteString length: length freeWhenDone: flag]; initWithCStringNoCopy: byteString length: length freeWhenDone: flag];
[self release]; RELEASE(self);
return a; return a;
} }

View file

@ -111,8 +111,8 @@ void _fastBuildCache()
static objc_mutex_t retain_counts_gate = NULL; static objc_mutex_t retain_counts_gate = NULL;
#if GS_WITH_GC == 0 #if GS_WITH_GC == 0
#define REFCNT_LOCAL 1 #define REFCNT_LOCAL 0
#define CACHE_ZONE 1 #define CACHE_ZONE 0
#endif #endif
#if defined(REFCNT_LOCAL) || defined(CACHE_ZONE) #if defined(REFCNT_LOCAL) || defined(CACHE_ZONE)

View file

@ -371,9 +371,9 @@ typedef struct {
static SEL debSel = @selector(deserializeBytes:length:atCursor:); static SEL debSel = @selector(deserializeBytes:length:atCursor:);
static SEL deiSel = @selector(deserializeIntAtCursor:); static SEL deiSel = @selector(deserializeIntAtCursor:);
static SEL csInitSel = @selector(initWithCStringNoCopy:length:fromZone:); static SEL csInitSel = @selector(initWithCStringNoCopy:length:freeWhenDone:);
static SEL usInitSel = @selector(initWithCharactersNoCopy:length:fromZone:); static SEL usInitSel = @selector(initWithCharactersNoCopy:length:freeWhenDone:);
static SEL dInitSel = @selector(initWithBytesNoCopy:length:fromZone:); static SEL dInitSel = @selector(initWithBytesNoCopy:length:);
static SEL iaInitSel = @selector(initWithObjects:count:); static SEL iaInitSel = @selector(initWithObjects:count:);
static SEL maInitSel = @selector(initWithObjects:count:); static SEL maInitSel = @selector(initWithObjects:count:);
static SEL idInitSel = @selector(initWithObjects:forKeys:count:); static SEL idInitSel = @selector(initWithObjects:forKeys:count:);
@ -429,7 +429,7 @@ deserializeFromInfo(_NSDeserializerInfo* info)
(*info->debImp)(info->data, debSel, b, size, info->cursor); (*info->debImp)(info->data, debSel, b, size, info->cursor);
s = (NSGCString*)NSAllocateObject(CSCls, 0, NSDefaultMallocZone()); s = (NSGCString*)NSAllocateObject(CSCls, 0, NSDefaultMallocZone());
s = (*csInitImp)(s, csInitSel, b, size-1, NSDefaultMallocZone()); s = (*csInitImp)(s, csInitSel, b, size-1, YES);
/* /*
* If we are supposed to be doing uniquing of strings, handle it. * If we are supposed to be doing uniquing of strings, handle it.
@ -453,7 +453,7 @@ deserializeFromInfo(_NSDeserializerInfo* info)
(*info->debImp)(info->data, debSel, b, size*2, info->cursor); (*info->debImp)(info->data, debSel, b, size*2, info->cursor);
s = (NSGString*)NSAllocateObject(USCls, 0, NSDefaultMallocZone()); s = (NSGString*)NSAllocateObject(USCls, 0, NSDefaultMallocZone());
s = (*usInitImp)(s, usInitSel, b, size, NSDefaultMallocZone()); s = (*usInitImp)(s, usInitSel, b, size, YES);
/* /*
* If we are supposed to be doing uniquing of strings, handle it. * If we are supposed to be doing uniquing of strings, handle it.
@ -570,11 +570,19 @@ deserializeFromInfo(_NSDeserializerInfo* info)
case ST_DATA: case ST_DATA:
{ {
NSData *d; NSData *d;
d = (NSData*)NSAllocateObject(DCls, 0, NSDefaultMallocZone());
if (size > 0)
{
void *b = NSZoneMalloc(NSDefaultMallocZone(), size); void *b = NSZoneMalloc(NSDefaultMallocZone(), size);
(*info->debImp)(info->data, debSel, b, size, info->cursor); (*info->debImp)(info->data, debSel, b, size, info->cursor);
d = (NSData*)NSAllocateObject(DCls, 0, NSDefaultMallocZone()); d = (*dInitImp)(d, dInitSel, b, size);
d = (*dInitImp)(d, dInitSel, b, size, NSDefaultMallocZone()); }
else
{
d = (*dInitImp)(d, dInitSel, 0, 0);
}
return d; return d;
} }

View file

@ -353,69 +353,41 @@ handle_printf_atsign (FILE *stream,
// Initializing Newly Allocated Strings // Initializing Newly Allocated Strings
/* This is the designated initializer for Unicode Strings. */ /* This is the designated initializer for Unicode Strings. */
- (id) initWithCharactersNoCopy: (unichar*)chars
length: (unsigned)length
fromZone: (NSZone*)zone
{
[self subclassResponsibility: _cmd];
return self;
}
- (id) initWithCharactersNoCopy: (unichar*)chars - (id) initWithCharactersNoCopy: (unichar*)chars
length: (unsigned)length length: (unsigned)length
freeWhenDone: (BOOL)flag freeWhenDone: (BOOL)flag
{ {
if (flag) [self subclassResponsibility: _cmd];
return [self initWithCharactersNoCopy: chars
length: length
fromZone: NSZoneFromPointer(chars)];
else
return [self initWithCharactersNoCopy: chars
length: length
fromZone: 0];
return self; return self;
} }
- (id) initWithCharacters: (const unichar*)chars - (id) initWithCharacters: (const unichar*)chars
length: (unsigned)length length: (unsigned)length
{ {
NSZone *z;
unichar *s;
if (length > 0) if (length > 0)
{ {
z = [self zone]; unichar *s = NSZoneMalloc(fastZone(self), sizeof(unichar)*length);
s = NSZoneMalloc(z, sizeof(unichar)*length);
if (chars) if (chars != 0)
{
memcpy(s, chars, sizeof(unichar)*length); memcpy(s, chars, sizeof(unichar)*length);
} }
self = [self initWithCharactersNoCopy: s
length: length
freeWhenDone: YES];
}
else else
{ {
s = 0; self = [self initWithCharactersNoCopy: 0 length: 0 freeWhenDone: NO];
z = 0;
} }
return [self initWithCharactersNoCopy: s length: length fromZone: z]; return self;
}
- (id) initWithCStringNoCopy: (char*)byteString
length: (unsigned)length
freeWhenDone: (BOOL)flag
{
if (flag)
return [self initWithCStringNoCopy: byteString
length: length
fromZone: length?NSZoneFromPointer(byteString):0];
else
return [self initWithCStringNoCopy: byteString
length: length
fromZone: 0];
} }
/* This is the designated initializer for CStrings. */ /* This is the designated initializer for CStrings. */
- (id) initWithCStringNoCopy: (char*)byteString - (id) initWithCStringNoCopy: (char*)byteString
length: (unsigned)length length: (unsigned)length
fromZone: (NSZone*)zone freeWhenDone: (BOOL)flag
{ {
[self subclassResponsibility: _cmd]; [self subclassResponsibility: _cmd];
return self; return self;
@ -423,25 +395,22 @@ handle_printf_atsign (FILE *stream,
- (id) initWithCString: (const char*)byteString length: (unsigned)length - (id) initWithCString: (const char*)byteString length: (unsigned)length
{ {
NSZone *z;
char *s;
if (length > 0) if (length > 0)
{ {
z = [self zone]; char *s = NSZoneMalloc(fastZone(self), length);
s = NSZoneMalloc(z, length);
if (byteString) if (byteString != 0)
{ {
memcpy(s, byteString, length); memcpy(s, byteString, length);
} }
self = [self initWithCStringNoCopy: s length: length freeWhenDone: YES];
} }
else else
{ {
s = 0; self = [self initWithCStringNoCopy: 0 length: 0 freeWhenDone: NO];
z = 0;
} }
return [self initWithCStringNoCopy: s length: length fromZone: z]; return self;
} }
- (id) initWithCString: (const char*)byteString - (id) initWithCString: (const char*)byteString
@ -453,45 +422,45 @@ handle_printf_atsign (FILE *stream,
- (id) initWithString: (NSString*)string - (id) initWithString: (NSString*)string
{ {
unsigned length = [string length]; unsigned length = [string length];
NSZone *z;
unichar *s;
if (length > 0) if (length > 0)
{ {
z = [self zone]; unichar *s = NSZoneMalloc(fastZone(self), sizeof(unichar)*length);
s = NSZoneMalloc(z, sizeof(unichar)*length);
[string getCharacters: s]; [string getCharacters: s];
self = [self initWithCharactersNoCopy: s
length: length
freeWhenDone: YES];
} }
else else
{ {
s = 0; self = [self initWithCharactersNoCopy: 0
z = 0; length: 0
freeWhenDone: NO];
} }
return [self initWithCharactersNoCopy: s return self;
length: length
fromZone: z];
} }
- (id) initWithUTF8String:(const char *)bytes - (id) initWithUTF8String:(const char *)bytes
{ {
unsigned length = strlen(bytes); unsigned length = strlen(bytes);
NSZone *z;
unichar *s;
if (length > 0) if (length > 0)
{ {
z = [self zone]; unichar *s = NSZoneMalloc(fastZone(self), sizeof(unichar)*length);
s = NSZoneMalloc(z, sizeof(unichar)*length);
length = encode_strtoustr(s, bytes, length+1, NSUTF8StringEncoding); length = encode_strtoustr(s, bytes, length+1, NSUTF8StringEncoding);
self = [self initWithCharactersNoCopy: s
length: length
freeWhenDone: YES];
} }
else else
{ {
s = 0; self = [self initWithCharactersNoCopy: 0
z = 0; length: 0
freeWhenDone: NO];
} }
return [self initWithCharactersNoCopy: s return self;
length: length
fromZone: z];
} }
- (id) initWithFormat: (NSString*)format,... - (id) initWithFormat: (NSString*)format,...
@ -816,50 +785,56 @@ handle_printf_atsign (FILE *stream,
|| (encoding == NSASCIIStringEncoding)) || (encoding == NSASCIIStringEncoding))
{ {
unsigned len = [data length]; unsigned len = [data length];
NSZone *z;
char *s;
if (len > 0) if (len > 0)
{ {
z = fastZone(self); char *s = NSZoneMalloc(fastZone(self), len);
s = NSZoneMalloc(z, len);
[data getBytes: s]; [data getBytes: s];
self = [self initWithCStringNoCopy: s length: len freeWhenDone: YES];
} }
else else
{ {
s = 0; self = [self initWithCStringNoCopy: 0 length: 0 freeWhenDone: NO];
z = 0;
} }
return [self initWithCStringNoCopy: s length: len fromZone: z]; return self;
} }
else else
{ {
unsigned len = [data length]; unsigned len = [data length];
NSZone *z;
unichar *u; unichar *u;
unsigned count; unsigned count;
const unsigned char *b; const unsigned char *b;
z = fastZone(self);
if (len < 2) if (len < 2)
return [self initWithCStringNoCopy: 0 length: 0 fromZone: z]; return [self initWithCStringNoCopy: 0 length: 0 freeWhenDone: NO];
b = [data bytes]; b = [data bytes];
u = NSZoneMalloc(z, sizeof(unichar)*(len+1)); u = NSZoneMalloc(fastZone(self), sizeof(unichar)*(len+1));
if (encoding == NSUnicodeStringEncoding) if (encoding == NSUnicodeStringEncoding)
{ {
if ((b[0]==0xFE) & (b[1]==0xFF)) if ((b[0]==0xFE) & (b[1]==0xFF))
{
for (count = 2; count < (len - 1); count += 2) for (count = 2; count < (len - 1); count += 2)
{
u[count/2 - 1] = 256*b[count] + b[count + 1]; u[count/2 - 1] = 256*b[count] + b[count + 1];
}
}
else else
{
for (count = 2; count < (len - 1); count += 2) for (count = 2; count < (len - 1); count += 2)
{
u[count/2 - 1] = 256*b[count + 1] + b[count]; u[count/2 - 1] = 256*b[count + 1] + b[count];
}
}
count = count/2 - 1; count = count/2 - 1;
} }
else else
{
count = encode_strtoustr(u, b, len, encoding); count = encode_strtoustr(u, b, len, encoding);
}
return [self initWithCharactersNoCopy: u length: count fromZone: z]; self = [self initWithCharactersNoCopy: u length: count freeWhenDone: YES];
} }
return self; return self;
} }
@ -875,7 +850,9 @@ handle_printf_atsign (FILE *stream,
if ([d length] < 2) if ([d length] < 2)
return @""; return @"";
test = [d bytes]; test = [d bytes];
if (test && (((test[0]==0xFF) && (test[1]==0xFE)) || ((test[1]==0xFF) && (test[0]==0xFE)))) if (test != 0 &&
(((test[0]==0xFF) && (test[1]==0xFE))
|| ((test[1]==0xFF) && (test[0]==0xFE))))
enc = NSUnicodeStringEncoding; enc = NSUnicodeStringEncoding;
else else
enc = [NSString defaultCStringEncoding]; enc = [NSString defaultCStringEncoding];
@ -893,7 +870,9 @@ handle_printf_atsign (FILE *stream,
if ([d length] < 2) if ([d length] < 2)
return @""; return @"";
test = [d bytes]; test = [d bytes];
if (test && (((test[0]==0xFF) && (test[1]==0xFE)) || ((test[1]==0xFF) && (test[0]==0xFE)))) if (test != 0
&& (((test[0]==0xFF) && (test[1]==0xFE))
|| ((test[1]==0xFF) && (test[0]==0xFE))))
enc = NSUnicodeStringEncoding; enc = NSUnicodeStringEncoding;
else else
enc = [NSString defaultCStringEncoding]; enc = [NSString defaultCStringEncoding];
@ -961,16 +940,16 @@ handle_printf_atsign (FILE *stream,
- (NSString*) stringByAppendingString: (NSString*)aString - (NSString*) stringByAppendingString: (NSString*)aString
{ {
NSZone *z = fastZone(self);
unsigned len = [self length]; unsigned len = [self length];
unsigned otherLength = [aString length]; unsigned otherLength = [aString length];
NSZone *z = fastZone(self);
unichar *s = NSZoneMalloc(z, (len+otherLength)*sizeof(unichar)); unichar *s = NSZoneMalloc(z, (len+otherLength)*sizeof(unichar));
NSString *tmp; NSString *tmp;
[self getCharacters: s]; [self getCharacters: s];
[aString getCharacters: s + len]; [aString getCharacters: s + len];
tmp = [[NSString_concrete_class allocWithZone: z] initWithCharactersNoCopy: s tmp = [[NSString_concrete_class allocWithZone: z] initWithCharactersNoCopy: s
length: len+otherLength fromZone: z]; length: len + otherLength freeWhenDone: YES];
return AUTORELEASE(tmp); return AUTORELEASE(tmp);
} }
@ -1023,7 +1002,6 @@ handle_printf_atsign (FILE *stream,
- (NSString*) substringWithRange: (NSRange)aRange - (NSString*) substringWithRange: (NSRange)aRange
{ {
NSZone *z;
unichar *buf; unichar *buf;
id ret; id ret;
unsigned len = [self length]; unsigned len = [self length];
@ -1032,11 +1010,10 @@ handle_printf_atsign (FILE *stream,
if (aRange.length == 0) if (aRange.length == 0)
return @""; return @"";
z = fastZone(self); buf = NSZoneMalloc(fastZone(self), sizeof(unichar)*aRange.length);
buf = NSZoneMalloc(z, sizeof(unichar)*aRange.length);
[self getCharacters: buf range: aRange]; [self getCharacters: buf range: aRange];
ret = [[NSString_concrete_class allocWithZone: NSDefaultMallocZone()] ret = [[NSString_concrete_class allocWithZone: NSDefaultMallocZone()]
initWithCharactersNoCopy: buf length: aRange.length fromZone: z]; initWithCharactersNoCopy: buf length: aRange.length freeWhenDone: YES];
return AUTORELEASE(ret); return AUTORELEASE(ret);
} }
@ -1542,7 +1519,6 @@ handle_printf_atsign (FILE *stream,
// but this will work in most cases // but this will work in most cases
- (NSString*) capitalizedString - (NSString*) capitalizedString
{ {
NSZone *z;
unichar *s; unichar *s;
unsigned count = 0; unsigned count = 0;
BOOL found = YES; BOOL found = YES;
@ -1553,8 +1529,7 @@ handle_printf_atsign (FILE *stream,
if (whitespce == nil) if (whitespce == nil)
setupWhitespce(); setupWhitespce();
z = fastZone(self); s = NSZoneMalloc(fastZone(self), sizeof(unichar)*len);
s = NSZoneMalloc(z, sizeof(unichar)*len);
[self getCharacters: s]; [self getCharacters: s];
while (count < len) while (count < len)
{ {
@ -1588,12 +1563,11 @@ handle_printf_atsign (FILE *stream,
found = NO; found = NO;
} }
return AUTORELEASE([[NSString allocWithZone: NSDefaultMallocZone()] return AUTORELEASE([[NSString allocWithZone: NSDefaultMallocZone()]
initWithCharactersNoCopy: s length: len fromZone: z]); initWithCharactersNoCopy: s length: len freeWhenDone: YES]);
} }
- (NSString*) lowercaseString - (NSString*) lowercaseString
{ {
NSZone *z;
unichar *s; unichar *s;
unsigned count; unsigned count;
unsigned len = [self length]; unsigned len = [self length];
@ -1603,8 +1577,7 @@ handle_printf_atsign (FILE *stream,
{ {
return self; return self;
} }
z = fastZone(self); s = NSZoneMalloc(fastZone(self), sizeof(unichar)*len);
s = NSZoneMalloc(z, sizeof(unichar)*len);
caiImp = (unichar (*)())[self methodForSelector: caiSel]; caiImp = (unichar (*)())[self methodForSelector: caiSel];
for (count = 0; count < len; count++) for (count = 0; count < len; count++)
{ {
@ -1612,12 +1585,11 @@ handle_printf_atsign (FILE *stream,
} }
return AUTORELEASE([[NSString_concrete_class return AUTORELEASE([[NSString_concrete_class
allocWithZone: NSDefaultMallocZone()] allocWithZone: NSDefaultMallocZone()]
initWithCharactersNoCopy: s length: len fromZone: z]); initWithCharactersNoCopy: s length: len freeWhenDone: YES]);
} }
- (NSString*) uppercaseString; - (NSString*) uppercaseString;
{ {
NSZone *z;
unichar *s; unichar *s;
unsigned count; unsigned count;
unsigned len = [self length]; unsigned len = [self length];
@ -1627,8 +1599,7 @@ handle_printf_atsign (FILE *stream,
{ {
return self; return self;
} }
z = fastZone(self); s = NSZoneMalloc(fastZone(self), sizeof(unichar)*len);
s = NSZoneMalloc(z, sizeof(unichar)*len);
caiImp = (unichar (*)())[self methodForSelector: caiSel]; caiImp = (unichar (*)())[self methodForSelector: caiSel];
for (count = 0; count < len; count++) for (count = 0; count < len; count++)
{ {
@ -1636,7 +1607,7 @@ handle_printf_atsign (FILE *stream,
} }
return AUTORELEASE([[NSString_concrete_class return AUTORELEASE([[NSString_concrete_class
allocWithZone: NSDefaultMallocZone()] allocWithZone: NSDefaultMallocZone()]
initWithCharactersNoCopy: s length: len fromZone: z]); initWithCharactersNoCopy: s length: len freeWhenDone: YES]);
} }
// Storing the String // Storing the String

View file

@ -975,8 +975,7 @@ mapClassName(NSUnarchiverObjectInfo *info)
count: l count: l
at: b]; at: b];
d = [[NSData allocWithZone: zone] initWithBytesNoCopy: b d = [[NSData allocWithZone: zone] initWithBytesNoCopy: b
length: l length: l];
fromZone: z];
IF_NO_GC(AUTORELEASE(d)); IF_NO_GC(AUTORELEASE(d));
return d; return d;
} }

View file

@ -1,11 +1,6 @@
#include <Foundation/Foundation.h> #include <Foundation/Foundation.h>
#include <stdio.h> #include <stdio.h>
#define _(X) \
[[NSBundle mainBundle] localizedStringForKey: @#X value: nil table: nil]
#define $(X) \
[[NSBundle mainBundle] localizedStringForKey: X value: nil table: nil]
#if 0 #if 0
int main () int main ()
@ -19,18 +14,12 @@ int main (int argc, char **argv)
{ {
NSString *string; NSString *string;
id pool = [NSAutoreleasePool new]; id pool = [NSAutoreleasePool new];
NSURL *url = [NSURL fileURLWithPath: @"/tmp/a"]; NSProcessInfo *info = [NSProcessInfo processInfo];
NSData *data = [url resourceDataUsingCache: YES]; NSUserDefaults *defaults;
NSLog(@"%@", data);
url = [NSURL fileURLWithPath: @"/tmp/z"];
[url setResourceData: data];
NSLog(@"%@", _(Testing));
NSLog(@"%@", $(@"Testing"));
string = [NSString stringWithCString:argv[1]];
[info setProcessName: @"TestProcess"];
defaults = [NSUserDefaults standardUserDefaults];
NSLog(@"%@", [defaults dictionaryRepresentation]);
return 0; return 0;
} }
#endif #endif