Garbage collection updates

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4510 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-07-03 19:59:44 +00:00
parent ee8a964960
commit 006286ee6a
22 changed files with 869 additions and 707 deletions

View file

@ -1,3 +1,27 @@
Sat Jul 3 21:05:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSCallBacks.m: Changes for garbage collection.
* Source/NSDateFormatter.m: ditto.
* Source/NSDictionary.m: ditto.
* Source/NSDistributedLock.m: ditto.
* Source/NSDistributedNotificationCenter.m: ditto.
* Source/NSGArray.m: ditto.
* Source/NSGCString.m: ditto.
* Source/NSGCountedSet.m: ditto.
* Source/NSGDictionary.m: ditto.
* Source/NSGSet.m: ditto.
* Source/NSHost.m: ditto.
* Source/NSInvocation.m: ditto.
* Source/NSNotification.m: ditto.
* Source/NSProtocolChecker.m: ditto.
* Source/NSScanner.m: ditto.
* Source/NSSerializer.m: ditto.
* Source/NSSet.m: ditto.
* Source/NSData.m: ditto.
* Source/NSPortNameServer.m: ditto.
* Source/NSUndoManager.m: ditto.
* Source/NSURL.m: ditto.
Fri Jul 2 14:20:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/GSeq.h: Fix boundary error when searching for string in

View file

@ -149,14 +149,14 @@ _NS_id_is_equal (void *table, id <NSObject> o, id <NSObject> p)
void
_NS_id_retain (void *table, id <NSObject> o)
{
[o retain];
RETAIN(o);
return;
}
void
_NS_id_release (void *table, id <NSObject> o)
{
[o release];
RELEASE(o);
return;
}

View file

@ -273,45 +273,63 @@ failure:
+ (id) data
{
return [[[NSDataStatic allocWithZone: NSDefaultMallocZone()]
initWithBytesNoCopy: 0 length: 0] autorelease];
NSData *d;
d = [NSDataStatic allocWithZone: NSDefaultMallocZone()];
d = [d initWithBytesNoCopy: 0 length: 0];
return AUTORELEASE(d);
}
+ (id) dataWithBytes: (const void*)bytes
length: (unsigned)length
{
return [[[dataMalloc allocWithZone: NSDefaultMallocZone()]
initWithBytes: bytes length: length] autorelease];
NSData *d;
d = [dataMalloc allocWithZone: NSDefaultMallocZone()];
d = [d initWithBytes: bytes length: length];
return AUTORELEASE(d);
}
+ (id) dataWithBytesNoCopy: (void*)bytes
length: (unsigned)length
{
return [[[dataMalloc allocWithZone: NSDefaultMallocZone()]
initWithBytesNoCopy: bytes length: length] autorelease];
NSData *d;
d = [dataMalloc allocWithZone: NSDefaultMallocZone()];
d = [d initWithBytesNoCopy: bytes length: length];
return AUTORELEASE(d);
}
+ (id) dataWithContentsOfFile: (NSString*)path
{
return [[[dataMalloc allocWithZone: NSDefaultMallocZone()]
initWithContentsOfFile: path] autorelease];
NSData *d;
d = [dataMalloc allocWithZone: NSDefaultMallocZone()];
d = [d initWithContentsOfFile: path];
return AUTORELEASE(d);
}
+ (id) dataWithContentsOfMappedFile: (NSString*)path
{
NSData *d;
#if HAVE_MMAP
return [[[NSDataMappedFile allocWithZone: NSDefaultMallocZone()]
initWithContentsOfMappedFile: path] autorelease];
d = [NSDataMappedFile allocWithZone: NSDefaultMallocZone()];
d = [d initWithContentsOfMappedFile: path];
#else
return [[[dataMalloc allocWithZone: NSDefaultMallocZone()]
initWithContentsOfMappedFile: path] autorelease];
d = [dataMalloc allocWithZone: NSDefaultMallocZone()];
d = [d initWithContentsOfMappedFile: path];
#endif
return AUTORELEASE(d);
}
+ (id) dataWithData: (NSData*)data
{
return [[[dataMalloc allocWithZone: NSDefaultMallocZone()]
initWithBytes: [data bytes] length: [data length]] autorelease];
NSData *d;
d = [dataMalloc allocWithZone: NSDefaultMallocZone()];
d = [d initWithBytes: [data bytes] length: [data length]];
return AUTORELEASE(d);
}
- (id) init
@ -394,10 +412,10 @@ failure:
}
dest[j++] = '>';
dest[j] = '\0';
str = [[[NSString allocWithZone: z] initWithCStringNoCopy: dest
length: j
fromZone: z] autorelease];
return str;
str = [[NSString allocWithZone: z] initWithCStringNoCopy: dest
length: j
fromZone: z];
return AUTORELEASE(str);
}
- (void)getBytes: (void*)buffer
@ -581,8 +599,7 @@ failure:
if ([mgr fileExistsAtPath: path])
{
att = [[mgr fileAttributesAtPath:path traverseLink:YES] mutableCopy];
if (att)
[att autorelease];
TEST_AUTORELEASE(att);
}
c = rename(thePath, theRealPath);
@ -676,14 +693,16 @@ failure:
}
else
{
unsigned len = (length+1)*sizeof(char);
unsigned len = (length+1)*sizeof(char);
NSZone *z = [self zone];
NSData *d;
*(char**)data = (char*)NSZoneMalloc(z, len);
[[[dataMalloc allocWithZone: z]
initWithBytesNoCopy: *(void**)data
length: len
fromZone: z] autorelease];
d = [dataMalloc allocWithZone: z];
d = [d initWithBytesNoCopy: *(void**)data
length: len
fromZone: z];
AUTORELEASE(d);
}
[self deserializeBytes: *(char**)data
@ -744,14 +763,16 @@ failure:
}
case _C_PTR:
{
unsigned len = objc_sizeof_type(++type);
NSZone *z = [self zone];
unsigned len = objc_sizeof_type(++type);
NSZone *z = [self zone];
NSData *d;
*(char**)data = (char*)NSZoneMalloc(z, len);
[[[dataMalloc allocWithZone: z]
initWithBytesNoCopy: *(void**)data
length: len
fromZone: z] autorelease];
d = [dataMalloc allocWithZone: z];
d = [d initWithBytesNoCopy: *(void**)data
length: len
fromZone: z];
AUTORELEASE(d);
[self deserializeDataAt: *(char**)data
ofObjCType: type
atCursor: cursor
@ -969,7 +990,7 @@ failure:
{
if (NSShouldRetainWithZone(self, z) &&
[self isKindOfClass: [NSMutableData class]] == NO)
return [self retain];
return RETAIN(self);
else
return [[dataMalloc allocWithZone: z]
initWithBytes: [self bytes] length: [self length]];
@ -998,8 +1019,11 @@ failure:
+ (id) dataWithShmID: (int)anID length: (unsigned)length
{
#if HAVE_SHMCTL
return [[[NSDataShared allocWithZone: NSDefaultMallocZone()]
initWithShmID: anID length: length] autorelease];
NSDataShared *d;
d = [NSDataShared allocWithZone: NSDefaultMallocZone()];
d = [d initWithShmID: anID length: length];
return AUTORELEASE(d);
#else
NSLog(@"[NSData -dataWithSmdID:length:] no shared memory support");
return nil;
@ -1008,19 +1032,25 @@ failure:
+ (id) dataWithSharedBytes: (const void*)bytes length: (unsigned)length
{
NSData *d;
#if HAVE_SHMCTL
return [[[NSDataShared allocWithZone: NSDefaultMallocZone()]
initWithBytes: bytes length: length] autorelease];
d = [NSDataShared allocWithZone: NSDefaultMallocZone()];
d = [d initWithBytes: bytes length: length];
#else
return [[[dataMalloc allocWithZone: NSDefaultMallocZone()]
initWithBytes: bytes length: length] autorelease];
d = [dataMalloc allocWithZone: NSDefaultMallocZone()];
d = [d initWithBytes: bytes length: length];
#endif
return AUTORELEASE(d);
}
+ (id) dataWithStaticBytes: (const void*)bytes length: (unsigned)length
{
return [[[NSDataStatic allocWithZone: NSDefaultMallocZone()]
initWithBytesNoCopy: (void*)bytes length: length] autorelease];
NSDataStatic *d;
d = [NSDataStatic allocWithZone: NSDefaultMallocZone()];
d = [d initWithBytesNoCopy: (void*)bytes length: length];
return AUTORELEASE(d);
}
- (id) initWithBytesNoCopy: (void*)bytes
@ -1104,52 +1134,76 @@ failure:
+ (id) data
{
return [[[mutableDataMalloc allocWithZone: NSDefaultMallocZone()]
initWithCapacity: 0] autorelease];
NSMutableData *d;
d = [mutableDataMalloc allocWithZone: NSDefaultMallocZone()];
d = [d initWithCapacity: 0];
return AUTORELEASE(d);
}
+ (id) dataWithBytes: (const void*)bytes
length: (unsigned)length
{
return [[[mutableDataMalloc allocWithZone: NSDefaultMallocZone()]
initWithBytes: bytes length: length] autorelease];
NSData *d;
d = [mutableDataMalloc allocWithZone: NSDefaultMallocZone()];
d = [d initWithBytes: bytes length: length];
return AUTORELEASE(d);
}
+ (id) dataWithBytesNoCopy: (void*)bytes
length: (unsigned)length
{
return [[[mutableDataMalloc allocWithZone: NSDefaultMallocZone()]
initWithBytesNoCopy: bytes length: length] autorelease];
NSData *d;
d = [mutableDataMalloc allocWithZone: NSDefaultMallocZone()];
d = [d initWithBytesNoCopy: bytes length: length];
return AUTORELEASE(d);
}
+ (id) dataWithCapacity: (unsigned)numBytes
{
return [[[mutableDataMalloc allocWithZone: NSDefaultMallocZone()]
initWithCapacity: numBytes] autorelease];
NSMutableData *d;
d = [mutableDataMalloc allocWithZone: NSDefaultMallocZone()];
d = [d initWithCapacity: numBytes];
return AUTORELEASE(d);
}
+ (id) dataWithContentsOfFile: (NSString*)path
{
return [[[mutableDataMalloc allocWithZone: NSDefaultMallocZone()]
initWithContentsOfFile: path] autorelease];
NSData *d;
d = [mutableDataMalloc allocWithZone: NSDefaultMallocZone()];
d = [d initWithContentsOfFile: path];
return AUTORELEASE(d);
}
+ (id) dataWithContentsOfMappedFile: (NSString*)path
{
return [[[mutableDataMalloc allocWithZone: NSDefaultMallocZone()]
initWithContentsOfFile: path] autorelease];
NSData *d;
d = [mutableDataMalloc allocWithZone: NSDefaultMallocZone()];
d = [d initWithContentsOfMappedFile: path];
return AUTORELEASE(d);
}
+ (id) dataWithData: (NSData*)data
{
return [[[mutableDataMalloc allocWithZone: NSDefaultMallocZone()]
initWithBytes: [data bytes] length: [data length]] autorelease];
NSData *d;
d = [mutableDataMalloc allocWithZone: NSDefaultMallocZone()];
d = [d initWithBytes: [data bytes] length: [data length]];
return AUTORELEASE(d);
}
+ (id) dataWithLength: (unsigned)length
{
return [[[mutableDataMalloc allocWithZone: NSDefaultMallocZone()]
initWithLength: length] autorelease];
NSMutableData *d;
d = [mutableDataMalloc allocWithZone: NSDefaultMallocZone()];
d = [d initWithLength: length];
return AUTORELEASE(d);
}
- (const void*) bytes
@ -1463,8 +1517,11 @@ failure:
+ (id) dataWithShmID: (int)anID length: (unsigned)length
{
#if HAVE_SHMCTL
return [[[NSMutableDataShared allocWithZone: NSDefaultMallocZone()]
initWithShmID: anID length: length] autorelease];
NSDataShared *d;
d = [NSMutableDataShared allocWithZone: NSDefaultMallocZone()];
d = [d initWithShmID: anID length: length];
return AUTORELEASE(d);
#else
NSLog(@"[NSMutableData -dataWithSmdID:length:] no shared memory support");
return nil;
@ -1473,13 +1530,16 @@ failure:
+ (id) dataWithSharedBytes: (const void*)bytes length: (unsigned)length
{
NSData *d;
#if HAVE_SHMCTL
return [[[NSMutableDataShared allocWithZone: NSDefaultMallocZone()]
initWithBytes: bytes length: length] autorelease];
d = [NSMutableDataShared allocWithZone: NSDefaultMallocZone()];
d = [d initWithBytes: bytes length: length];
#else
return [[[mutableDataMalloc allocWithZone: NSDefaultMallocZone()]
initWithBytes: bytes length: length] autorelease];
d = [mutableDataMalloc allocWithZone: NSDefaultMallocZone()];
d = [d initWithBytes: bytes length: length];
#endif
return AUTORELEASE(d);
}
- (unsigned) capacity
@ -1564,12 +1624,12 @@ failure:
- (id) copy
{
return [self retain];
return RETAIN(self);
}
- (id) copyWithZone: (NSZone*)z
{
return [self retain];
return RETAIN(self);
}
- (id) mutableCopy
@ -1714,10 +1774,12 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
NSZone *z = [self zone];
*(char**)data = (char*)NSZoneMalloc(z, len+1);
#if !GS_WITH_GC
[[[dataMalloc allocWithZone: z]
initWithBytesNoCopy: *(void**)data
length: len+1
fromZone: z] autorelease];
#endif
}
getBytes(*(void**)data, bytes, len, length, cursor);
(*(char**)data)[len] = '\0';
@ -1779,10 +1841,12 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
NSZone *z = [self zone];
*(char**)data = (char*)NSZoneMalloc(z, len);
#if !GS_WITH_GC
[[[dataMalloc allocWithZone: z]
initWithBytesNoCopy: *(void**)data
length: len
fromZone: z] autorelease];
#endif
[self deserializeDataAt: *(char**)data
ofObjCType: type
atCursor: cursor
@ -1995,7 +2059,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
- (id) copy
{
if (NSShouldRetainWithZone(self, NSDefaultMallocZone()))
return [self retain];
return RETAIN(self);
else
return [[dataMalloc allocWithZone: NSDefaultMallocZone()]
initWithBytes: bytes length: length];
@ -2004,7 +2068,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
- (id) copyWithZone: (NSZone*)z
{
if (NSShouldRetainWithZone(self, z))
return [self retain];
return RETAIN(self);
else
return [[dataMalloc allocWithZone: z]
initWithBytes: bytes length: length];
@ -2031,7 +2095,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
if (tmp == 0)
{
NSLog(@"[NSDataMalloc -initWithBytes:length:] unable to allocate %lu bytes", bufferSize);
[self release];
RELEASE(self);
return nil;
}
else
@ -2065,7 +2129,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
data = [[NSDataStatic allocWithZone: NSDefaultMallocZone()]
initWithBytesNoCopy: aBuffer length: bufferSize];
[self release];
RELEASE(self);
return data;
}
@ -2092,7 +2156,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
if (b == 0)
{
NSLog(@"[NSDataMalloc -initWithCoder:] unable to get %lu bytes", l);
[self release];
RELEASE(self);
return nil;
}
[aCoder decodeArrayOfObjCType: @encode(unsigned char) count: l at: b];
@ -2109,7 +2173,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
zone = [self zone];
if (readContentsOfFile(path, &bytes, &length, zone) == NO)
{
[self release];
RELEASE(self);
self = nil;
}
return self;
@ -2120,7 +2184,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
#if HAVE_MMAP
NSZone *z = [self zone];
[self release];
RELEASE(self);
self = [NSDataMappedFile allocWithZone: z];
return [self initWithContentsOfMappedFile: path];
#else
@ -2137,7 +2201,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
if ([anObject isKindOfClass: [NSData class]] == NO)
{
NSLog(@"-initWithData: passed a non-data object");
[self release];
RELEASE(self);
return nil;
}
return [self initWithBytes: [anObject bytes] length: [anObject length]];
@ -2190,7 +2254,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
if (fd < 0)
{
NSLog(@"[NSDataMappedFile -initWithContentsOfMappedFile:] unable to open %s - %s", thePath, strerror(errno));
[self release];
RELEASE(self);
return nil;
}
/* Find size of file to be mapped. */
@ -2199,7 +2263,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
{
NSLog(@"[NSDataMappedFile -initWithContentsOfMappedFile:] unable to seek to eof %s - %s", thePath, strerror(errno));
close(fd);
[self release];
RELEASE(self);
return nil;
}
/* Position at start of file. */
@ -2207,7 +2271,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
{
NSLog(@"[NSDataMappedFile -initWithContentsOfMappedFile:] unable to seek to sof %s - %s", thePath, strerror(errno));
close(fd);
[self release];
RELEASE(self);
return nil;
}
bytes = mmap(0, length, PROT_READ, MAP_SHARED, fd, 0);
@ -2215,7 +2279,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
{
NSLog(@"[NSDataMappedFile -initWithContentsOfMappedFile:] mapping failed for %s - %s", thePath, strerror(errno));
close(fd);
[self release];
RELEASE(self);
self = [dataMalloc allocWithZone: NSDefaultMallocZone()];
self = [self initWithContentsOfFile: path];
}
@ -2270,7 +2334,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
{
NSLog(@"[-initWithBytes:length:] shared mem get failed for %u - %s",
bufferSize, strerror(errno));
[self release];
RELEASE(self);
self = [dataMalloc allocWithZone: NSDefaultMallocZone()];
return [self initWithBytes: aBuffer length: bufferSize];
}
@ -2281,7 +2345,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
NSLog(@"[-initWithBytes:length:] shared mem attach failed for %u - %s",
bufferSize, strerror(errno));
bytes = 0;
[self release];
RELEASE(self);
self = [dataMalloc allocWithZone: NSDefaultMallocZone()];
return [self initWithBytes: aBuffer length: bufferSize];
}
@ -2298,13 +2362,13 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
if (shmctl(shmid, IPC_STAT, &buf) < 0)
{
NSLog(@"[NSDataShared -initWithShmID:length:] shared memory control failed - %s", strerror(errno));
[self release]; /* Unable to access memory. */
RELEASE(self); /* Unable to access memory. */
return nil;
}
if (buf.shm_segsz < bufferSize)
{
NSLog(@"[NSDataShared -initWithShmID:length:] shared memory segment too small");
[self release]; /* Memory segment too small. */
RELEASE(self); /* Memory segment too small. */
return nil;
}
bytes = shmat(shmid, 0, 0);
@ -2313,7 +2377,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
NSLog(@"[NSDataShared -initWithShmID:length:] shared memory attach failed - %s",
strerror(errno));
bytes = 0;
[self release]; /* Unable to attach to memory. */
RELEASE(self); /* Unable to attach to memory. */
return nil;
}
length = bufferSize;
@ -2435,7 +2499,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
bytes = NSZoneMalloc(zone, size);
if (bytes == 0) {
NSLog(@"[NSMutableDataMalloc -initWithCapacity:] out of memory for %u bytes - %s", size, strerror(errno));
[self release];
RELEASE(self);
return nil;
}
}
@ -2460,7 +2524,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
if (bytes == 0)
{
NSLog(@"[NSMutableDataMalloc -initWithCoder:] unable to allocate %lu bytes", l);
[self release];
RELEASE(self);
return nil;
}
[aCoder decodeArrayOfObjCType: @encode(unsigned char)
@ -2485,7 +2549,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
{
self = [self initWithCapacity: 0];
if (readContentsOfFile(path, &bytes, &length, zone) == NO) {
[self release];
RELEASE(self);
self = nil;
}
else {
@ -2506,7 +2570,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
}
if ([anObject isKindOfClass: [NSData class]] == NO) {
NSLog(@"-initWithData: passed a non-data object");
[self release];
RELEASE(self);
return nil;
}
return [self initWithBytes: [anObject bytes] length: [anObject length]];
@ -2933,7 +2997,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
if (shmid == -1) /* Created memory? */
{
NSLog(@"[NSMutableDataShared -initWithCapacity:] shared memory get failed for %u - %s", bufferSize, strerror(errno));
[self release];
RELEASE(self);
self = [mutableDataMalloc allocWithZone: NSDefaultMallocZone()];
return [self initWithCapacity: bufferSize];
}
@ -2944,7 +3008,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
{
NSLog(@"[NSMutableDataShared -initWithCapacity:] shared memory attach failed for %u - %s", bufferSize, strerror(e));
bytes = 0;
[self release];
RELEASE(self);
self = [mutableDataMalloc allocWithZone: NSDefaultMallocZone()];
return [self initWithCapacity: bufferSize];
}
@ -2962,13 +3026,13 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
if (shmctl(shmid, IPC_STAT, &buf) < 0)
{
NSLog(@"[NSMutableDataShared -initWithShmID:length:] shared memory control failed - %s", strerror(errno));
[self release]; /* Unable to access memory. */
RELEASE(self); /* Unable to access memory. */
return nil;
}
if (buf.shm_segsz < bufferSize)
{
NSLog(@"[NSMutableDataShared -initWithShmID:length:] shared memory segment too small");
[self release]; /* Memory segment too small. */
RELEASE(self); /* Memory segment too small. */
return nil;
}
bytes = shmat(shmid, 0, 0);
@ -2976,7 +3040,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
{
NSLog(@"[NSMutableDataShared -initWithShmID:length:] shared memory attach failed - %s", strerror(errno));
bytes = 0;
[self release]; /* Unable to attach to memory. */
RELEASE(self); /* Unable to attach to memory. */
return nil;
}
length = bufferSize;

View file

@ -45,7 +45,7 @@
{
NSDateFormatter *other = (id)NSCopyObject(self, 0, zone);
[other->dateFormat retain];
RETAIN(other->dateFormat);
return other;
}
@ -54,6 +54,12 @@
return dateFormat;
}
- (void) dealloc
{
RELEASE(dateFormat);
[super dealloc];
}
- (NSString*) editingStringForObjectValue: (id)anObject
{
return [self stringForObjectValue: anObject];

View file

@ -117,12 +117,12 @@ static Class NSMutableDictionary_concrete_class;
return nil;
}
- copyWithZone: (NSZone*)z
- (id) copyWithZone: (NSZone*)z
{
return [self retain];
return RETAIN(self);
}
- mutableCopyWithZone: (NSZone*)z
- (id) mutableCopyWithZone: (NSZone*)z
{
return [[[[self class] _mutableConcreteClass] allocWithZone: z]
initWithDictionary: self];
@ -142,23 +142,23 @@ static Class NSMutableDictionary_concrete_class;
@implementation NSDictionaryNonCore
+ dictionary
+ (id) dictionary
{
return [[[self allocWithZone: NSDefaultMallocZone()] init] autorelease];
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()] init]);
}
+ dictionaryWithDictionary: (NSDictionary*)otherDictionary
+ (id) dictionaryWithDictionary: (NSDictionary*)otherDictionary
{
return [[[self allocWithZone: NSDefaultMallocZone()]
initWithDictionary: otherDictionary] autorelease];
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
initWithDictionary: otherDictionary]);
}
+ dictionaryWithObjects: (id*)objects
forKeys: (id*)keys
count: (unsigned)count
+ (id) dictionaryWithObjects: (id*)objects
forKeys: (id*)keys
count: (unsigned)count
{
return [[[self allocWithZone: NSDefaultMallocZone()]
initWithObjects: objects forKeys: keys count: count] autorelease];
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
initWithObjects: objects forKeys: keys count: count]);
}
- (unsigned) hash
@ -273,8 +273,8 @@ static Class NSMutableDictionary_concrete_class;
}
}
NSAssert (argi % 2 == 0, NSInvalidArgumentException);
d = [[[self allocWithZone: NSDefaultMallocZone()]
initWithObjects: objects forKeys: keys count: num_pairs] autorelease];
d = AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
initWithObjects: objects forKeys: keys count: num_pairs]);
OBJC_FREE(objects);
OBJC_FREE(keys);
return d;
@ -283,20 +283,20 @@ static Class NSMutableDictionary_concrete_class;
return [self dictionary];
}
+ dictionaryWithObjects: (NSArray*)objects forKeys: (NSArray*)keys
+ (id) dictionaryWithObjects: (NSArray*)objects forKeys: (NSArray*)keys
{
return [[[self allocWithZone: NSDefaultMallocZone()]
initWithObjects: objects forKeys: keys] autorelease];
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
initWithObjects: objects forKeys: keys]);
}
+ dictionaryWithObject: (id)object forKey: (id)key
+ (id) dictionaryWithObject: (id)object forKey: (id)key
{
return [[[self allocWithZone: NSDefaultMallocZone()]
initWithObjects: &object forKeys: &key count: 1] autorelease];
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
initWithObjects: &object forKeys: &key count: 1]);
}
/* Override superclass's designated initializer */
- init
- (id) init
{
return [self initWithObjects: NULL forKeys: NULL count: 0];
}
@ -323,10 +323,12 @@ static Class NSMutableDictionary_concrete_class;
i++;
}
self = [self initWithObjects: os forKeys: ks count: i];
#if !GS_WITH_GC
while (i > 0)
{
[os[--i] release];
}
#endif
return self;
}
else
@ -360,7 +362,7 @@ static Class NSMutableDictionary_concrete_class;
result = nil;
}
NS_ENDHANDLER
[myString release];
RELEASE(myString);
if ([result isKindOfClass: [NSDictionary class]])
{
[self initWithDictionary: result];
@ -368,14 +370,14 @@ static Class NSMutableDictionary_concrete_class;
}
}
NSLog(@"Contents of file does not contain a dictionary");
[self release];
RELEASE(self);
return nil;
}
+ dictionaryWithContentsOfFile: (NSString *)path
+ (id) dictionaryWithContentsOfFile: (NSString *)path
{
return [[[self allocWithZone: NSDefaultMallocZone()]
initWithContentsOfFile: path] autorelease];
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
initWithContentsOfFile: path]);
}
- (BOOL) isEqual: other
@ -418,8 +420,8 @@ static Class NSMutableDictionary_concrete_class;
NSAssert (k[i], NSInternalInconsistencyException);
}
NSAssert (![e nextObject], NSInternalInconsistencyException);
return [[[NSArray allocWithZone: NSDefaultMallocZone()]
initWithObjects: k count: c] autorelease];
return AUTORELEASE([[NSArray allocWithZone: NSDefaultMallocZone()]
initWithObjects: k count: c]);
}
- (NSArray*) allValues
@ -434,8 +436,8 @@ static Class NSMutableDictionary_concrete_class;
NSAssert (k[i], NSInternalInconsistencyException);
}
NSAssert (![e nextObject], NSInternalInconsistencyException);
return [[[NSArray allocWithZone: NSDefaultMallocZone()]
initWithObjects: k count: c] autorelease];
return AUTORELEASE([[NSArray allocWithZone: NSDefaultMallocZone()]
initWithObjects: k count: c]);
}
- (NSArray*) allKeysForObject: anObject
@ -449,8 +451,8 @@ static Class NSMutableDictionary_concrete_class;
a[c++] = k;
if (c == 0)
return nil;
return [[[NSArray allocWithZone: NSDefaultMallocZone()]
initWithObjects: a count: c] autorelease];
return AUTORELEASE([[NSArray allocWithZone: NSDefaultMallocZone()]
initWithObjects: a count: c]);
}
struct foo { NSDictionary *d; SEL s; IMP i; };
@ -509,7 +511,7 @@ compareIt(id o1, id o2, void* context)
NSEnumerator *enumerator;
id key;
result = [[[NSGMutableCString alloc] initWithCapacity: 1024] autorelease];
result = AUTORELEASE([[NSGMutableCString alloc] initWithCapacity: 1024]);
enumerator = [self keyEnumerator];
while ((key = [enumerator nextObject]) != nil)
{
@ -539,8 +541,8 @@ compareIt(id o1, id o2, void* context)
{
NSMutableString *result;
result = [[[NSGMutableCString alloc] initWithCapacity: 20*[self count]]
autorelease];
result = AUTORELEASE([[NSGMutableCString alloc] initWithCapacity:
20*[self count]]);
[self descriptionWithLocale: locale
indent: level
to: (id<GNUDescriptionDestination>)result];
@ -690,10 +692,12 @@ static NSString *indentStrings[] = {
initWithObjects: objects
forKeys: keys
count: count];
#if !GS_WITH_GC
while (i > 0)
{
[objects[--i] release];
}
#endif
return newDictionary;
}
@ -718,16 +722,16 @@ static NSString *indentStrings[] = {
@implementation NSMutableDictionaryNonCore
+ dictionaryWithCapacity: (unsigned)numItems
+ (id) dictionaryWithCapacity: (unsigned)numItems
{
return [[[self allocWithZone: NSDefaultMallocZone()]
initWithCapacity: numItems] autorelease];
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
initWithCapacity: numItems]);
}
/* Override superclass's designated initializer */
- initWithObjects: (id*)objects
forKeys: (id*)keys
count: (unsigned)count
- (id) initWithObjects: (id*)objects
forKeys: (id*)keys
count: (unsigned)count
{
[self initWithCapacity: count];
while (count--)

View file

@ -35,7 +35,7 @@
+ (NSDistributedLock*) lockWithPath: (NSString*)aPath
{
return [[[self alloc] initWithPath: aPath] autorelease];
return AUTORELEASE([[self alloc] initWithPath: aPath]);
}
- (void) breakLock
@ -47,14 +47,14 @@
[NSException raise: NSGenericException
format: @"Failed to remove lock directory '%@' - %s",
lockPath, strerror(errno)];
[lockTime release];
RELEASE(lockTime);
lockTime = nil;
}
- (void) dealloc
{
[lockPath release];
[lockTime release];
RELEASE(lockPath);
RELEASE(lockTime);
[super dealloc];
}
@ -72,27 +72,27 @@
if ([fileManager fileExistsAtPath: lockDir isDirectory: &isDirectory] == NO)
{
NSLog(@"part of the path to the lock file '%@' is missing\n", lockPath);
[self release];
RELEASE(self);
return nil;
}
if (isDirectory == NO)
{
NSLog(@"part of the path to the lock file '%@' is not a directory\n",
lockPath);
[self release];
RELEASE(self);
return nil;
}
if ([fileManager isWritableFileAtPath: lockDir] == NO)
{
NSLog(@"parent directory of lock file '%@' is not writable\n", lockPath);
[self release];
RELEASE(self);
return nil;
}
if ([fileManager isExecutableFileAtPath: lockDir] == NO)
{
NSLog(@"parent directory of lock file '%@' is not accessible\n",
lockPath);
[self release];
RELEASE(self);
return nil;
}
return self;
@ -146,7 +146,7 @@
if (locked == NO)
{
[lockTime release];
RELEASE(lockTime);
lockTime = nil;
return NO;
}
@ -154,8 +154,8 @@
{
attributes = [fileManager fileAttributesAtPath: lockPath
traverseLink: YES];
[lockTime release];
lockTime = [[attributes objectForKey: NSFileModificationDate] retain];
RELEASE(lockTime);
lockTime = RETAIN([attributes objectForKey: NSFileModificationDate]);
return YES;
}
}
@ -185,7 +185,7 @@
else
NSLog(@"lock '%@' already broken and in use again\n", lockPath);
[lockTime release];
RELEASE(lockTime);
lockTime = nil;
}

View file

@ -103,7 +103,7 @@ static NSDistributedNotificationCenter *defCenter = nil;
{
[remote unregisterClient: (id<GDNCClient>)self];
}
[remote release];
RELEASE(remote);
[super dealloc];
}
@ -313,9 +313,10 @@ static NSDistributedNotificationCenter *defCenter = nil;
/*
* Connect to the NSDistributedNotificationCenter for this host.
*/
remote = [NSConnection rootProxyForConnectionWithRegisteredName:
GDNC_SERVICE host: @""];
if ((remote = [remote retain]) != nil)
remote = RETAIN([NSConnection rootProxyForConnectionWithRegisteredName:
GDNC_SERVICE host: @""]);
if (remote != nil)
{
NSConnection *c = [remote connectionForProxy];
Protocol *p = @protocol(GDNCProtocol);
@ -382,7 +383,7 @@ NSLog(@"Connection to GDNC server established.\n");
object: connection];
NSAssert(connection == [remote connectionForProxy],
NSInternalInconsistencyException);
[remote release];
RELEASE(remote);
remote = nil;
}

View file

@ -69,12 +69,14 @@
{
if (_contents_array)
{
#if !GS_WITH_GC
unsigned i;
for (i = 0; i < _count; i++)
{
[_contents_array[i] release];
}
#endif
NSZoneFree([self zone], _contents_array);
}
[super dealloc];
@ -90,16 +92,16 @@
_contents_array = NSZoneMalloc([self zone], sizeof(id)*count);
if (_contents_array == 0)
{
[self release];
RELEASE(self);
return nil;
}
for (i = 0; i < count; i++)
{
if ((_contents_array[i] = [objects[i] retain]) == nil)
if ((_contents_array[i] = RETAIN(objects[i])) == nil)
{
_count = i;
[self release];
RELEASE(self);
[NSException raise: NSInvalidArgumentException
format: @"Tried to add nil"];
}
@ -318,10 +320,10 @@
for (i = 0; i < count; i++)
{
if ((_contents_array[i] = [objects[i] retain]) == nil)
if ((_contents_array[i] = RETAIN(objects[i])) == nil)
{
_count = i;
[self release];
RELEASE(self);
[NSException raise: NSInvalidArgumentException
format: @"Tried to add nil"];
}
@ -371,7 +373,7 @@
*/
_contents_array[index] = nil;
_count++;
_contents_array[index] = [anObject retain];
_contents_array[index] = RETAIN(anObject);
}
- (void) addObject: (id)anObject
@ -396,7 +398,7 @@
_capacity += _grow_factor;
_grow_factor = _capacity/2;
}
_contents_array[_count] = [anObject retain];
_contents_array[_count] = RETAIN(anObject);
_count++; /* Do this AFTER we have retained the object. */
}
@ -408,7 +410,7 @@
format: @"Trying to remove from an empty array."];
}
_count--;
[_contents_array[_count] release];
RELEASE(_contents_array[_count]);
}
- (void) removeObjectAtIndex: (unsigned)index
@ -428,7 +430,7 @@
_contents_array[index] = _contents_array[index+1];
index++;
}
[obj release]; /* Adjust array BEFORE releasing object. */
RELEASE(obj); /* Adjust array BEFORE releasing object. */
}
- (void) replaceObjectAtIndex: (unsigned)index withObject: (id)anObject
@ -440,15 +442,15 @@
[NSException raise: NSRangeException format:
@"in replaceObjectAtIndex:withObject:, index %d is out of range",
index];
}
}
/*
* Swap objects in order so that there is always a valid object in the
* array in case a retain or release causes an exception.
*/
obj = _contents_array[index];
[anObject retain];
RETAIN(anObject);
_contents_array[index] = anObject;
[obj release];
RELEASE(anObject);
}
- (void) sortUsingFunction: (int(*)(id,id,void*))compare

View file

@ -163,7 +163,7 @@ static IMP msInitImp; /* designated initialiser for mutable */
id a = [[NSGString allocWithZone: z] initWithCharactersNoCopy: chars
length: length
fromZone: z];
[self release];
RELEASE(self);
return a;
}
@ -175,7 +175,7 @@ static IMP msInitImp; /* designated initialiser for mutable */
id a = [[NSGString allocWithZone: z] initWithCharactersNoCopy: chars
length: length
freeWhenDone: flag];
[self release];
RELEASE(self);
return a;
}
@ -253,7 +253,7 @@ static IMP msInitImp; /* designated initialiser for mutable */
}
else
{
return [self retain];
return RETAIN(self);
}
}
@ -284,7 +284,7 @@ static IMP msInitImp; /* designated initialiser for mutable */
}
else
{
return [self retain];
return RETAIN(self);
}
}
@ -668,7 +668,7 @@ static IMP msInitImp; /* designated initialiser for mutable */
result = [[_fastCls._NSGCString allocWithZone: z]
initWithCStringNoCopy: buf length: length fromZone: z];
[output appendString: result];
[result release];
RELEASE(result);
}
}
else
@ -883,7 +883,7 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
id a = [[NSGMutableString allocWithZone: z] initWithCharactersNoCopy: chars
length: length
fromZone: z];
[self release];
RELEASE(self);
return a;
}
@ -895,7 +895,7 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
id a = [[NSGMutableString allocWithZone: z] initWithCharactersNoCopy: chars
length: length
freeWhenDone: flag];
[self release];
RELEASE(self);
return a;
}
@ -1164,7 +1164,7 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
return _contents_chars;
}
- retain
- (id) retain
{
return self;
}
@ -1174,7 +1174,7 @@ stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
return;
}
- autorelease
- (id) autorelease
{
return self;
}

View file

@ -62,7 +62,7 @@
self = [super init];
if (self)
{
set = [(NSGCountedSet*)d retain];
set = RETAIN((NSGCountedSet*)d);
node = set->map.firstNode;
}
return self;
@ -82,7 +82,7 @@
- (void) dealloc
{
[set release];
RELEASE(set);
[super dealloc];
}
@ -170,7 +170,7 @@
if (objs[i] == nil)
{
[self autorelease];
AUTORELEASE(self);
[NSException raise: NSInvalidArgumentException
format: @"Tried to init counted set with nil value"];
}
@ -248,8 +248,8 @@
- (NSEnumerator*) objectEnumerator
{
return [[[NSGCountedSetEnumerator allocWithZone: NSDefaultMallocZone()]
initWithSet: self] autorelease];
return AUTORELEASE([[NSGCountedSetEnumerator allocWithZone:
NSDefaultMallocZone()] initWithSet: self]);
}
- (void) removeObject: (NSObject*)anObject

View file

@ -209,13 +209,13 @@ myEqual(id self, id other)
if (keys[i] == nil)
{
[self autorelease];
AUTORELEASE(self);
[NSException raise: NSInvalidArgumentException
format: @"Tried to init dictionary with nil key"];
}
if (objs[i] == nil)
{
[self autorelease];
AUTORELEASE(self);
[NSException raise: NSInvalidArgumentException
format: @"Tried to init dictionary with nil value"];
}
@ -223,8 +223,8 @@ myEqual(id self, id other)
node = GSIMapNodeForKey(&map, (GSIMapKey)keys[i]);
if (node)
{
[objs[i] retain];
[node->value.obj release];
RETAIN(objs[i]);
RELEASE(node->value.obj);
node->value.obj = objs[i];
}
else
@ -256,7 +256,7 @@ myEqual(id self, id other)
k = [k copyWithZone: z];
if (k == nil)
{
[self autorelease];
AUTORELEASE(self);
[NSException raise: NSInvalidArgumentException
format: @"Tried to init dictionary with nil key"];
}
@ -266,11 +266,11 @@ myEqual(id self, id other)
}
else
{
o = [o retain];
o = RETAIN(o);
}
if (o == nil)
{
[self autorelease];
AUTORELEASE(self);
[NSException raise: NSInvalidArgumentException
format: @"Tried to init dictionary with nil value"];
}
@ -278,7 +278,7 @@ myEqual(id self, id other)
node = GSIMapNodeForKey(&map, (GSIMapKey)k);
if (node)
{
[node->value.obj release];
RELEASE(node->value.obj);
node->value.obj = o;
}
else
@ -291,14 +291,14 @@ myEqual(id self, id other)
- (NSEnumerator*) keyEnumerator
{
return [[[NSGDictionaryKeyEnumerator allocWithZone: NSDefaultMallocZone()]
initWithDictionary: self] autorelease];
return AUTORELEASE([[NSGDictionaryKeyEnumerator allocWithZone:
NSDefaultMallocZone()] initWithDictionary: self]);
}
- (NSEnumerator*) objectEnumerator
{
return [[[NSGDictionaryObjectEnumerator allocWithZone: NSDefaultMallocZone()]
initWithDictionary: self] autorelease];
return AUTORELEASE([[NSGDictionaryObjectEnumerator allocWithZone:
NSDefaultMallocZone()] initWithDictionary: self]);
}
- (id) objectForKey: aKey
@ -352,8 +352,8 @@ myEqual(id self, id other)
node = GSIMapNodeForKey(&map, (GSIMapKey)aKey);
if (node)
{
[anObject retain];
[node->value.obj release];
RETAIN(anObject);
RELEASE(node->value.obj);
node->value.obj = anObject;
}
else
@ -382,12 +382,12 @@ myEqual(id self, id other)
- (id) initWithDictionary: (NSDictionary*)d
{
[super init];
dictionary = (NSGDictionary*)[d retain];
dictionary = (NSGDictionary*)RETAIN(d);
node = dictionary->map.firstNode;
return self;
}
- nextObject
- (id) nextObject
{
GSIMapNode old = node;
@ -401,7 +401,7 @@ myEqual(id self, id other)
- (void) dealloc
{
[dictionary release];
RELEASE(dictionary);
[super dealloc];
}
@ -409,7 +409,7 @@ myEqual(id self, id other)
@implementation NSGDictionaryObjectEnumerator
- nextObject
- (id) nextObject
{
GSIMapNode old = node;

View file

@ -65,7 +65,7 @@
- initWithSet: (NSSet*)d
{
[super init];
set = [(NSGSet*)d retain];
set = (NSGSet*)RETAIN(d);
node = set->map.firstNode;
return self;
}
@ -84,7 +84,7 @@
- (void) dealloc
{
[set release];
RELEASE(set);
[super dealloc];
}
@ -164,7 +164,7 @@
if (objs[i] == nil)
{
[self autorelease];
AUTORELEASE(self);
[NSException raise: NSInvalidArgumentException
format: @"Tried to init set with nil value"];
}
@ -193,7 +193,7 @@
- (NSEnumerator*) objectEnumerator
{
return [[[NSGSetEnumerator alloc] initWithSet: self] autorelease];
return AUTORELEASE([[NSGSetEnumerator alloc] initWithSet: self]);
}
@end

View file

@ -47,38 +47,39 @@ static BOOL _hostCacheEnabled = NO;
static NSMutableDictionary *_hostCache = nil;
@interface NSHost (Private)
+ (NSHost *)_hostWithHostEntry:(struct hostent *)entry;
+ (NSHost *)_hostWithHostEntry:(struct hostent *)entry name:name;
- _initWithHostEntry:(struct hostent *)entry name:name;
+ (NSHost *)_hostWithHostEntry: (struct hostent *)entry;
+ (NSHost *)_hostWithHostEntry: (struct hostent *)entry name: name;
- _initWithHostEntry: (struct hostent *)entry name: name;
@end
@implementation NSHost (Private)
+ (NSHost *)_hostWithHostEntry:(struct hostent *)entry
+ (NSHost *)_hostWithHostEntry: (struct hostent *)entry
{
if (!entry)
return nil;
return [[self class] _hostWithHostEntry:entry
name:[NSString stringWithCString:entry->h_name]];
return [[self class] _hostWithHostEntry: entry
name: [NSString stringWithCString: entry->h_name]];
}
+ (NSHost *)_hostWithHostEntry:(struct hostent *)entry name:name
+ (NSHost *)_hostWithHostEntry: (struct hostent *)entry name: name
{
NSHost *res = nil;
[_hostCacheLock lock];
if (_hostCacheEnabled == YES)
{
res = [_hostCache objectForKey:name];
res = [_hostCache objectForKey: name];
}
[_hostCacheLock unlock];
return (res != nil) ? res : [[[[self class] alloc]
_initWithHostEntry:entry name:name] autorelease];
return (res != nil) ? res
: AUTORELEASE([[[self class] alloc]
_initWithHostEntry: entry name: name]);
}
- _initWithHostEntry:(struct hostent *)entry name:name
- _initWithHostEntry: (struct hostent *)entry name: name
{
int i;
char *ptr;
@ -92,21 +93,21 @@ static NSMutableDictionary *_hostCache = nil;
return nil;
}
names = [[NSMutableArray array] retain];
addresses = [[NSMutableArray array] retain];
names = RETAIN([NSMutableArray array]);
addresses = RETAIN([NSMutableArray array]);
[names addObject:name];
h_name = [NSString stringWithCString:entry->h_name];
[names addObject: name];
h_name = [NSString stringWithCString: entry->h_name];
if (![h_name isEqual:name])
if (![h_name isEqual: name])
{
[names addObject:h_name];
[names addObject: h_name];
}
for (i = 0, ptr = entry->h_aliases[0]; ptr != NULL; i++,
ptr = entry->h_aliases[i])
{
[names addObject:[NSString stringWithCString:ptr]];
[names addObject: [NSString stringWithCString: ptr]];
}
for (i = 0, ptr = entry->h_addr_list[0]; ptr != NULL; i++,
@ -114,14 +115,14 @@ static NSMutableDictionary *_hostCache = nil;
{
memcpy((void *)&in.s_addr, (const void *)ptr,
entry->h_length);
[addresses addObject:[NSString
stringWithCString:(char*)inet_ntoa(in)]];
[addresses addObject: [NSString
stringWithCString: (char*)inet_ntoa(in)]];
}
[_hostCacheLock lock];
if (_hostCacheEnabled == YES)
{
[_hostCache setObject:self forKey:name];
[_hostCache setObject: self forKey: name];
}
[_hostCacheLock unlock];
@ -163,11 +164,11 @@ static NSMutableDictionary *_hostCache = nil;
}
return [self _hostWithHostEntry:h name:[NSString
stringWithCString:name]];
return [self _hostWithHostEntry: h name: [NSString
stringWithCString: name]];
}
+ (NSHost *)hostWithName:(NSString *)name
+ (NSHost *)hostWithName: (NSString *)name
{
struct hostent *h;
@ -179,11 +180,11 @@ static NSMutableDictionary *_hostCache = nil;
h = gethostbyname((char *)[name cString]);
return [self _hostWithHostEntry:h name:name];
return [self _hostWithHostEntry: h name: name];
}
+ (NSHost *)hostWithAddress:(NSString *)address
+ (NSHost *)hostWithAddress: (NSString *)address
{
struct hostent *h;
struct in_addr hostaddr;
@ -201,10 +202,10 @@ static NSMutableDictionary *_hostCache = nil;
}
h = gethostbyaddr((char *)&hostaddr, sizeof(hostaddr), AF_INET);
return [self _hostWithHostEntry:h];
return [self _hostWithHostEntry: h];
}
+ (void)setHostCacheEnabled:(BOOL)flag
+ (void)setHostCacheEnabled: (BOOL)flag
{
[_hostCacheLock lock];
_hostCacheEnabled = flag;
@ -234,7 +235,7 @@ static NSMutableDictionary *_hostCache = nil;
{
return [self class];
}
- replacementObjectForPortCoder:(NSPortCoder*)aCoder
- replacementObjectForPortCoder: (NSPortCoder*)aCoder
{
return self;
}
@ -271,8 +272,8 @@ static NSMutableDictionary *_hostCache = nil;
/*
* The OpenStep spec says that [-hash] must be the same for any two
* objects that [-isEqual:] returns YES for. We have a problem in
* that [-isEqualToHost:] is specified to return YES if any name or
* objects that [-isEqual: ] returns YES for. We have a problem in
* that [-isEqualToHost: ] is specified to return YES if any name or
* address part of two hosts is the same. That means we can't
* reasonably calculate a hash since two hosts with radically
* different ivar contents may be 'equal'. The best I can think of
@ -293,7 +294,7 @@ static NSMutableDictionary *_hostCache = nil;
return NO;
}
- (BOOL)isEqualToHost:(NSHost *)aHost
- (BOOL)isEqualToHost: (NSHost *)aHost
{
NSArray* a;
int i;
@ -303,12 +304,12 @@ static NSMutableDictionary *_hostCache = nil;
a = [aHost addresses];
for (i = 0; i < [a count]; i++)
if ([addresses containsObject:[a objectAtIndex:i]])
if ([addresses containsObject: [a objectAtIndex: i]])
return YES;
a = [aHost names];
for (i = 0; i < [a count]; i++)
if ([addresses containsObject:[a objectAtIndex:i]])
if ([addresses containsObject: [a objectAtIndex: i]])
return YES;
return NO;
@ -316,7 +317,7 @@ static NSMutableDictionary *_hostCache = nil;
- (NSString *)name
{
return [names objectAtIndex:0];
return [names objectAtIndex: 0];
}
- (NSArray *)names
@ -326,7 +327,7 @@ static NSMutableDictionary *_hostCache = nil;
- (NSString *)address
{
return [addresses objectAtIndex:0];
return [addresses objectAtIndex: 0];
}
- (NSArray *)addresses
@ -336,16 +337,16 @@ static NSMutableDictionary *_hostCache = nil;
- (NSString *)description
{
return [NSString stringWithFormat:@"Host %@ (%@ %@)", [self
return [NSString stringWithFormat: @"Host %@ (%@ %@)", [self
name],
[[self names] description], [[self addresses]
description]];
}
- (void)dealloc
- (void) dealloc
{
[names autorelease];
[addresses autorelease];
RELEASE(names);
RELEASE(addresses);
[super dealloc];
}

View file

@ -34,15 +34,14 @@
+ (NSInvocation*) invocationWithMethodSignature: (NSMethodSignature*)signature
{
return [[[NSInvocation alloc] initWithMethodSignature: signature]
autorelease];
return AUTORELEASE([[NSInvocation alloc] initWithMethodSignature: signature]);
}
- (void) dealloc
{
if (argsRetained)
{
[target release];
RELEASE(target);
argsRetained = NO;
if (argframe && sig)
{
@ -62,7 +61,7 @@
id obj;
mframe_get_arg(argframe, &info[i], &obj);
[obj release];
RELEASE(obj);
}
}
}
@ -75,7 +74,7 @@
{
objc_free(retval);
}
[sig release];
RELEASE(sig);
[super dealloc];
}
@ -163,10 +162,10 @@
mframe_get_arg(argframe, &info[i], &old);
mframe_set_arg(argframe, &info[i], buffer);
[*(id*)buffer retain];
RETAIN(*(id*)buffer);
if (old != nil)
{
[old release];
RELEASE(old);
}
}
else
@ -227,8 +226,7 @@
{
if (argsRetained)
{
[anObject retain];
[target release];
ASSIGN(target, anObject);
}
target = anObject;
}
@ -258,7 +256,7 @@
int i;
argsRetained = YES;
[target retain];
RETAIN(target);
if (argframe == 0)
{
return;
@ -274,7 +272,7 @@
mframe_get_arg(argframe, &info[i], &old);
if (old != nil)
{
[old retain];
RETAIN(old);
}
}
else
@ -326,7 +324,7 @@
* Temporarily set new target and copy it (and the selector) into the
* argframe.
*/
old_target = [target retain];
old_target = RETAIN(target);
[self setTarget: anObject];
mframe_set_arg(argframe, &info[1], &target);
@ -345,7 +343,7 @@
imp = objc_msg_lookup(target, selector);
[self setTarget: old_target];
[old_target release];
RELEASE(old_target);
stack_argsize = [sig frameLength];
@ -520,7 +518,7 @@
*/
- initWithMethodSignature: (NSMethodSignature*)aSignature
{
sig = [aSignature retain];
sig = RETAIN(aSignature);
numArgs = [aSignature numberOfArguments];
info = [aSignature methodInfo];
argframe = mframe_create_argframe([sig methodType], &retval);
@ -562,7 +560,7 @@
*(id*)datum = va_arg (ap, id);
if (argsRetained)
{
[*(id*)datum retain];
RETAIN(*(id*)datum);
}
break;
case _C_CHARPTR:

View file

@ -55,8 +55,8 @@
object: (id)object
userInfo: (id)info
{
return [[[self allocWithZone: NSDefaultMallocZone()] initWithName: name
object: object userInfo: info] autorelease];
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
initWithName: name object: object userInfo: info]);
}
+ (NSNotification*) notificationWithName: (NSString*)name

View file

@ -104,8 +104,8 @@ static NSPortNameServer *defaultServer = nil;
serverLock = [NSRecursiveLock new];
modes = [[NSArray alloc] initWithObjects: &mode count: 1];
#ifdef GDOMAP_PORT_OVERRIDE
serverPort = [[NSString stringWithCString:
make_gdomap_port(GDOMAP_PORT_OVERRIDE)] retain];
serverPort = RETAIN([NSString stringWithCString:
make_gdomap_port(GDOMAP_PORT_OVERRIDE)]);
#endif
}
[gnustep_global_lock unlock];
@ -374,7 +374,7 @@ static NSPortNameServer *defaultServer = nil;
p = [TcpOutPort newForSendingToSockaddr: &sin
withAcceptedSocket: 0
pollingInPort: nil];
return [p autorelease];
return AUTORELEASE(p);
}
else
{
@ -430,7 +430,7 @@ static NSPortNameServer *defaultServer = nil;
{
known = [NSMutableSet new];
NSMapInsert(portMap, port, known);
[known release];
RELEASE(known);
}
/*
@ -710,7 +710,7 @@ static NSPortNameServer *defaultServer = nil;
name: GSFileHandleWriteCompletionNotification
object: handle];
[handle closeFile];
[handle release];
RELEASE(handle);
handle = nil;
}
}
@ -871,7 +871,7 @@ static NSPortNameServer *defaultServer = nil;
NS_ENDHANDLER
if (handle)
{
[serverPort release];
RELEASE(serverPort);
serverPort = @"538";
}
}
@ -884,7 +884,7 @@ static NSPortNameServer *defaultServer = nil;
}
expecting = 1;
[handle retain];
RETAIN(handle);
nc = [NSNotificationCenter defaultCenter];
[nc addObserver: self
selector: @selector(_didConnect:)

View file

@ -34,37 +34,37 @@
// restrict the messages that can be sent to anObject. Returns the
// new instance.
+ (id)protocolCheckerWithTarget:(NSObject *)anObject
protocol:(Protocol *)aProtocol
+ (id)protocolCheckerWithTarget: (NSObject *)anObject
protocol: (Protocol *)aProtocol
{
return [[[NSProtocolChecker alloc] initWithTarget:anObject
protocol:aProtocol] autorelease];
return AUTORELEASE([[NSProtocolChecker alloc] initWithTarget: anObject
protocol: aProtocol]);
}
// Forwards any message to the delegate if the method is declared in
// the checker's protocol; otherwise raises an NSInvalidArgumentException.
- (void)forwardInvocation:(NSInvocation *)anInvocation
- (void)forwardInvocation: (NSInvocation *)anInvocation
{
unsigned int length;
void *buffer;
if ((struct objc_method_description *)NULL
!= [self methodDescriptionForSelector:[anInvocation selector]])
[[NSException exceptionWithName:NSInvalidArgumentException
reason:@"Method not declared in current protocol"
userInfo:nil]
!= [self methodDescriptionForSelector: [anInvocation selector]])
[[NSException exceptionWithName: NSInvalidArgumentException
reason: @"Method not declared in current protocol"
userInfo: nil]
raise];
[anInvocation invokeWithTarget:myTarget];
[anInvocation invokeWithTarget: myTarget];
length = [[anInvocation methodSignature] methodReturnLength];
buffer = (void *)malloc(length);
[anInvocation getReturnValue:buffer];
[anInvocation getReturnValue: buffer];
if (0 == strcmp([[anInvocation methodSignature] methodReturnType],
[[anInvocation methodSignatureForSelector:
@selector(init:)] methodReturnType]) )
@selector(init: )] methodReturnType]) )
{
if (((id)buffer) == myTarget)
{
@ -77,7 +77,7 @@
}
- (id)init
- (id) init
{
myProtocol = nil;
myTarget = nil;
@ -92,21 +92,13 @@
// allowed to be freed or dereferenced by clients, the free method
// should be included in aProtocol. Returns the new instance.
- (id)initWithTarget:(NSObject *)anObject protocol:(Protocol *)aProtocol
- (id)initWithTarget: (NSObject *)anObject protocol: (Protocol *)aProtocol
{
[super init];
//if (nil != myProtocol)
// [myProtocol autorelease];
myProtocol = aProtocol;
//if (nil != myProtocol)
// [myProtocol retain];
if (nil != myTarget)
[myTarget autorelease];
myTarget = anObject;
if (nil != myTarget)
[myTarget retain];
ASSIGN(myTarget, anObject);
return self;
}
@ -115,9 +107,9 @@
// protocol, or NULL if aSelector isn't declared as an instance method
// in the protocol.
- (struct objc_method_description *)methodDescriptionForSelector:(SEL)aSelector
- (struct objc_method_description *)methodDescriptionForSelector: (SEL)aSelector
{
return [myProtocol descriptionForInstanceMethod:aSelector];
return [myProtocol descriptionForInstanceMethod: aSelector];
}
// Returns the protocol object the checker uses to verify whether a
@ -127,9 +119,9 @@
- (Protocol *)protocol
{
if (nil == myProtocol)
[[NSException exceptionWithName:NSInvalidArgumentException
reason:@"No protocol specified"
userInfo:nil]
[[NSException exceptionWithName: NSInvalidArgumentException
reason: @"No protocol specified"
userInfo: nil]
raise];
return myProtocol;

View file

@ -34,13 +34,12 @@
/*
* Create and return a scanner that scans aString.
*/
+ scannerWithString:(NSString *)aString
+ (id) scannerWithString: (NSString *)aString
{
return [[[self alloc] initWithString: aString]
autorelease];
return AUTORELEASE([[self alloc] initWithString: aString]);
}
+ localizedScannerWithString: (NSString*)locale
+ (id) localizedScannerWithString: (NSString*)locale
{
[self notImplemented: _cmd];
return Nil;
@ -50,31 +49,31 @@
* Initialize a a newly-allocated scanner to scan aString.
* Returns self.
*/
- initWithString:(NSString *)aString
- (id) initWithString: (NSString *)aString
{
[super init];
string = [aString copyWithZone: [self zone]];
len = [string length];
charactersToBeSkipped = [[NSCharacterSet whitespaceAndNewlineCharacterSet] retain];
charactersToBeSkipped = RETAIN([NSCharacterSet whitespaceAndNewlineCharacterSet]);
return self;
}
/*
* Deallocate a scanner and all its associated storage.
*/
- (void)dealloc
- (void) dealloc
{
[string release];
[locale release];
[charactersToBeSkipped release];
RELEASE(string);
RELEASE(locale);
RELEASE(charactersToBeSkipped);
[super dealloc];
}
/*
* Like scanCharactersFromSet:intoString: but no initial skip
* Like scanCharactersFromSet: intoString: but no initial skip
* For internal use only.
*/
- (BOOL)_scanCharactersFromSet: (NSCharacterSet *)set
- (BOOL) _scanCharactersFromSet: (NSCharacterSet *)set
intoString: (NSString **)value;
{
unsigned int start;
@ -84,7 +83,7 @@
start = scanLocation;
while (scanLocation < len)
{
if (![set characterIsMember: [string characterAtIndex:scanLocation]])
if (![set characterIsMember: [string characterAtIndex: scanLocation]])
break;
scanLocation++;
}
@ -154,12 +153,12 @@
BOOL got_digits = NO;
/* Check for sign */
switch ([string characterAtIndex:scanLocation])
switch ([string characterAtIndex: scanLocation])
{
case '+':
case '+':
scanLocation++;
break;
case '-':
case '-':
negative = YES;
scanLocation++;
break;
@ -211,9 +210,9 @@
/*
* Scan an unsigned int of the given radix into value.
* Internal version used by scanRadixUnsignedInt: and scanHexInt:.
* Internal version used by scanRadixUnsignedInt: and scanHexInt: .
*/
- (BOOL)scanUnsignedInt_: (unsigned int *)value radix:(int)radix gotDigits:(BOOL)gotDigits
- (BOOL) scanUnsignedInt_: (unsigned int *)value radix: (int)radix gotDigits: (BOOL)gotDigits
{
unsigned int num = 0;
unsigned int numLimit, digitLimit, digitValue;
@ -227,7 +226,7 @@
/* Process digits */
while (scanLocation < len)
{
unichar digit = [string characterAtIndex:scanLocation];
unichar digit = [string characterAtIndex: scanLocation];
switch (digit)
{
case '0': digitValue = 0; break;
@ -252,7 +251,7 @@
case 'D': digitValue = 0xD; break;
case 'E': digitValue = 0xE; break;
case 'F': digitValue = 0xF; break;
default:
default:
digitValue = radix;
break;
}
@ -288,7 +287,7 @@
/*
* Scan an unsigned int of the given radix into value.
*/
- (BOOL)scanRadixUnsignedInt: (unsigned int *)value
- (BOOL) scanRadixUnsignedInt: (unsigned int *)value
{
int radix;
BOOL gotDigits = NO;
@ -303,17 +302,17 @@
/* Check radix */
radix = 10;
if ((scanLocation < len) && ([string characterAtIndex:scanLocation] == '0'))
if ((scanLocation < len) && ([string characterAtIndex: scanLocation] == '0'))
{
radix = 8;
scanLocation++;
gotDigits = YES;
if (scanLocation < len)
{
switch ([string characterAtIndex:scanLocation])
switch ([string characterAtIndex: scanLocation])
{
case 'x':
case 'X':
case 'x':
case 'X':
scanLocation++;
radix = 16;
gotDigits = NO;
@ -321,7 +320,7 @@
}
}
}
if ( [self scanUnsignedInt_:value radix:radix gotDigits:gotDigits])
if ( [self scanUnsignedInt_: value radix: radix gotDigits: gotDigits])
return YES;
scanLocation = saveScanLocation;
return NO;
@ -330,7 +329,7 @@
/*
* Scan a hexadecimal unsigned integer into value.
*/
- (BOOL)scanHexInt: (unsigned int *)value
- (BOOL) scanHexInt: (unsigned int *)value
{
unsigned int saveScanLocation = scanLocation;
@ -340,7 +339,7 @@
scanLocation = saveScanLocation;
return NO;
}
if ([self scanUnsignedInt_:value radix:16 gotDigits:NO])
if ([self scanUnsignedInt_: value radix: 16 gotDigits: NO])
return YES;
scanLocation = saveScanLocation;
return NO;
@ -350,7 +349,7 @@
* Scan a long long int into value.
* Same as scanInt, except with different variable types and limits.
*/
- (BOOL)scanLongLong: (long long *)value
- (BOOL) scanLongLong: (long long *)value
{
#if defined(LONG_LONG_MAX)
unsigned long long num = 0;
@ -368,12 +367,12 @@
}
/* Check for sign */
switch ([string characterAtIndex:scanLocation])
switch ([string characterAtIndex: scanLocation])
{
case '+':
case '+':
scanLocation++;
break;
case '-':
case '-':
negative = YES;
scanLocation++;
break;
@ -382,7 +381,7 @@
/* Process digits */
while (scanLocation < len)
{
unichar digit = [string characterAtIndex:scanLocation];
unichar digit = [string characterAtIndex: scanLocation];
if ((digit < '0') || (digit > '9'))
break;
if (!overflow) {
@ -417,7 +416,7 @@
*/
# warning "Can't use long long variables."
[NSException raise: NSGenericException
format:@"Can't use long long variables."];
format: @"Can't use long long variables."];
return NO;
#endif /* defined(LONG_LONG_MAX) */
}
@ -430,7 +429,7 @@
* On underflow, 0.0 is put into value and YES is returned.
* Based on the strtod code from the GNU C library.
*/
- (BOOL)scanDouble:(double *)value
- (BOOL) scanDouble: (double *)value
{
unichar decimal;
unichar c = 0;
@ -456,12 +455,12 @@
decimal = '.';
/* Check for sign */
switch ([string characterAtIndex:scanLocation])
switch ([string characterAtIndex: scanLocation])
{
case '+':
case '+':
scanLocation++;
break;
case '-':
case '-':
negative = YES;
scanLocation++;
break;
@ -556,13 +555,13 @@
* On overflow, HUGE_VAL or -HUGE_VAL is put into value and YES is returned.
* On underflow, 0.0 is put into value and YES is returned.
*/
- (BOOL)scanFloat: (float*)value
- (BOOL) scanFloat: (float*)value
{
double num;
if (value == NULL)
return [self scanDouble:NULL];
if ([self scanDouble:&num])
return [self scanDouble: NULL];
if ([self scanDouble: &num])
{
*value = num;
return YES;
@ -577,8 +576,8 @@
* If value is non-NULL, and any characters were scanned, a string
* containing the scanned characters is returned by reference in value.
*/
- (BOOL)scanCharactersFromSet:(NSCharacterSet *)aSet
intoString:(NSString **)value;
- (BOOL) scanCharactersFromSet: (NSCharacterSet *)aSet
intoString: (NSString **)value;
{
unsigned int saveScanLocation = scanLocation;
@ -596,8 +595,8 @@
* If value is non-NULL, and any characters were scanned, a string
* containing the scanned characters is returned by reference in value.
*/
- (BOOL)scanUpToCharactersFromSet:(NSCharacterSet *)set
intoString:(NSString **)value;
- (BOOL) scanUpToCharactersFromSet: (NSCharacterSet *)set
intoString: (NSString **)value;
{
unsigned int saveScanLocation = scanLocation;
unsigned int start;
@ -607,7 +606,7 @@
start = scanLocation;
while (scanLocation < len)
{
if ([set characterIsMember:[string characterAtIndex: scanLocation]])
if ([set characterIsMember: [string characterAtIndex: scanLocation]])
break;
scanLocation++;
}
@ -634,7 +633,7 @@
* If value is non-NULL, and the characters at the scan location match aString,
* a string containing the matching string is returned by reference in value.
*/
- (BOOL)scanString:(NSString *)aString intoString:(NSString **)value;
- (BOOL) scanString: (NSString *)aString intoString: (NSString **)value;
{
NSRange range;
unsigned int saveScanLocation = scanLocation;
@ -644,16 +643,16 @@
range.length = [aString length];
if (range.location + range.length > len)
return NO;
range = [string rangeOfString:aString
options:caseSensitive ? 0 : NSCaseInsensitiveSearch
range:range];
range = [string rangeOfString: aString
options: caseSensitive ? 0 : NSCaseInsensitiveSearch
range: range];
if (range.length == 0)
{
scanLocation = saveScanLocation;
return NO;
}
if (value)
*value = [string substringFromRange:range];
*value = [string substringFromRange: range];
scanLocation += range.length;
return YES;
}
@ -665,8 +664,8 @@
* If value is non-NULL, and any characters were scanned, a string
* containing the scanned characters is returned by reference in value.
*/
- (BOOL)scanUpToString:(NSString *)aString
intoString:(NSString **)value;
- (BOOL) scanUpToString: (NSString *)aString
intoString: (NSString **)value;
{
NSRange range;
NSRange found;
@ -675,9 +674,9 @@
[self _skipToNextField];
range.location = scanLocation;
range.length = len - scanLocation;
found = [string rangeOfString:aString
options:caseSensitive ? 0 : NSCaseInsensitiveSearch
range:range];
found = [string rangeOfString: aString
options: caseSensitive ? 0 : NSCaseInsensitiveSearch
range: range];
if (found.length)
range.length = found.location - scanLocation;
if (range.length == 0)
@ -686,7 +685,7 @@
return NO;
}
if (value)
*value = [string substringFromRange:range];
*value = [string substringFromRange: range];
scanLocation += range.length;
return YES;
}
@ -694,7 +693,7 @@
/*
* Returns the string being scanned.
*/
- (NSString *)string
- (NSString *) string
{
return string;
}
@ -703,7 +702,7 @@
* Returns the character index at which the scanner
* will begin the next scanning operation.
*/
- (unsigned)scanLocation
- (unsigned) scanLocation
{
return scanLocation;
}
@ -712,7 +711,7 @@
* Set the character location at which the scanner
* will begin the next scanning operation to anIndex.
*/
- (void)setScanLocation:(unsigned int)anIndex
- (void) setScanLocation: (unsigned int)anIndex
{
scanLocation = anIndex;
}
@ -721,7 +720,7 @@
* Returns YES if the scanner makes a distinction
* between upper and lower case characters.
*/
- (BOOL)caseSensitive
- (BOOL) caseSensitive
{
return caseSensitive;
}
@ -731,7 +730,7 @@
* to be the same during scanning. If flag is NO the scanner will
* not make a distinction between upper and lower case characters.
*/
- (void)setCaseSensitive:(BOOL)flag
- (void) setCaseSensitive: (BOOL)flag
{
caseSensitive = flag;
}
@ -740,7 +739,7 @@
* Return a character set object containing the characters the scanner
* will ignore when searching for the next element to be scanned.
*/
- (NSCharacterSet *)charactersToBeSkipped
- (NSCharacterSet *) charactersToBeSkipped
{
return charactersToBeSkipped;
}
@ -749,17 +748,16 @@
* Set the characters to be ignored when the scanner
* searches for the next element to be scanned.
*/
- (void)setCharactersToBeSkipped:(NSCharacterSet *)aSet
- (void) setCharactersToBeSkipped: (NSCharacterSet *)aSet
{
[charactersToBeSkipped release];
charactersToBeSkipped = [aSet copyWithZone: [self zone]];
ASSIGNCOPY(charactersToBeSkipped, aSet);
}
/*
* Returns a dictionary object containing the locale
* information used by the scanner.
*/
- (NSDictionary *)locale
- (NSDictionary *) locale
{
return locale;
}
@ -768,17 +766,17 @@
* Set the dictionary containing the locale
* information used by the scanner to localeDictionary.
*/
- (void)setLocale:(NSDictionary *)localeDictionary
- (void) setLocale: (NSDictionary *)localeDictionary
{
locale = [localeDictionary retain];
locale = RETAIN(localeDictionary);
}
/*
* NSCopying protocol
*/
- copyWithZone:(NSZone *)zone
- (id) copyWithZone: (NSZone *)zone
{
NSScanner *n = [[self class] allocWithZone:zone];
NSScanner *n = [[self class] allocWithZone: zone];
[n initWithString: string];
[n setCharactersToBeSkipped: charactersToBeSkipped];

View file

@ -424,7 +424,7 @@ deserializeFromInfo(_NSDeserializerInfo* info)
{
case ST_XREF:
{
return [GSIArrayItemAtIndex(&info->array, size).obj retain];
return RETAIN(GSIArrayItemAtIndex(&info->array, size).obj);
}
case ST_CSTRING:
@ -515,10 +515,12 @@ deserializeFromInfo(_NSDeserializerInfo* info)
objects[i] = deserializeFromInfo(info);
if (objects[i] == nil)
{
#if !GS_WITH_GC
while (i > 0)
{
[objects[--i] release];
}
#endif
objc_free(objects);
return nil;
}
@ -533,11 +535,12 @@ deserializeFromInfo(_NSDeserializerInfo* info)
a = NSAllocateObject(IACls, 0, NSDefaultMallocZone());
a = (*iaInitImp)(a, iaInitSel, objects, size);
}
#if !GS_WITH_GC
for (i = 0; i < size; i++)
{
[objects[i] release];
}
#endif
return a;
}
@ -554,22 +557,26 @@ deserializeFromInfo(_NSDeserializerInfo* info)
keys[i] = deserializeFromInfo(info);
if (keys[i] == nil)
{
#if !GS_WITH_GC
while (i > 0)
{
[keys[--i] release];
[objects[i] release];
}
#endif
return nil;
}
objects[i] = deserializeFromInfo(info);
if (objects[i] == nil)
{
#if !GS_WITH_GC
[keys[i] release];
while (i > 0)
{
[keys[--i] release];
[objects[i] release];
}
#endif
return nil;
}
}
@ -583,11 +590,13 @@ deserializeFromInfo(_NSDeserializerInfo* info)
d = NSAllocateObject(IDCls, 0, NSDefaultMallocZone());
d = (*idInitImp)(d, idInitSel, objects, keys, size);
}
#if !GS_WITH_GC
for (i = 0; i < size; i++)
{
[keys[i] release];
[objects[i] release];
}
#endif
return d;
}
@ -627,15 +636,15 @@ deserializeFromInfo(_NSDeserializerInfo* info)
_NSDeserializerProxy *proxy;
proxy = (_NSDeserializerProxy*)NSAllocateObject(self,0,NSDefaultMallocZone());
initDeserializerInfo(&proxy->info, [d retain], c, m);
return [proxy autorelease];
initDeserializerInfo(&proxy->info, RETAIN(d), c, m);
return AUTORELEASE(proxy);
}
- (void) dealloc
{
[info.data release];
RELEASE(info.data);
endDeserializerInfo(&info);
[plist release];
RELEASE(plist);
[super dealloc];
}
@ -644,7 +653,7 @@ deserializeFromInfo(_NSDeserializerInfo* info)
if (plist == nil && info.data != nil)
{
plist = deserializeFromInfo(&info);
[info.data release];
RELEASE(info.data);
info.data = nil;
}
return [plist performv: aSel :frame];
@ -663,7 +672,7 @@ deserializeFromInfo(_NSDeserializerInfo* info)
if (plist == nil && info.data != nil)
{
plist = deserializeFromInfo(&info);
[info.data release];
RELEASE(info.data);
info.data = nil;
}
return plist;
@ -719,8 +728,7 @@ deserializeFromInfo(_NSDeserializerInfo* info)
initDeserializerInfo(&info, data, cursor, flag);
o = deserializeFromInfo(&info);
endDeserializerInfo(&info);
[o autorelease];
return o;
return AUTORELEASE(o);
}
+ (id) deserializePropertyListFromData: (NSData*)data
@ -734,8 +742,7 @@ deserializeFromInfo(_NSDeserializerInfo* info)
initDeserializerInfo(&info, data, &cursor, flag);
o = deserializeFromInfo(&info);
endDeserializerInfo(&info);
[o autorelease];
return o;
return AUTORELEASE(o);
}
+ (id) deserializePropertyListLazilyFromData: (NSData*)data
@ -753,8 +760,7 @@ deserializeFromInfo(_NSDeserializerInfo* info)
initDeserializerInfo(&info, data, cursor, flag);
o = deserializeFromInfo(&info);
endDeserializerInfo(&info);
[o autorelease];
return o;
return AUTORELEASE(o);
}
else
{

View file

@ -70,66 +70,67 @@ static Class NSMutableSet_concrete_class;
return NSMutableSet_concrete_class;
}
+ set
+ (id) set
{
return [[[self allocWithZone: NSDefaultMallocZone()] init] autorelease];
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()] init]);
}
+ setWithObjects: (id*)objects
count: (unsigned)count
+ (id) setWithObjects: (id*)objects
count: (unsigned)count
{
return [[[self allocWithZone: NSDefaultMallocZone()]
initWithObjects: objects count: count] autorelease];
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
initWithObjects: objects count: count]);
}
+ setWithArray: (NSArray*)objects
+ (id) setWithArray: (NSArray*)objects
{
return [[[self allocWithZone: NSDefaultMallocZone()]
initWithArray: objects] autorelease];
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
initWithArray: objects]);
}
+ setWithObject: anObject
+ (id) setWithObject: anObject
{
return [[[self allocWithZone: NSDefaultMallocZone()]
initWithObjects: &anObject count: 1] autorelease];
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
initWithObjects: &anObject count: 1]);
}
+ setWithObjects: firstObject, ...
+ (id) setWithObjects: firstObject, ...
{
id set;
va_list ap;
va_start(ap, firstObject);
self = [[self allocWithZone: NSDefaultMallocZone()]
set = [[self allocWithZone: NSDefaultMallocZone()]
initWithObjects: firstObject rest: ap];
va_end(ap);
return [self autorelease];
return AUTORELEASE(set);
}
+ setWithSet: (NSSet*)aSet
+ (id) setWithSet: (NSSet*)aSet
{
return [[[self allocWithZone: NSDefaultMallocZone()]
initWithSet: aSet] autorelease];
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
initWithSet: aSet]);
}
+ allocWithZone: (NSZone*)z
+ (id) allocWithZone: (NSZone*)z
{
return NSAllocateObject([self _concreteClass], 0, z);
}
/* This is the designated initializer */
- initWithObjects: (id*)objects
count: (unsigned)count
- (id) initWithObjects: (id*)objects
count: (unsigned)count
{
[self subclassResponsibility: _cmd];
return 0;
}
- initWithCoder: aCoder
- (id) initWithCoder: (NSCoder*)aCoder
{
[self subclassResponsibility: _cmd];
return nil;
}
- (void) encodeWithCoder: aCoder
- (void) encodeWithCoder: (NSCoder*)aCoder
{
[self subclassResponsibility: _cmd];
}
@ -140,7 +141,7 @@ static Class NSMutableSet_concrete_class;
return 0;
}
- member: anObject
- (id) member: anObject
{
return [self subclassResponsibility: _cmd];
return 0;
@ -153,7 +154,7 @@ static Class NSMutableSet_concrete_class;
- (id) copyWithZone: (NSZone*)z
{
return [self retain];
return RETAIN(self);
}
- (id) mutableCopyWithZone: (NSZone*)z
@ -167,7 +168,7 @@ static Class NSMutableSet_concrete_class;
@implementation NSSetNonCore
/* Same as NSArray */
- initWithObjects: firstObject rest: (va_list)ap
- (id) initWithObjects: firstObject rest: (va_list)ap
{
register unsigned i;
register unsigned curSize;
@ -261,9 +262,11 @@ static Class NSMutableSet_concrete_class;
i++;
}
self = [self initWithObjects: os count: c];
#if !GS_WITH_GC
if (flag)
while (i--)
[os[i] release];
#endif
return self;
}
@ -282,8 +285,8 @@ static Class NSMutableSet_concrete_class;
{
k[i] = [e nextObject];
}
return [[[NSArray allocWithZone: NSDefaultMallocZone()]
initWithObjects: k count: c] autorelease];
return AUTORELEASE([[NSArray allocWithZone: NSDefaultMallocZone()]
initWithObjects: k count: c]);
}
- (id) anyObject
@ -433,8 +436,8 @@ static Class NSMutableSet_concrete_class;
+ (id) setWithCapacity: (unsigned)numItems
{
return [[[self allocWithZone: NSDefaultMallocZone()]
initWithCapacity: numItems] autorelease];
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
initWithCapacity: numItems]);
}
+ (id) allocWithZone: (NSZone*)z

View file

@ -58,24 +58,21 @@ NSString* NSURLPartKey_query=@"query";
//-----------------------------------------------------------------------------
+ (id) fileURLWithPath: (NSString*)_path
{
return [[[NSURL alloc] initFileURLWithPath: _path]
autorelease];
return AUTORELEASE([[NSURL alloc] initFileURLWithPath: _path]);
}
//-----------------------------------------------------------------------------
+ (id)URLWithString: (NSString*)_urlString
{
return [[[NSURL alloc] initWithString: _urlString]
autorelease];
return AUTORELEASE([[NSURL alloc] initWithString: _urlString]);
}
//-----------------------------------------------------------------------------
+ (id)URLWithString: (NSString*)_urlString
relativeToURL: (NSURL*)_baseURL
{
return [[[NSURL alloc] initWithString: _urlString
relativeToURL: _baseURL]
autorelease];
return AUTORELEASE([[NSURL alloc] initWithString: _urlString
relativeToURL: _baseURL]);
}
//-----------------------------------------------------------------------------
@ -158,7 +155,7 @@ NSString* NSURLPartKey_query=@"query";
return [[isa allocWithZone: zone] initWithString: urlString
relativeToURL: baseURL];
else
return [self retain];
return RETAIN(self);
}
//-----------------------------------------------------------------------------
@ -287,7 +284,7 @@ NSString* NSURLPartKey_query=@"query";
{
int index=2;
NSRange range;
elements=[[NSMutableDictionary new] autorelease];
elements = [NSMutableDictionary dictionaryWithCapacity: 0];
if (![[self scheme] isEqualToString: NSURLFileScheme])
{
range=[resourceSpecifier rangeOfString: @"/"

View file

@ -67,74 +67,83 @@ NSString *NSUndoManagerWillUndoChangeNotification =
- (NSMutableArray*) actions
{
return actions;
return actions;
}
- (void) addInvocation: (NSInvocation*)inv
{
if (actions == nil) {
actions = [[NSMutableArray alloc] initWithCapacity: 2];
if (actions == nil)
{
actions = [[NSMutableArray alloc] initWithCapacity: 2];
}
[actions addObject: inv];
[actions addObject: inv];
}
- (void) dealloc
{
[actions release];
[parent release];
[super dealloc];
RELEASE(actions);
RELEASE(parent);
[super dealloc];
}
- (id) initWithParent: (PrivateUndoGroup*)p
{
self = [super init];
if (self) {
parent = [p retain];
actions = nil;
self = [super init];
if (self)
{
parent = RETAIN(p);
actions = nil;
}
return self;
return self;
}
- (void) orphan
{
id p = parent;
parent = nil;
[p release];
id p = parent;
parent = nil;
RELEASE(p);
}
- (PrivateUndoGroup*) parent
{
return parent;
return parent;
}
- (void) perform
{
if (actions != nil) {
int i;
if (actions != nil)
{
unsigned i = [actions count];
for (i = [actions count]; i > 0; i--) {
[[actions objectAtIndex: i-1] invoke];
while (i-- > 0)
{
[[actions objectAtIndex: i] invoke];
}
}
}
- (BOOL) removeActionsForTarget: (id)target
{
if (actions != nil) {
int i;
if (actions != nil)
{
unsigned i = [actions count];
for (i = [actions count]; i > 0; i--) {
NSInvocation *inv = [actions objectAtIndex: i-1];
while (i-- > 0)
{
NSInvocation *inv = [actions objectAtIndex: i];
if ([inv target] == target) {
[actions removeObjectAtIndex: i-1];
if ([inv target] == target)
{
[actions removeObjectAtIndex: i];
}
}
if ([actions count] > 0) {
return YES;
if ([actions count] > 0)
{
return YES;
}
}
return NO;
return NO;
}
@end
@ -151,11 +160,13 @@ NSString *NSUndoManagerWillUndoChangeNotification =
@implementation NSUndoManager (Private)
- (void) _loop: (id)arg
{
if (groupsByEvent) {
if (group != nil) {
[self endUndoGrouping];
if (groupsByEvent)
{
if (group != nil)
{
[self endUndoGrouping];
}
[self beginUndoGrouping];
[self beginUndoGrouping];
}
}
@end
@ -169,422 +180,472 @@ NSString *NSUndoManagerWillUndoChangeNotification =
- (void) beginUndoGrouping
{
PrivateUndoGroup *parent;
PrivateUndoGroup *parent;
if (isUndoing == NO) {
[[NSNotificationCenter defaultCenter]
postNotificationName: NSUndoManagerCheckpointNotification
object: self];
if (isUndoing == NO)
{
[[NSNotificationCenter defaultCenter]
postNotificationName: NSUndoManagerCheckpointNotification
object: self];
}
parent = (PrivateUndoGroup*)group;
group = [[PrivateUndoGroup alloc] initWithParent: parent];
if (group == nil) {
group = parent;
[NSException raise: NSInternalInconsistencyException
format: @"beginUndoGrouping failed to greate group"];
parent = (PrivateUndoGroup*)group;
group = [[PrivateUndoGroup alloc] initWithParent: parent];
if (group == nil)
{
group = parent;
[NSException raise: NSInternalInconsistencyException
format: @"beginUndoGrouping failed to greate group"];
}
else {
[parent release];
else
{
RELEASE(parent);
[[NSNotificationCenter defaultCenter]
postNotificationName: NSUndoManagerDidOpenUndoGroupNotification
object: self];
[[NSNotificationCenter defaultCenter]
postNotificationName: NSUndoManagerDidOpenUndoGroupNotification
object: self];
}
}
- (BOOL) canRedo
{
[[NSNotificationCenter defaultCenter]
postNotificationName: NSUndoManagerCheckpointNotification
object: self];
if ([redoStack count] > 0) {
return YES;
[[NSNotificationCenter defaultCenter]
postNotificationName: NSUndoManagerCheckpointNotification
object: self];
if ([redoStack count] > 0)
{
return YES;
}
else {
return NO;
else
{
return NO;
}
}
- (BOOL) canUndo
{
if ([undoStack count] > 0) {
return YES;
if ([undoStack count] > 0)
{
return YES;
}
if (group != nil && [[group actions] count] > 0) {
return YES;
if (group != nil && [[group actions] count] > 0)
{
return YES;
}
return NO;
return NO;
}
- (void) dealloc
{
[[NSRunLoop currentRunLoop] cancelPerformSelector: @selector(_loop:)
target: self
argument: nil];
[redoStack release];
[undoStack release];
[actionName release];
[group release];
[modes release];
[super dealloc];
[[NSRunLoop currentRunLoop] cancelPerformSelector: @selector(_loop:)
target: self
argument: nil];
RELEASE(redoStack);
RELEASE(undoStack);
RELEASE(actionName);
RELEASE(group);
RELEASE(modes);
[super dealloc];
}
- (void) disableUndoRegistration
{
disableCount++;
disableCount++;
}
- (void) enableUndoRegistration
{
if (disableCount > 0) {
disableCount--;
registeredUndo = NO; /* No operations since registration enabled. */
if (disableCount > 0)
{
disableCount--;
registeredUndo = NO; /* No operations since registration enabled. */
}
else {
[NSException raise: NSInternalInconsistencyException
format: @"enableUndoRegistration without disable"];
else
{
[NSException raise: NSInternalInconsistencyException
format: @"enableUndoRegistration without disable"];
}
}
- (void) endUndoGrouping
{
PrivateUndoGroup *g;
PrivateUndoGroup *p;
PrivateUndoGroup *g;
PrivateUndoGroup *p;
if (group == nil) {
[NSException raise: NSInternalInconsistencyException
format: @"endUndoGrouping without beginUndoGrouping"];
if (group == nil)
{
[NSException raise: NSInternalInconsistencyException
format: @"endUndoGrouping without beginUndoGrouping"];
}
[[NSNotificationCenter defaultCenter]
postNotificationName: NSUndoManagerCheckpointNotification
object: self];
g = (PrivateUndoGroup*)group;
p = [[g parent] retain];
group = p;
[g orphan];
[[NSNotificationCenter defaultCenter]
postNotificationName: NSUndoManagerWillCloseUndoGroupNotification
object: self];
if (p == nil) {
if (isUndoing) {
if (levelsOfUndo > 0 && [redoStack count] == levelsOfUndo) {
[redoStack removeObjectAtIndex: 0];
[[NSNotificationCenter defaultCenter]
postNotificationName: NSUndoManagerCheckpointNotification
object: self];
g = (PrivateUndoGroup*)group;
p = RETAIN([g parent]);
group = p;
[g orphan];
[[NSNotificationCenter defaultCenter]
postNotificationName: NSUndoManagerWillCloseUndoGroupNotification
object: self];
if (p == nil)
{
if (isUndoing)
{
if (levelsOfUndo > 0 && [redoStack count] == levelsOfUndo)
{
[redoStack removeObjectAtIndex: 0];
}
[redoStack addObject: g];
[redoStack addObject: g];
}
else {
if (levelsOfUndo > 0 && [undoStack count] == levelsOfUndo) {
[undoStack removeObjectAtIndex: 0];
else
{
if (levelsOfUndo > 0 && [undoStack count] == levelsOfUndo)
{
[undoStack removeObjectAtIndex: 0];
}
[undoStack addObject: g];
[undoStack addObject: g];
}
}
else if ([g actions] != nil) {
NSArray *a = [g actions];
int i;
else if ([g actions] != nil)
{
NSArray *a = [g actions];
unsigned i;
for (i = 0; i < [a count]; i++) {
[p addInvocation: [a objectAtIndex: i]];
for (i = 0; i < [a count]; i++)
{
[p addInvocation: [a objectAtIndex: i]];
}
}
[g release];
RELEASE(g);
}
- (void) forwardInvocation: (NSInvocation*)anInvocation
{
if (disableCount == 0) {
if (nextTarget == nil) {
[NSException raise: NSInternalInconsistencyException
format: @"forwardInvocation without perparation"];
if (disableCount == 0)
{
if (nextTarget == nil)
{
[NSException raise: NSInternalInconsistencyException
format: @"forwardInvocation without perparation"];
}
if (group == nil) {
[NSException raise: NSInternalInconsistencyException
format: @"forwardInvocation without beginUndoGrouping"];
if (group == nil)
{
[NSException raise: NSInternalInconsistencyException
format: @"forwardInvocation without beginUndoGrouping"];
}
[anInvocation setTarget: nextTarget];
nextTarget = nil;
[group addInvocation: anInvocation];
if (isUndoing == NO) {
[redoStack removeAllObjects];
[anInvocation setTarget: nextTarget];
nextTarget = nil;
[group addInvocation: anInvocation];
if (isUndoing == NO)
{
[redoStack removeAllObjects];
}
registeredUndo = YES;
registeredUndo = YES;
}
}
- (int) groupingLevel
{
PrivateUndoGroup *g = (PrivateUndoGroup*)group;
int level = 0;
PrivateUndoGroup *g = (PrivateUndoGroup*)group;
int level = 0;
while (g != nil) {
level++;
g = [g parent];
while (g != nil)
{
level++;
g = [g parent];
}
return level;
return level;
}
- (BOOL) groupsByEvent
{
return groupsByEvent;
return groupsByEvent;
}
- (id) init
{
self = [super init];
if (self) {
actionName = @"";
redoStack = [[NSMutableArray alloc] initWithCapacity: 16];
undoStack = [[NSMutableArray alloc] initWithCapacity: 16];
[self setRunLoopModes:
[NSArray arrayWithObjects: NSDefaultRunLoopMode, nil]];
self = [super init];
if (self)
{
actionName = @"";
redoStack = [[NSMutableArray alloc] initWithCapacity: 16];
undoStack = [[NSMutableArray alloc] initWithCapacity: 16];
[self setRunLoopModes:
[NSArray arrayWithObjects: NSDefaultRunLoopMode, nil]];
}
return self;
return self;
}
- (BOOL) isRedoing
{
return isRedoing;
return isRedoing;
}
- (BOOL) isUndoing
{
return isUndoing;
return isUndoing;
}
- (BOOL) isUndoRegistrationEnabled
{
if (disableCount == 0) {
return YES;
if (disableCount == 0)
{
return YES;
}
else {
return NO;
else
{
return NO;
}
}
- (unsigned int) levelsOfUndo
{
return levelsOfUndo;
return levelsOfUndo;
}
- (id) prepareWithInvocationTarget: (id)target
{
nextTarget = target;
return self;
nextTarget = target;
return self;
}
- (void) redo
{
if (isUndoing || isRedoing) {
[NSException raise: NSInternalInconsistencyException
format: @"redo while undoing or redoing"];
if (isUndoing || isRedoing)
{
[NSException raise: NSInternalInconsistencyException
format: @"redo while undoing or redoing"];
}
[[NSNotificationCenter defaultCenter]
postNotificationName: NSUndoManagerCheckpointNotification
object: self];
if ([redoStack count] > 0) {
PrivateUndoGroup *oldGroup;
PrivateUndoGroup *groupToRedo;
[[NSNotificationCenter defaultCenter]
postNotificationName: NSUndoManagerCheckpointNotification
object: self];
if ([redoStack count] > 0)
{
PrivateUndoGroup *oldGroup;
PrivateUndoGroup *groupToRedo;
[[NSNotificationCenter defaultCenter]
postNotificationName: NSUndoManagerWillRedoChangeNotification
object: self];
groupToRedo = [redoStack objectAtIndex: [redoStack count] - 1];
[groupToRedo retain];
[redoStack removeObjectAtIndex: [redoStack count] - 1];
oldGroup = group;
group = nil;
isRedoing = YES;
[self beginUndoGrouping];
[groupToRedo perform];
[groupToRedo release];
[self endUndoGrouping];
isRedoing = NO;
group = oldGroup;
[[NSNotificationCenter defaultCenter]
postNotificationName: NSUndoManagerDidRedoChangeNotification
object: self];
[[NSNotificationCenter defaultCenter]
postNotificationName: NSUndoManagerWillRedoChangeNotification
object: self];
groupToRedo = [redoStack objectAtIndex: [redoStack count] - 1];
RETAIN(groupToRedo);
[redoStack removeObjectAtIndex: [redoStack count] - 1];
oldGroup = group;
group = nil;
isRedoing = YES;
[self beginUndoGrouping];
[groupToRedo perform];
RELEASE(groupToRedo);
[self endUndoGrouping];
isRedoing = NO;
group = oldGroup;
[[NSNotificationCenter defaultCenter]
postNotificationName: NSUndoManagerDidRedoChangeNotification
object: self];
}
}
- (NSString*) redoActionName
{
if ([self canRedo] == NO) {
return nil;
if ([self canRedo] == NO)
{
return nil;
}
return actionName;
return actionName;
}
- (NSString*) redoMenuItemTitle
{
return [self redoMenuTitleForUndoActionName: [self redoActionName]];
return [self redoMenuTitleForUndoActionName: [self redoActionName]];
}
- (NSString*) redoMenuTitleForUndoActionName: (NSString*)name
{
if (name) {
if ([name isEqual: @""]) {
return @"Redo";
if (name)
{
if ([name isEqual: @""])
{
return @"Redo";
}
else {
return [NSString stringWithFormat: @"Redo %@", name];
else
{
return [NSString stringWithFormat: @"Redo %@", name];
}
}
return name;
return name;
}
- (void) registerUndoWithTarget: (id)target
selector: (SEL)aSelector
object: (id)anObject
{
if (disableCount == 0) {
NSMethodSignature *sig;
NSInvocation *inv;
PrivateUndoGroup *g;
if (disableCount == 0)
{
NSMethodSignature *sig;
NSInvocation *inv;
PrivateUndoGroup *g;
if (group == nil) {
[NSException raise: NSInternalInconsistencyException
format: @"registerUndo without beginUndoGrouping"];
if (group == nil)
{
[NSException raise: NSInternalInconsistencyException
format: @"registerUndo without beginUndoGrouping"];
}
g = group;
sig = [target methodSignatureForSelector: aSelector];
inv = [NSInvocation invocationWithMethodSignature: sig];
[inv setTarget: target];
[inv setSelector: aSelector];
[inv setArgument: &anObject atIndex: 2];
[g addInvocation: inv];
if (isUndoing == NO) {
[redoStack removeAllObjects];
g = group;
sig = [target methodSignatureForSelector: aSelector];
inv = [NSInvocation invocationWithMethodSignature: sig];
[inv setTarget: target];
[inv setSelector: aSelector];
[inv setArgument: &anObject atIndex: 2];
[g addInvocation: inv];
if (isUndoing == NO)
{
[redoStack removeAllObjects];
}
registeredUndo = YES;
registeredUndo = YES;
}
}
- (void) removeAllActions
{
[redoStack removeAllObjects];
[undoStack removeAllObjects];
isRedoing = NO;
isUndoing = NO;
disableCount = 0;
[redoStack removeAllObjects];
[undoStack removeAllObjects];
isRedoing = NO;
isUndoing = NO;
disableCount = 0;
}
- (void) removeAllActionsWithTarget: (id)target
{
int i;
unsigned i;
for (i = [redoStack count]; i > 0; i--) {
PrivateUndoGroup *g;
i = [redoStack count];
while (i-- > 0)
{
PrivateUndoGroup *g;
g = [redoStack objectAtIndex: i-1];
if ([g removeActionsForTarget: target] == NO) {
[redoStack removeObjectAtIndex: i-1];
g = [redoStack objectAtIndex: i];
if ([g removeActionsForTarget: target] == NO)
{
[redoStack removeObjectAtIndex: i];
}
}
for (i = [undoStack count]; i > 0; i--) {
PrivateUndoGroup *g;
i = [undoStack count];
while (i-- > 0)
{
PrivateUndoGroup *g;
g = [undoStack objectAtIndex: i-1];
if ([g removeActionsForTarget: target] == NO) {
[undoStack removeObjectAtIndex: i-1];
g = [undoStack objectAtIndex: i];
if ([g removeActionsForTarget: target] == NO)
{
[undoStack removeObjectAtIndex: i];
}
}
}
- (NSArray*) runLoopModes
{
return modes;
return modes;
}
- (void) setActionName: (NSString*)name
{
if (name != nil && actionName != name) {
[actionName release];
actionName = [name copy];
if (name != nil && actionName != name)
{
ASSIGNCOPY(actionName, name);
}
}
- (void) setGroupsByEvent: (BOOL)flag
{
if (groupsByEvent != flag) {
groupsByEvent = flag;
if (groupsByEvent != flag)
{
groupsByEvent = flag;
}
}
- (void) setLevelsOfUndo: (unsigned)num
{
levelsOfUndo = num;
if (num > 0) {
while ([undoStack count] > num) {
[undoStack removeObjectAtIndex: 0];
levelsOfUndo = num;
if (num > 0)
{
while ([undoStack count] > num)
{
[undoStack removeObjectAtIndex: 0];
}
while ([redoStack count] > num) {
[redoStack removeObjectAtIndex: 0];
while ([redoStack count] > num)
{
[redoStack removeObjectAtIndex: 0];
}
}
}
- (void) setRunLoopModes: (NSArray*)newModes
{
if (modes != newModes) {
[modes release];
modes = [newModes retain];
[[NSRunLoop currentRunLoop] cancelPerformSelector: @selector(_loop:)
target: self
argument: nil];
[[NSRunLoop currentRunLoop] performSelector: @selector(_loop:)
target: self
argument: nil
order: 0
modes: modes];
if (modes != newModes)
{
ASSIGN(modes, newModes);
[[NSRunLoop currentRunLoop] cancelPerformSelector: @selector(_loop:)
target: self
argument: nil];
[[NSRunLoop currentRunLoop] performSelector: @selector(_loop:)
target: self
argument: nil
order: 0
modes: modes];
}
}
- (void) undo
{
if ([self groupingLevel] == 1) {
[self endUndoGrouping];
if ([self groupingLevel] == 1)
{
[self endUndoGrouping];
}
if (group != nil) {
[NSException raise: NSInternalInconsistencyException
format: @"undo with nested groups"];
if (group != nil)
{
[NSException raise: NSInternalInconsistencyException
format: @"undo with nested groups"];
}
[self undoNestedGroup];
[self undoNestedGroup];
}
- (NSString*) undoActionName
{
if ([self canUndo] == NO) {
return nil;
if ([self canUndo] == NO)
{
return nil;
}
return actionName;
return actionName;
}
- (NSString*) undoMenuItemTitle
{
return [self undoMenuTitleForUndoActionName: [self undoActionName]];
return [self undoMenuTitleForUndoActionName: [self undoActionName]];
}
- (NSString*) undoMenuTitleForUndoActionName: (NSString*)name
{
if (name) {
if ([name isEqual: @""]) {
return @"Undo";
if (name)
{
if ([name isEqual: @""])
{
return @"Undo";
}
else {
return [NSString stringWithFormat: @"Undo %@", name];
else
{
return [NSString stringWithFormat: @"Undo %@", name];
}
}
return name;
return name;
}
- (void) undoNestedGroup
{
PrivateUndoGroup *oldGroup;
PrivateUndoGroup *groupToUndo;
PrivateUndoGroup *oldGroup;
PrivateUndoGroup *groupToUndo;
[[NSNotificationCenter defaultCenter]
postNotificationName: NSUndoManagerCheckpointNotification
object: self];
[[NSNotificationCenter defaultCenter]
postNotificationName: NSUndoManagerCheckpointNotification
object: self];
#if 0
/*
* The documentation says we should raise an exception - but I can't
@ -592,44 +653,49 @@ NSString *NSUndoManagerWillUndoChangeNotification =
* It would make more sense to raise an exception if NO undo operations
* had been registered.
*/
if (registeredUndo) {
[NSException raise: NSInternalInconsistencyException
format: @"undoNestedGroup with registered undo ops"];
if (registeredUndo)
{
[NSException raise: NSInternalInconsistencyException
format: @"undoNestedGroup with registered undo ops"];
}
#endif
if (isUndoing || isRedoing) {
[NSException raise: NSInternalInconsistencyException
format: @"undoNestedGroup while undoing or redoing"];
if (isUndoing || isRedoing)
{
[NSException raise: NSInternalInconsistencyException
format: @"undoNestedGroup while undoing or redoing"];
}
if (group != nil && [undoStack count] == 0)
{
return;
}
if (group != nil && [undoStack count] == 0) {
return;
[[NSNotificationCenter defaultCenter]
postNotificationName: NSUndoManagerWillUndoChangeNotification
object: self];
oldGroup = group;
group = nil;
isUndoing = YES;
if (oldGroup)
{
groupToUndo = oldGroup;
oldGroup = RETAIN([oldGroup parent]);
[groupToUndo orphan];
[redoStack addObject: groupToUndo];
}
[[NSNotificationCenter defaultCenter]
postNotificationName: NSUndoManagerWillUndoChangeNotification
object: self];
oldGroup = group;
group = nil;
isUndoing = YES;
if (oldGroup) {
groupToUndo = oldGroup;
oldGroup = [[oldGroup parent] retain];
[groupToUndo orphan];
[redoStack addObject: groupToUndo];
else
{
groupToUndo = [undoStack objectAtIndex: [undoStack count] - 1];
RETAIN(groupToUndo);
[undoStack removeObjectAtIndex: [undoStack count] - 1];
}
else {
groupToUndo = [undoStack objectAtIndex: [undoStack count] - 1];
[groupToUndo retain];
[undoStack removeObjectAtIndex: [undoStack count] - 1];
}
[self beginUndoGrouping];
[groupToUndo perform];
[groupToUndo release];
[self endUndoGrouping];
isUndoing = NO;
group = oldGroup;
[[NSNotificationCenter defaultCenter]
postNotificationName: NSUndoManagerDidUndoChangeNotification
object: self];
[self beginUndoGrouping];
[groupToUndo perform];
RELEASE(groupToUndo);
[self endUndoGrouping];
isUndoing = NO;
group = oldGroup;
[[NSNotificationCenter defaultCenter]
postNotificationName: NSUndoManagerDidUndoChangeNotification
object: self];
}
@end