mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-01 09:02:01 +00:00
Memory leak fix and tidyup
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@20360 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
fe0e08aba9
commit
c6ac02ff60
3 changed files with 131 additions and 110 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
2004-11-19 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Tools/pl.m: Make code conform to gnu coding standards.
|
||||||
|
* Source/NSRunLoop.m: ([runMode:beforeDate:]) add autorelease pool
|
||||||
|
to retain old behavior where anything inside a runloop is
|
||||||
|
automatically in the scope of an autorelease pool, and will not
|
||||||
|
be leaked by autoreleasing. Fixes obscure problems with the last
|
||||||
|
limitDateForMode changes.
|
||||||
|
|
||||||
2004-11-18 Gregory John Casamento <greg_casamento@yahoo.com>
|
2004-11-18 Gregory John Casamento <greg_casamento@yahoo.com>
|
||||||
|
|
||||||
* Tools/pl.m: Added a tool I wrote a while back which is an
|
* Tools/pl.m: Added a tool I wrote a while back which is an
|
||||||
|
|
|
@ -1743,6 +1743,7 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
|
||||||
while (GSIArrayCount(timers) != 0)
|
while (GSIArrayCount(timers) != 0)
|
||||||
{
|
{
|
||||||
NSTimer *min_timer = GSIArrayItemAtIndex(timers, 0).obj;
|
NSTimer *min_timer = GSIArrayItemAtIndex(timers, 0).obj;
|
||||||
|
|
||||||
if (timerInvalidated(min_timer) == YES)
|
if (timerInvalidated(min_timer) == YES)
|
||||||
{
|
{
|
||||||
GSIArrayRemoveItemAtIndex(timers, 0);
|
GSIArrayRemoveItemAtIndex(timers, 0);
|
||||||
|
@ -1750,9 +1751,10 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!when)
|
if (when == nil)
|
||||||
|
{
|
||||||
when = [timerDate(min_timer) copy];
|
when = [timerDate(min_timer) copy];
|
||||||
|
}
|
||||||
if ([timerDate(min_timer) timeIntervalSinceNow] > 0)
|
if ([timerDate(min_timer) timeIntervalSinceNow] > 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
@ -1849,13 +1851,14 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
|
||||||
* that the housekeeper timer does not keep the runloop
|
* that the housekeeper timer does not keep the runloop
|
||||||
* active. It's a special case set up in NSThread.m
|
* active. It's a special case set up in NSThread.m
|
||||||
*/
|
*/
|
||||||
if (min_watcher == nil && when)
|
if (min_watcher == nil && when != nil)
|
||||||
{
|
{
|
||||||
unsigned count = GSIArrayCount(timers);
|
unsigned count = GSIArrayCount(timers);
|
||||||
|
|
||||||
while (count-- > 1)
|
while (count-- > 1)
|
||||||
{
|
{
|
||||||
NSTimer *tmp = GSIArrayItemAtIndex(timers, 0).obj;
|
NSTimer *tmp = GSIArrayItemAtIndex(timers, 0).obj;
|
||||||
|
|
||||||
if (timerInvalidated(tmp) == YES)
|
if (timerInvalidated(tmp) == YES)
|
||||||
{
|
{
|
||||||
GSIArrayRemoveItemAtIndex(timers, count);
|
GSIArrayRemoveItemAtIndex(timers, count);
|
||||||
|
@ -1885,7 +1888,7 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
|
||||||
* watcher (or leave it as the date of the earliest timer if that is
|
* watcher (or leave it as the date of the earliest timer if that is
|
||||||
* before the watchers limit).
|
* before the watchers limit).
|
||||||
*/
|
*/
|
||||||
if (when)
|
if (when != nil)
|
||||||
{
|
{
|
||||||
if (min_watcher != nil
|
if (min_watcher != nil
|
||||||
&& [min_watcher->_date compare: when] == NSOrderedAscending)
|
&& [min_watcher->_date compare: when] == NSOrderedAscending)
|
||||||
|
@ -1894,8 +1897,10 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
|
||||||
when = min_watcher->_date;
|
when = min_watcher->_date;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
AUTORELEASE(when);
|
AUTORELEASE(when);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (min_watcher != nil)
|
else if (min_watcher != nil)
|
||||||
{
|
{
|
||||||
when = min_watcher->_date;
|
when = min_watcher->_date;
|
||||||
|
@ -2030,7 +2035,8 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
|
||||||
*/
|
*/
|
||||||
- (BOOL) runMode: (NSString*)mode beforeDate: (NSDate*)date
|
- (BOOL) runMode: (NSString*)mode beforeDate: (NSDate*)date
|
||||||
{
|
{
|
||||||
id d;
|
CREATE_AUTORELEASE_POOL(arp);
|
||||||
|
NSDate *d;
|
||||||
|
|
||||||
NSAssert(mode != nil, NSInvalidArgumentException);
|
NSAssert(mode != nil, NSInvalidArgumentException);
|
||||||
|
|
||||||
|
@ -2046,6 +2052,7 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
|
||||||
{
|
{
|
||||||
GSNotifyASAP();
|
GSNotifyASAP();
|
||||||
}
|
}
|
||||||
|
RELEASE(arp);
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2064,7 +2071,7 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
|
||||||
[self acceptInputForMode: mode beforeDate: d];
|
[self acceptInputForMode: mode beforeDate: d];
|
||||||
|
|
||||||
RELEASE(d);
|
RELEASE(d);
|
||||||
|
RELEASE(arp);
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
37
Tools/pl.m
37
Tools/pl.m
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
void create_output( id propertyList )
|
void create_output(id propertyList)
|
||||||
{
|
{
|
||||||
NSFileHandle *fileHandle = nil;
|
NSFileHandle *fileHandle = nil;
|
||||||
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
|
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
|
||||||
|
@ -38,11 +38,12 @@ void create_output( id propertyList )
|
||||||
|
|
||||||
// insert your code here
|
// insert your code here
|
||||||
outputIndex = [arguments indexOfObject: @"-output"];
|
outputIndex = [arguments indexOfObject: @"-output"];
|
||||||
if( outputIndex == NSNotFound )
|
if (outputIndex == NSNotFound)
|
||||||
{
|
{
|
||||||
const char *buffer = [[propertyList description] cString];
|
const char *buffer = [[propertyList description] cString];
|
||||||
NSData *outputData = [NSData dataWithBytes: buffer length: strlen(buffer)];
|
NSData *outputData;
|
||||||
|
|
||||||
|
outputData = [NSData dataWithBytes: buffer length: strlen(buffer)];
|
||||||
// setup the file handle.
|
// setup the file handle.
|
||||||
fileHandle = [NSFileHandle fileHandleWithStandardOutput];
|
fileHandle = [NSFileHandle fileHandleWithStandardOutput];
|
||||||
// Send the data to stdout
|
// Send the data to stdout
|
||||||
|
@ -62,7 +63,7 @@ void create_output( id propertyList )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
id process_plist( NSData *inputData )
|
id process_plist(NSData *inputData)
|
||||||
{
|
{
|
||||||
id propertyList = nil;
|
id propertyList = nil;
|
||||||
NSString *string = nil;
|
NSString *string = nil;
|
||||||
|
@ -92,7 +93,7 @@ NSData *read_input()
|
||||||
|
|
||||||
// insert your code here
|
// insert your code here
|
||||||
inputIndex = [arguments indexOfObject: @"-input"];
|
inputIndex = [arguments indexOfObject: @"-input"];
|
||||||
if( inputIndex == NSNotFound )
|
if (inputIndex == NSNotFound)
|
||||||
{
|
{
|
||||||
// setup the file handle.
|
// setup the file handle.
|
||||||
fileHandle = [NSFileHandle fileHandleWithStandardInput];
|
fileHandle = [NSFileHandle fileHandleWithStandardInput];
|
||||||
|
@ -106,20 +107,22 @@ NSData *read_input()
|
||||||
char *buffer = 0;
|
char *buffer = 0;
|
||||||
|
|
||||||
// set up the file handle.
|
// set up the file handle.
|
||||||
fileHandle = [NSFileHandle fileHandleForReadingAtPath: [arguments objectAtIndex: inputIndex+1]];
|
fileHandle = [NSFileHandle fileHandleForReadingAtPath:
|
||||||
|
[arguments objectAtIndex: inputIndex+1]];
|
||||||
// read in the serialized plist.
|
// read in the serialized plist.
|
||||||
serializedData = [fileHandle readDataToEndOfFile];
|
serializedData = [fileHandle readDataToEndOfFile];
|
||||||
[fileHandle closeFile];
|
[fileHandle closeFile];
|
||||||
propertyList = [NSDeserializer deserializePropertyListFromData: serializedData
|
propertyList = [NSDeserializer deserializePropertyListFromData:
|
||||||
mutableContainers: NO];
|
serializedData mutableContainers: NO];
|
||||||
if( propertyList != nil )
|
if (propertyList != nil)
|
||||||
{
|
{
|
||||||
buffer = (char *)[[propertyList description] cString];
|
buffer = (char *)[[propertyList description] cString];
|
||||||
inputData = [NSData dataWithBytes: buffer length: strlen(buffer)];
|
inputData = [NSData dataWithBytes: buffer length: strlen(buffer)];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NSLog(@"%@ is not a serialized property list.", [arguments objectAtIndex: inputIndex+1]);
|
NSLog(@"%@ is not a serialized property list.",
|
||||||
|
[arguments objectAtIndex: inputIndex+1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,19 +131,19 @@ NSData *read_input()
|
||||||
|
|
||||||
int main (int argc, const char *argv[])
|
int main (int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
NSData *inputData = nil;
|
NSData *inputData = nil;
|
||||||
id propertyList = nil;
|
id propertyList = nil;
|
||||||
|
|
||||||
// put your code here.
|
// put your code here.
|
||||||
if(argc == 1 || argc == 3|| argc == 5)
|
if (argc == 1 || argc == 3|| argc == 5)
|
||||||
{
|
{
|
||||||
inputData = read_input();
|
inputData = read_input();
|
||||||
if( inputData != nil )
|
if (inputData != nil)
|
||||||
{
|
{
|
||||||
// If the input data was sucessfully read...
|
// If the input data was sucessfully read...
|
||||||
propertyList = process_plist( inputData );
|
propertyList = process_plist( inputData );
|
||||||
if( propertyList != nil )
|
if (propertyList != nil)
|
||||||
{
|
{
|
||||||
// If the property list was okay...
|
// If the property list was okay...
|
||||||
create_output( propertyList );
|
create_output( propertyList );
|
||||||
|
@ -150,9 +153,11 @@ int main (int argc, const char *argv[])
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
puts("pl {-input <serialized_file>} {-output <serialized_file>}");
|
puts("pl {-input <serialized_file>} {-output <serialized_file>}");
|
||||||
puts(" - Reads an ASCII property list from standard in, or a serialized one");
|
puts(
|
||||||
|
" - Reads an ASCII property list from standard in, or a serialized one");
|
||||||
puts(" if -input is specified.");
|
puts(" if -input is specified.");
|
||||||
puts(" - Writes an ASCII propert list to standard out, or a serialized one");
|
puts(
|
||||||
|
" - Writes an ASCII propert list to standard out, or a serialized one");
|
||||||
puts(" if -output is specified.");
|
puts(" if -output is specified.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue