mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +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
1ddff14944
commit
5e95fdf285
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
|
||||||
|
|
|
@ -1724,7 +1724,7 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
|
||||||
*/
|
*/
|
||||||
- (NSDate*) limitDateForMode: (NSString*)mode
|
- (NSDate*) limitDateForMode: (NSString*)mode
|
||||||
{
|
{
|
||||||
extern NSTimer *GSHousekeeper(void);
|
extern NSTimer *GSHousekeeper(void);
|
||||||
GSRunLoopCtxt *context = NSMapGet(_contextMap, mode);
|
GSRunLoopCtxt *context = NSMapGet(_contextMap, mode);
|
||||||
NSDate *when = nil;
|
NSDate *when = nil;
|
||||||
|
|
||||||
|
@ -1742,7 +1742,8 @@ 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);
|
||||||
|
@ -1863,7 +1866,7 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
|
||||||
}
|
}
|
||||||
if (GSIArrayCount(timers) == 1)
|
if (GSIArrayCount(timers) == 1)
|
||||||
{
|
{
|
||||||
DESTROY(when);
|
DESTROY(when);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,7 +1897,9 @@ 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)
|
||||||
{
|
{
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
203
Tools/pl.m
203
Tools/pl.m
|
@ -29,134 +29,139 @@
|
||||||
|
|
||||||
#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];
|
||||||
NSArray *arguments = [processInfo arguments];
|
NSArray *arguments = [processInfo arguments];
|
||||||
int outputIndex = 0;
|
int outputIndex = 0;
|
||||||
|
|
||||||
// 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;
|
||||||
|
|
||||||
// setup the file handle.
|
outputData = [NSData dataWithBytes: buffer length: strlen(buffer)];
|
||||||
fileHandle = [NSFileHandle fileHandleWithStandardOutput];
|
// setup the file handle.
|
||||||
// Send the data to stdout
|
fileHandle = [NSFileHandle fileHandleWithStandardOutput];
|
||||||
[fileHandle writeData: outputData];
|
// Send the data to stdout
|
||||||
puts("\n");
|
[fileHandle writeData: outputData];
|
||||||
|
puts("\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NSData *serializedData = nil;
|
NSData *serializedData = nil;
|
||||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||||
|
|
||||||
// Write in the serialized plist.
|
// Write in the serialized plist.
|
||||||
serializedData = [NSSerializer serializePropertyList: propertyList];
|
serializedData = [NSSerializer serializePropertyList: propertyList];
|
||||||
[fileManager createFileAtPath: [arguments objectAtIndex: outputIndex+1]
|
[fileManager createFileAtPath: [arguments objectAtIndex: outputIndex+1]
|
||||||
contents: serializedData
|
contents: serializedData
|
||||||
attributes: nil];
|
attributes: nil];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
id process_plist( NSData *inputData )
|
id process_plist(NSData *inputData)
|
||||||
{
|
{
|
||||||
id propertyList = nil;
|
id propertyList = nil;
|
||||||
NSString *string = nil;
|
NSString *string = nil;
|
||||||
|
|
||||||
// Initialize a string with the contents of the file.
|
// Initialize a string with the contents of the file.
|
||||||
string = [NSString stringWithCString: (char *)[inputData bytes]];
|
string = [NSString stringWithCString: (char *)[inputData bytes]];
|
||||||
|
|
||||||
// Convert the string into a property list. If there is a parsing error
|
// Convert the string into a property list. If there is a parsing error
|
||||||
// the property list interpreter will throw an exception.
|
// the property list interpreter will throw an exception.
|
||||||
NS_DURING
|
NS_DURING
|
||||||
propertyList = [string propertyList];
|
propertyList = [string propertyList];
|
||||||
NS_HANDLER
|
NS_HANDLER
|
||||||
NSLog([localException description]);
|
NSLog([localException description]);
|
||||||
NS_ENDHANDLER
|
NS_ENDHANDLER
|
||||||
|
|
||||||
// return the results
|
// return the results
|
||||||
return propertyList;
|
return propertyList;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSData *read_input()
|
NSData *read_input()
|
||||||
{
|
{
|
||||||
NSData *inputData = nil;
|
NSData *inputData = nil;
|
||||||
NSFileHandle *fileHandle = nil;
|
NSFileHandle *fileHandle = nil;
|
||||||
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
|
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
|
||||||
NSArray *arguments = [processInfo arguments];
|
NSArray *arguments = [processInfo arguments];
|
||||||
int inputIndex = 0;
|
int inputIndex = 0;
|
||||||
|
|
||||||
// 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];
|
||||||
// Read in the input from the file.
|
// Read in the input from the file.
|
||||||
inputData = [fileHandle readDataToEndOfFile];
|
inputData = [fileHandle readDataToEndOfFile];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NSData *serializedData = nil;
|
NSData *serializedData = nil;
|
||||||
id propertyList = nil;
|
id propertyList = nil;
|
||||||
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:
|
||||||
// read in the serialized plist.
|
[arguments objectAtIndex: inputIndex+1]];
|
||||||
serializedData = [fileHandle readDataToEndOfFile];
|
// read in the serialized plist.
|
||||||
[fileHandle closeFile];
|
serializedData = [fileHandle readDataToEndOfFile];
|
||||||
propertyList = [NSDeserializer deserializePropertyListFromData: serializedData
|
[fileHandle closeFile];
|
||||||
mutableContainers: NO];
|
propertyList = [NSDeserializer deserializePropertyListFromData:
|
||||||
if( propertyList != nil )
|
serializedData mutableContainers: NO];
|
||||||
{
|
if (propertyList != nil)
|
||||||
buffer = (char *)[[propertyList description] cString];
|
{
|
||||||
inputData = [NSData dataWithBytes: buffer length: strlen(buffer)];
|
buffer = (char *)[[propertyList description] cString];
|
||||||
}
|
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]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return inputData;
|
return inputData;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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(
|
||||||
puts(" if -input is specified.");
|
" - Reads an ASCII property list from standard in, or a serialized one");
|
||||||
puts(" - Writes an ASCII propert list to standard out, or a serialized one");
|
puts(" if -input is specified.");
|
||||||
puts(" if -output is specified.");
|
puts(
|
||||||
|
" - Writes an ASCII propert list to standard out, or a serialized one");
|
||||||
|
puts(" if -output is specified.");
|
||||||
}
|
}
|
||||||
|
|
||||||
[pool release];
|
[pool release];
|
||||||
exit(0); // insure the process exit status is 0
|
exit(0); // insure the process exit status is 0
|
||||||
return 0; // ...and make main fit the ANSI spec.
|
return 0; // ...and make main fit the ANSI spec.
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue