mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Fix for singleton stdin,stdout,stderr retention
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@37289 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
bc91e4ee4b
commit
163a0d9601
5 changed files with 72 additions and 32 deletions
|
@ -1,3 +1,12 @@
|
|||
2013-10-27 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/GSFileHandle.m: Fix retention of singletons and add exception
|
||||
if an attempt is made to release too many times.
|
||||
* Tools/make_strings/make_strings.m: fix minor coding standard errrors.
|
||||
* Tests/base/NSFileHandle/basic.m:
|
||||
* Tests/base/NSFileHandle/singleton.m:
|
||||
Correct faulty tests.
|
||||
|
||||
2013-10-26 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSPredicate.m: ([_evaluateLeftValue:rightValue:object:])
|
||||
|
|
|
@ -179,6 +179,24 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
|
|||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (self == fh_stdin)
|
||||
{
|
||||
RETAIN(self);
|
||||
[NSException raise: NSGenericException
|
||||
format: @"Attempt to deallocate standard input handle"];
|
||||
}
|
||||
if (self == fh_stdout)
|
||||
{
|
||||
RETAIN(self);
|
||||
[NSException raise: NSGenericException
|
||||
format: @"Attempt to deallocate standard output handle"];
|
||||
}
|
||||
if (self == fh_stderr)
|
||||
{
|
||||
RETAIN(self);
|
||||
[NSException raise: NSGenericException
|
||||
format: @"Attempt to deallocate standard error handle"];
|
||||
}
|
||||
DESTROY(address);
|
||||
DESTROY(service);
|
||||
DESTROY(protocol);
|
||||
|
@ -192,13 +210,6 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
|
|||
|
||||
- (void) finalize
|
||||
{
|
||||
if (self == fh_stdin)
|
||||
fh_stdin = nil;
|
||||
if (self == fh_stdout)
|
||||
fh_stdout = nil;
|
||||
if (self == fh_stderr)
|
||||
fh_stderr = nil;
|
||||
|
||||
[self ignoreReadDescriptor];
|
||||
[self ignoreWriteDescriptor];
|
||||
|
||||
|
@ -997,7 +1008,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
|||
else
|
||||
{
|
||||
self = [self initWithFileDescriptor: 2 closeOnDealloc: NO];
|
||||
fh_stderr = self;
|
||||
ASSIGN(fh_stderr, self);
|
||||
if (self)
|
||||
{
|
||||
readOK = NO;
|
||||
|
@ -1015,7 +1026,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
|||
else
|
||||
{
|
||||
self = [self initWithFileDescriptor: 0 closeOnDealloc: NO];
|
||||
fh_stdin = self;
|
||||
ASSIGN(fh_stdin, self);
|
||||
if (self)
|
||||
{
|
||||
writeOK = NO;
|
||||
|
@ -1033,7 +1044,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
|||
else
|
||||
{
|
||||
self = [self initWithFileDescriptor: 1 closeOnDealloc: NO];
|
||||
fh_stdout = self;
|
||||
ASSIGN(fh_stdout, self);
|
||||
if (self)
|
||||
{
|
||||
readOK = NO;
|
||||
|
|
|
@ -29,7 +29,7 @@ int main()
|
|||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
test_NSObject(@"NSFileHandle",
|
||||
[NSArray arrayWithObject:[NSFileHandle fileHandleWithStandardInput]]);
|
||||
[NSArray arrayWithObject:[NSFileHandle fileHandleWithStandardInput]]);
|
||||
[arp release]; arp = nil;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,16 +1,30 @@
|
|||
#import "ObjectTesting.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
id a,b,c;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
NSAutoreleasePool *p = [NSAutoreleasePool new];
|
||||
NSZombieEnabled = YES;
|
||||
a = [NSFileHandle fileHandleWithStandardInput];
|
||||
b = [NSFileHandle fileHandleWithStandardOutput];
|
||||
c = [NSFileHandle fileHandleWithStandardError];
|
||||
[p drain];
|
||||
assert(0 != [a description]);
|
||||
assert(0 != [b description]);
|
||||
assert(0 != [c description]);
|
||||
NSAutoreleasePool *p = [NSAutoreleasePool new];
|
||||
NSFileHandle *a;
|
||||
NSFileHandle *b;
|
||||
NSFileHandle *c;
|
||||
|
||||
START_SET("handle creation")
|
||||
a = [NSFileHandle fileHandleWithStandardInput];
|
||||
b = [NSFileHandle fileHandleWithStandardOutput];
|
||||
c = [NSFileHandle fileHandleWithStandardError];
|
||||
END_SET("handle creation")
|
||||
PASS([a retainCount]> 0, "stdin persists");
|
||||
PASS([b retainCount]> 0, "stdout persists");
|
||||
PASS([c retainCount]> 0, "strerr persists");
|
||||
PASS_EXCEPTION([a release], NSGenericException, "Cannot dealloc stdin");
|
||||
PASS_EXCEPTION([b release], NSGenericException, "Cannot dealloc stdout");
|
||||
PASS_EXCEPTION([c release], NSGenericException, "Cannot dealloc stderr");
|
||||
PASS([a retainCount]> 0, "stdin persists");
|
||||
PASS([b retainCount]> 0, "stdout persists");
|
||||
PASS([c retainCount]> 0, "strerr persists");
|
||||
|
||||
[p drain];
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -174,7 +174,7 @@ ParseFile(const char *filename, NSMutableDictionary *tables)
|
|||
ch = nch;
|
||||
if (ch == EOF) break;
|
||||
nch = fgetc(f);
|
||||
// printf("ch = %02x '%c' state =%i skip =%i\n", ch, ch, state, skip);
|
||||
// printf("ch = %02x '%c' state =%i skip =%i\n", ch, ch, state, skip);
|
||||
if (skip)
|
||||
{
|
||||
skip--;
|
||||
|
@ -274,8 +274,9 @@ ParseFile(const char *filename, NSMutableDictionary *tables)
|
|||
old_name = name;
|
||||
for (name++;loc_funcs[name].func_name;name++)
|
||||
{
|
||||
if (!strncmp(loc_funcs[old_name].func_name, loc_funcs[name].func_name, nindex) &&
|
||||
loc_funcs[name].func_name[nindex] == ch)
|
||||
if (!strncmp(loc_funcs[old_name].func_name,
|
||||
loc_funcs[name].func_name, nindex)
|
||||
&& loc_funcs[name].func_name[nindex] == ch)
|
||||
break;
|
||||
}
|
||||
if (loc_funcs[name].func_name)
|
||||
|
@ -289,8 +290,9 @@ ParseFile(const char *filename, NSMutableDictionary *tables)
|
|||
int old_name = name;
|
||||
for (name++;loc_funcs[name].func_name;name++)
|
||||
{
|
||||
if (!strncmp(loc_funcs[old_name].func_name, loc_funcs[name].func_name, nindex) &&
|
||||
loc_funcs[name].func_name[nindex] == 0)
|
||||
if (!strncmp(loc_funcs[old_name].func_name,
|
||||
loc_funcs[name].func_name, nindex)
|
||||
&& loc_funcs[name].func_name[nindex] == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -301,7 +303,9 @@ ParseFile(const char *filename, NSMutableDictionary *tables)
|
|||
}
|
||||
else
|
||||
{
|
||||
// printf("found call to '%s' at line %i\n", loc_funcs[name].func_name, cur_line);
|
||||
/* printf("found call to '%s' at line %i\n",
|
||||
* loc_funcs[name].func_name, cur_line);
|
||||
*/
|
||||
state = 7;
|
||||
}
|
||||
}
|
||||
|
@ -319,9 +323,11 @@ ParseFile(const char *filename, NSMutableDictionary *tables)
|
|||
arg_len[i] = 0;
|
||||
arg_ok[i] = 1;
|
||||
}
|
||||
// printf(" start arg list, want %i args\n", loc_funcs[name].num_args);
|
||||
/* printf(" start arg list, want %i args\n",
|
||||
* loc_funcs[name].num_args);
|
||||
*/
|
||||
}
|
||||
else if (ch>32)
|
||||
else if (ch > 32)
|
||||
state = 0;
|
||||
continue;
|
||||
}
|
||||
|
@ -425,7 +431,7 @@ printf(" %3i : %i '%s'\n", i, arg_ok[i], args[i]);
|
|||
}
|
||||
}
|
||||
|
||||
for (i = 0;i<MAX_ARGS;i++)
|
||||
for (i = 0; i<MAX_ARGS; i++)
|
||||
if (args[i])
|
||||
free(args[i]);
|
||||
|
||||
|
@ -461,7 +467,7 @@ UpdateTable(NSArray *source_table, NSString *filename)
|
|||
sf = [[StringsFile alloc] initWithFile: filename];
|
||||
|
||||
c = [source_table count];
|
||||
for (i = 0;i<c;i++)
|
||||
for (i = 0; i < c; i++)
|
||||
{
|
||||
[sf addSourceEntry: [source_table objectAtIndex: i]];
|
||||
}
|
||||
|
@ -548,8 +554,8 @@ int main(int argc, char **argv)
|
|||
NSLog (@"syntax error\n");
|
||||
return 1;
|
||||
}
|
||||
d = argv[i];
|
||||
while (1)
|
||||
d = argv[i];
|
||||
while (1)
|
||||
{
|
||||
d2 = strchr (d, ' ');
|
||||
if (d2)
|
||||
|
|
Loading…
Reference in a new issue