Updates to move towards ARC

This commit is contained in:
Richard Frith-Macdonald 2020-02-08 16:42:17 +00:00
parent 0cd9843f5f
commit 2e07244f8e
15 changed files with 86 additions and 70 deletions

View file

@ -1,3 +1,22 @@
2020-02-08 Richard Frith-Macdonald <rfm@gnu.org>
* Examples/dictionary.m:
* Examples/nsconnection_client.m:
* Headers/GNUstepBase/GNUstep.h:
* Source/Additions/GSMime.m:
* Source/NSConnection.m:
* Source/NSDictionary.m:
* Source/NSException.m:
* Source/NSFileManager.m:
* Source/NSFileWrapper.m:
* Source/NSTask.m:
* Source/NSUserDefaults.m:
* Tools/AGSIndex.m:
* Tools/AGSOutput.m:
* Tools/cvtenc.m:
Switch various places away from deprecated CREATE_AUTORELEASE_POOL()
to use the ARC-compatible ENTER_POOL and LEAVE_POOL macros.
2020-02-08 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/Foundation/NSXPCConnection.h: Workaround for clash between

View file

@ -19,7 +19,8 @@ int
main()
{
NSMutableDictionary *d;
CREATE_AUTORELEASE_POOL(pool);
ENTER_POOL
/* Create a Dictionary object. */
d = [[NSMutableDictionary alloc] initWithCapacity: 32];
@ -42,6 +43,6 @@ main()
NSLog(@"Now there are %u elements stored in the dictionary\n", [d count]);
DESTROY(pool);
LEAVE_POOL
exit(0);
}

View file

@ -465,13 +465,13 @@ con_callback (id prx)
k = 1000;
for (j = 0; j < k; j++)
{
CREATE_AUTORELEASE_POOL(arp);
ENTER_POOL
[prx unregisterClient: localObj];
[prx registerClient: localObj];
[prx tryClientCallback];
if (j < 10 || j %10 == 0)
printf("repeated client registration and callback %d\n", j);
RELEASE(arp);
LEAVE_POOL
}
printf("repeated client registration and callback %d\n", j);
RELEASE(localObj);

View file

@ -103,8 +103,7 @@
#ifndef RETAIN
/**
* Basic retain operation ... calls [NSObject-retain]<br />
* Deprecated ... pointless on modern processors.
* Simply call the -retain method.
* Does nothing when ARC is in use.
*/
#define RETAIN(object) [(object) retain]
#endif
@ -112,8 +111,7 @@
#ifndef RELEASE
/**
* Basic release operation ... calls [NSObject-release]<br />
* Deprecated ... pointless on modern processors.
* Simply call the -release method.
* Does nothing when ARC is in use.
*/
#define RELEASE(object) [(object) release]
#endif
@ -121,8 +119,7 @@
#ifndef AUTORELEASE
/**
* Basic autorelease operation ... calls [NSObject-autorelease]<br />
* Deprecated ... pointless on modern processors.
* Simply call the -autorelease method.
* Does nothing when ARC is in use.
*/
#define AUTORELEASE(object) [(object) autorelease]
#endif
@ -131,8 +128,7 @@
/**
* Tested retain - only invoke the
* objective-c method if the receiver is not nil.<br />
* Deprecated ... pointless on modern processors.
* Simply call the -retain method.
* Does nothing when ARC is in use.
*/
#define TEST_RETAIN(object) ({\
id __object = (object); (__object != nil) ? [__object retain] : nil; })
@ -142,8 +138,7 @@ id __object = (object); (__object != nil) ? [__object retain] : nil; })
/**
* Tested release - only invoke the
* objective-c method if the receiver is not nil.<br />
* Deprecated ... pointless on modern processors.
* Simply call the -release method.
* Does nothing when ARC is in use.
*/
#define TEST_RELEASE(object) ({\
id __object = (object); if (__object != nil) [__object release]; })
@ -153,8 +148,7 @@ id __object = (object); if (__object != nil) [__object release]; })
/**
* Tested autorelease - only invoke the
* objective-c method if the receiver is not nil.<br />
* Deprecated ... pointless on modern processors.
* Simply call the -autorelease method.
* Does nothing when ARC is in use.
*/
#define TEST_AUTORELEASE(object) ({\
id __object = (object); (__object != nil) ? [__object autorelease] : nil; })

View file

@ -6268,14 +6268,14 @@ appendString(NSMutableData *m, NSUInteger offset, NSUInteger fold,
- (NSString*) description
{
CREATE_AUTORELEASE_POOL(arp);
NSMutableString *m;
NSString *s;
m = [NSMutableString stringWithCapacity: 1000];
ENTER_POOL
NSMutableString *m = [NSMutableString stringWithCapacity: 1000];
[self _descriptionTo: m level: 0];
s = RETAIN(m);
RELEASE(arp);
LEAVE_POOL
return AUTORELEASE(s);
}
@ -7390,7 +7390,7 @@ appendString(NSMutableData *m, NSUInteger offset, NSUInteger fold,
- (void) encodePart: (GSMimeDocument*)document to: (NSMutableData*)md
{
CREATE_AUTORELEASE_POOL(arp);
ENTER_POOL
NSData *d = nil;
NSEnumerator *enumerator;
NSString *subtype;
@ -7813,7 +7813,7 @@ appendString(NSMutableData *m, NSUInteger offset, NSUInteger fold,
[md appendData: d];
}
}
RELEASE(arp);
LEAVE_POOL
}
- (NSUInteger) foldAt

View file

@ -335,7 +335,7 @@ GS_PRIVATE_INTERNAL(NSConnection)
- (void) removeLocalObject: (NSDistantObject*)anObj;
- (void) _doneInReply: (NSPortCoder*)c;
- (void) _doneInRmc: (NSPortCoder*)c;
- (void) _doneInRmc: (NSPortCoder*) NS_CONSUMED c;
- (void) _failInRmc: (NSPortCoder*)c;
- (void) _failOutRmc: (NSPortCoder*)c;
- (NSPortCoder*) _getReplyRmc: (int)sn for: (const char*)request;

View file

@ -960,11 +960,11 @@ compareIt(id o1, id o2, void* context)
- (NSArray *) keysSortedByValueWithOptions: (NSSortOptions)opts
usingComparator: (NSComparator)cmptr
{
CREATE_AUTORELEASE_POOL(arp);
NSArray *sortedValues;
NSArray *noDuplicates;
NSMutableArray *result;
ENTER_POOL
sortedValues = [[self allValues] sortedArrayWithOptions: opts
usingComparator: cmptr];
noDuplicates = [[NSOrderedSet orderedSetWithArray: sortedValues] array];
@ -972,7 +972,7 @@ compareIt(id o1, id o2, void* context)
FOR_IN(NSObject*, value, noDuplicates)
[result addObjectsFromArray: [self allKeysForObject: value]];
END_FOR_IN(noDuplicates)
RELEASE(arp);
LEAVE_POOL
return AUTORELEASE(result);
}

View file

@ -1101,7 +1101,7 @@ GSPrivateReturnAddresses(NSUInteger **returns)
{
if (nil == addresses && numReturns > FrameOffset)
{
CREATE_AUTORELEASE_POOL(pool);
ENTER_POOL
NSInteger count = numReturns - FrameOffset;
NSValue *objects[count];
NSUInteger index;
@ -1112,7 +1112,7 @@ GSPrivateReturnAddresses(NSUInteger **returns)
objects[index] = [NSValue valueWithPointer: ptrs[FrameOffset+index]];
}
addresses = [[NSArray alloc] initWithObjects: objects count: count];
DESTROY(pool);
LEAVE_POOL
}
return addresses;
}

View file

@ -688,7 +688,7 @@ static NSStringEncoding defaultEncoding;
NSString *n = [a1 objectAtIndex: index];
NSString *p1;
NSString *p2;
CREATE_AUTORELEASE_POOL(pool);
ENTER_POOL
p1 = [path1 stringByAppendingPathComponent: n];
p2 = [path2 stringByAppendingPathComponent: n];
@ -704,7 +704,7 @@ static NSStringEncoding defaultEncoding;
{
ok = [self contentsEqualAtPath: p1 andPath: p2];
}
RELEASE(pool);
LEAVE_POOL
}
return ok;
}
@ -1609,12 +1609,12 @@ static NSStringEncoding defaultEncoding;
NSString *item;
NSString *next;
BOOL result;
CREATE_AUTORELEASE_POOL(pool);
ENTER_POOL
item = [contents objectAtIndex: i];
next = [path stringByAppendingPathComponent: item];
result = [self removeFileAtPath: next handler: handler];
RELEASE(pool);
LEAVE_POOL
if (result == NO)
{
return NO;
@ -3187,7 +3187,8 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
{
NSDirectoryEnumerator *enumerator;
NSString *dirEntry;
CREATE_AUTORELEASE_POOL(pool);
BOOL result = YES;
ENTER_POOL
enumerator = [self enumeratorAtPath: source];
while ((dirEntry = [enumerator nextObject]))
@ -3227,8 +3228,8 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
fromPath: sourceFile
toPath: destinationFile])
{
RELEASE(pool);
return NO;
result = NO;
break;
}
/*
* We may have managed to create the directory but not set
@ -3246,8 +3247,8 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
toPath: destinationFile
handler: handler])
{
RELEASE(pool);
return NO;
result = NO;
break;
}
}
}
@ -3257,8 +3258,8 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
toFile: destinationFile
handler: handler])
{
RELEASE(pool);
return NO;
result = NO;
break;
}
}
else if ([fileType isEqual: NSFileTypeSymbolicLink])
@ -3275,8 +3276,8 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
fromPath: sourceFile
toPath: destinationFile])
{
RELEASE(pool);
return NO;
result = NO;
break;
}
}
}
@ -3292,9 +3293,9 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
}
[self changeFileAttributes: attributes atPath: destinationFile];
}
RELEASE(pool);
LEAVE_POOL
return YES;
return result;
}
- (BOOL) _linkPath: (NSString*)source
@ -3304,7 +3305,8 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
#ifdef HAVE_LINK
NSDirectoryEnumerator *enumerator;
NSString *dirEntry;
CREATE_AUTORELEASE_POOL(pool);
BOOL result = YES;
ENTER_POOL
enumerator = [self enumeratorAtPath: source];
while ((dirEntry = [enumerator nextObject]))
@ -3333,8 +3335,8 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
fromPath: sourceFile
toPath: destinationFile] == NO)
{
RELEASE(pool);
return NO;
result = NO;
break;
}
}
else
@ -3344,8 +3346,8 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
toPath: destinationFile
handler: handler] == NO)
{
RELEASE(pool);
return NO;
result = NO;
break;
}
}
}
@ -3363,8 +3365,8 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
fromPath: sourceFile
toPath: destinationFile] == NO)
{
RELEASE(pool);
return NO;
result = NO;
break;
}
}
}
@ -3379,15 +3381,15 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
fromPath: sourceFile
toPath: destinationFile] == NO)
{
RELEASE(pool);
return NO;
result = NO;
break;
}
}
}
[self changeFileAttributes: attributes atPath: destinationFile];
}
RELEASE(pool);
return YES;
LEAVE_POOL
return result;
#else
ASSIGN(_lastError, @"Links not supported on this platform");
return NO;

View file

@ -114,10 +114,10 @@
*/
- (id) initWithPath: (NSString*)path
{
CREATE_AUTORELEASE_POOL(arp);
ENTER_POOL
NSFileManager *fm = [NSFileManager defaultManager];
NSDictionary *fileAttributes;
NSString *fileType;
NSDictionary *fileAttributes;
NSString *fileType;
NSDebugLLog(@"NSFileWrapper", @"initWithPath: %@", path);
@ -158,7 +158,7 @@
[self setPreferredFilename: [path lastPathComponent]];
[self setFileAttributes: fileAttributes];
[arp drain];
LEAVE_POOL
return self;
}

View file

@ -845,7 +845,7 @@ pty_slave(const char* name)
*/
- (void) waitUntilExit
{
CREATE_AUTORELEASE_POOL(arp);
ENTER_POOL
NSRunLoop *loop = [NSRunLoop currentRunLoop];
NSTimer *timer = nil;
NSDate *limit = nil;
@ -874,7 +874,7 @@ pty_slave(const char* name)
*/
limit = [NSDate dateWithTimeIntervalSinceNow: 0.0];
[loop runMode: NSDefaultRunLoopMode beforeDate: limit];
IF_NO_GC([arp release];)
LEAVE_POOL
}
@end

View file

@ -566,7 +566,7 @@ newLanguages(NSArray *oldNames)
{
if (self == [NSUserDefaults class])
{
CREATE_AUTORELEASE_POOL(pool);
ENTER_POOL
NSEnumerator *enumerator;
NSArray *args;
NSString *key;
@ -655,7 +655,7 @@ newLanguages(NSArray *oldNames)
syncLock = [NSLock new];
[self _createArgumentDictionary: args];
DESTROY(pool);
LEAVE_POOL
}
}
@ -2356,7 +2356,6 @@ static BOOL isLocked = NO;
while ([_fileLock tryLock] == NO)
{
CREATE_AUTORELEASE_POOL(arp);
NSDate *lockDate;
/*
@ -2369,10 +2368,11 @@ static BOOL isLocked = NO;
{
fprintf(stderr, "Failed to lock user defaults database"
" even after breaking old locks!\n");
RELEASE(arp);
break;
}
ENTER_POOL
/* If lockDate is nil, we should be able to lock again ... but we
* wait a little anyway ... so that in the case of a locking
* problem we do an idle wait rather than a busy one.
@ -2388,7 +2388,7 @@ static BOOL isLocked = NO;
{
[NSThread sleepForTimeInterval: 0.1];
}
RELEASE(arp);
LEAVE_POOL;
}
isLocked = YES;
}

View file

@ -540,9 +540,9 @@ setDirectory(NSMutableDictionary *dict, NSString *path)
{
if (path != nil)
{
CREATE_AUTORELEASE_POOL(pool);
ENTER_POOL
setDirectory(refs, path);
[pool drain];
LEAVE_POOL
}
}

View file

@ -1354,7 +1354,7 @@ static BOOL snuggleStart(NSString *t)
withIndent: (unsigned)ind
to: (NSMutableString*)buf
{
CREATE_AUTORELEASE_POOL(arp);
ENTER_POOL
unsigned l = [str length];
NSRange r = [str rangeOfString: @"<example"];
unsigned i = 0;
@ -1472,7 +1472,7 @@ static BOOL snuggleStart(NSString *t)
[buf appendString: @"\n"];
}
}
[arp drain];
LEAVE_POOL
return ind;
}

View file

@ -317,12 +317,12 @@ main(int argc, char** argv, char **env)
else
{
NSFileHandle *out;
CREATE_AUTORELEASE_POOL(arp);
ENTER_POOL
out = [NSFileHandle fileHandleWithStandardOutput];
[out writeData: myData];
[out synchronizeFile];
RELEASE(arp);
LEAVE_POOL
}
}
}