mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 00:11:26 +00:00
Fixes from Frith-MacDonald.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2781 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
097ee73e95
commit
a29048c198
9 changed files with 229 additions and 30 deletions
|
@ -525,7 +525,7 @@ static id long_day[7] = {@"Sunday",
|
|||
oldOffset = [time_zone timeZoneSecondsFromGMT];
|
||||
time_zone = z;
|
||||
newOffset = [time_zone timeZoneSecondsFromGMT];
|
||||
s += oldOffset - newOffset;
|
||||
s += newOffset - oldOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -271,6 +271,18 @@ static int debug_run_loop = 0;
|
|||
@end
|
||||
|
||||
|
||||
|
||||
@interface NSRunLoop (TimedPerformers)
|
||||
- (NSMutableArray*) _timedPerformers;
|
||||
@end
|
||||
|
||||
@implementation NSRunLoop (TimedPerformers)
|
||||
- (NSMutableArray*) _timedPerformers
|
||||
{
|
||||
return _timedPerformers;
|
||||
}
|
||||
@end
|
||||
|
||||
/*
|
||||
* The RunLoopPerformer class is used to hold information about
|
||||
* messages which are due to be sent to objects once a particular
|
||||
|
@ -282,7 +294,8 @@ static int debug_run_loop = 0;
|
|||
id target;
|
||||
id argument;
|
||||
unsigned order;
|
||||
NSArray* modes;
|
||||
NSArray *modes;
|
||||
NSTimer *timer;
|
||||
}
|
||||
|
||||
- (void) fire;
|
||||
|
@ -296,12 +309,14 @@ static int debug_run_loop = 0;
|
|||
argument: anArgument;
|
||||
- (NSArray*) modes;
|
||||
- (unsigned int) order;
|
||||
- (void) setTimer: (NSTimer*)timer;
|
||||
@end
|
||||
|
||||
@implementation RunLoopPerformer
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[timer invalidate];
|
||||
[target release];
|
||||
[argument release];
|
||||
[modes release];
|
||||
|
@ -310,7 +325,13 @@ static int debug_run_loop = 0;
|
|||
|
||||
- (void)fire
|
||||
{
|
||||
[target perform:selector withObject:argument];
|
||||
if (timer != nil) {
|
||||
timer = nil;
|
||||
[[self retain] autorelease];
|
||||
[[[NSRunLoop currentInstance] _timedPerformers]
|
||||
removeObjectIdenticalTo: self];
|
||||
}
|
||||
[target perform: selector withObject: argument];
|
||||
}
|
||||
|
||||
- initWithSelector: (SEL)aSelector
|
||||
|
@ -351,6 +372,91 @@ static int debug_run_loop = 0;
|
|||
return order;
|
||||
}
|
||||
|
||||
- (void) setTimer: (NSTimer*)t
|
||||
{
|
||||
timer = t;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation NSObject (TimedPerformers)
|
||||
|
||||
+ (void) cancelPreviousPerformRequestsWithTarget: (id)target
|
||||
selector: (SEL)aSelector
|
||||
object: (id)arg
|
||||
{
|
||||
NSMutableArray *array;
|
||||
int i;
|
||||
|
||||
[target retain];
|
||||
[arg retain];
|
||||
array = [[NSRunLoop currentInstance] _timedPerformers];
|
||||
for (i = [array count]; i > 0; i--) {
|
||||
if ([[array objectAtIndex: i-1] matchesSelector: aSelector
|
||||
target: target
|
||||
argument: arg]) {
|
||||
[array removeObjectAtIndex: i-1];
|
||||
}
|
||||
}
|
||||
[arg release];
|
||||
[target release];
|
||||
}
|
||||
|
||||
- (void) performSelector: (SEL)aSelector
|
||||
withObject: (id)argument
|
||||
afterDelay: (NSTimeInterval)seconds
|
||||
{
|
||||
NSMutableArray *array;
|
||||
RunLoopPerformer *item;
|
||||
|
||||
array = [[NSRunLoop currentInstance] _timedPerformers];
|
||||
item = [[RunLoopPerformer alloc] initWithSelector: aSelector
|
||||
target: self
|
||||
argument: argument
|
||||
order: 0
|
||||
modes: nil];
|
||||
[array addObject: item];
|
||||
[item setTimer: [NSTimer scheduledTimerWithTimeInterval: seconds
|
||||
target: item
|
||||
selector: @selector(fire)
|
||||
userInfo: nil
|
||||
repeats: NO]];
|
||||
[item release];
|
||||
}
|
||||
|
||||
- (void) performSelector: (SEL)aSelector
|
||||
withObject: (id)argument
|
||||
afterDelay: (NSTimeInterval)seconds
|
||||
inModes: (NSArray*)modes
|
||||
{
|
||||
NSRunLoop *loop;
|
||||
NSMutableArray *array;
|
||||
RunLoopPerformer *item;
|
||||
NSTimer *timer;
|
||||
int i;
|
||||
|
||||
if (modes == nil || [modes count] == 0) {
|
||||
return;
|
||||
}
|
||||
loop = [NSRunLoop currentInstance];
|
||||
array = [loop _timedPerformers];
|
||||
item = [[RunLoopPerformer alloc] initWithSelector: aSelector
|
||||
target: self
|
||||
argument: argument
|
||||
order: 0
|
||||
modes: nil];
|
||||
[array addObject: item];
|
||||
timer = [NSTimer timerWithTimeInterval: seconds
|
||||
target: item
|
||||
selector: @selector(fire)
|
||||
userInfo: nil
|
||||
repeats: NO];
|
||||
[item setTimer: timer];
|
||||
[item release];
|
||||
for (i = 0; i < [modes count]; i++) {
|
||||
[loop addTimer: timer forMode: [modes objectAtIndex: i]];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
@ -362,6 +468,7 @@ static int debug_run_loop = 0;
|
|||
- (RunLoopWatcher*) _getWatcher: (void*)data
|
||||
type: (RunLoopEventType)type
|
||||
forMode: (NSString*)mode;
|
||||
- (NSMutableArray*) _performers;
|
||||
- (void) _removeWatcher: (void*)data
|
||||
type: (RunLoopEventType)type
|
||||
forMode: (NSString*)mode;
|
||||
|
@ -430,17 +537,20 @@ static int debug_run_loop = 0;
|
|||
- (void) _checkPerformers
|
||||
{
|
||||
RunLoopPerformer *item;
|
||||
int count = [_performers count];
|
||||
NSArray *array = [NSArray arrayWithArray: _performers];
|
||||
int count = [array count];
|
||||
unsigned pos;
|
||||
int i;
|
||||
|
||||
for (i = count; i > 0; i++) {
|
||||
item = (RunLoopPerformer*)[_performers objectAtIndex:(i-1)];
|
||||
for (i = 0; i < count; i++) {
|
||||
item = (RunLoopPerformer*)[array objectAtIndex: i];
|
||||
|
||||
if ([[item modes] containsObject: _current_mode]) {
|
||||
[item retain];
|
||||
[_performers removeObjectAtIndex:(i-1)];
|
||||
[item fire];
|
||||
[item release];
|
||||
pos = [_performers indexOfObjectIdenticalTo: item];
|
||||
if (pos != NSNotFound) {
|
||||
if ([[item modes] containsObject: _current_mode]) {
|
||||
[_performers removeObjectAtIndex: pos];
|
||||
[item fire];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -640,6 +750,7 @@ static int debug_run_loop = 0;
|
|||
_mode_2_watchers = NSCreateMapTable (NSObjectMapKeyCallBacks,
|
||||
NSObjectMapValueCallBacks, 0);
|
||||
_performers = [[NSMutableArray arrayWithCapacity:8] retain];
|
||||
_timedPerformers = [[NSMutableArray arrayWithCapacity:8] retain];
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -648,6 +759,7 @@ static int debug_run_loop = 0;
|
|||
NSFreeMapTable(_mode_2_timers);
|
||||
NSFreeMapTable(_mode_2_watchers);
|
||||
[_performers release];
|
||||
[_timedPerformers release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -1159,6 +1271,8 @@ id NSDefaultRunLoopMode = @"NSDefaultRunLoopMode";
|
|||
int count = [_performers count];
|
||||
int i;
|
||||
|
||||
[target retain];
|
||||
[argument retain];
|
||||
for (i = count; i > 0; i++) {
|
||||
item = (RunLoopPerformer*)[_performers objectAtIndex:(i-1)];
|
||||
|
||||
|
@ -1166,6 +1280,8 @@ id NSDefaultRunLoopMode = @"NSDefaultRunLoopMode";
|
|||
[_performers removeObjectAtIndex:(i-1)];
|
||||
}
|
||||
}
|
||||
[argument release];
|
||||
[target release];
|
||||
}
|
||||
|
||||
- (void) configureAsServer
|
||||
|
|
|
@ -218,7 +218,7 @@ NSString *NSTaskDidTerminateNotification = @"NSTaskDidTerminateNotification";
|
|||
if (hasCollected == NO) {
|
||||
[self _collectChild];
|
||||
}
|
||||
if (hasTerminated == NO) return NO;
|
||||
if (hasTerminated == YES) return NO;
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
@ -231,7 +231,7 @@ NSString *NSTaskDidTerminateNotification = @"NSTaskDidTerminateNotification";
|
|||
if (hasCollected == NO) {
|
||||
[self _collectChild];
|
||||
}
|
||||
if (hasTerminated) {
|
||||
if (hasTerminated == NO) {
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"NSTask - task has not yet terminated"];
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ NSString *NSTaskDidTerminateNotification = @"NSTaskDidTerminateNotification";
|
|||
int ec = [e count];
|
||||
int ac = [a count];
|
||||
const char *args[ac+2];
|
||||
const char *envp[ec+1];
|
||||
const char *envl[ec+1];
|
||||
int i;
|
||||
|
||||
if (hasLaunched) {
|
||||
|
@ -287,12 +287,18 @@ NSString *NSTaskDidTerminateNotification = @"NSTaskDidTerminateNotification";
|
|||
for (i = 0; i < ec; i++) {
|
||||
NSString *s;
|
||||
id key = [k objectAtIndex: i];
|
||||
id val = [e objectForKey: k];
|
||||
id val = [e objectForKey: key];
|
||||
|
||||
s = [NSString stringWithFormat: @"%s=%s", [key cString], [val cString]];
|
||||
envp[i] = [s cString];
|
||||
if (val) {
|
||||
s = [NSString stringWithFormat: @"%s=%s",
|
||||
[key cString], [val cString]];
|
||||
}
|
||||
else {
|
||||
s = [NSString stringWithFormat: @"%s=", [key cString]];
|
||||
}
|
||||
envl[i] = [s cString];
|
||||
}
|
||||
envp[ec] = 0;
|
||||
envl[ec] = 0;
|
||||
|
||||
path = [[self currentDirectoryPath] cString];
|
||||
idesc = [[self standardInput] fileDescriptor];
|
||||
|
@ -309,7 +315,7 @@ NSString *NSTaskDidTerminateNotification = @"NSTaskDidTerminateNotification";
|
|||
if (odesc != 1) dup2(odesc, 1);
|
||||
if (edesc != 2) dup2(edesc, 2);
|
||||
chdir(path);
|
||||
execve(executable, args, envp);
|
||||
execve(executable, args, envl);
|
||||
exit(-1);
|
||||
}
|
||||
else {
|
||||
|
@ -358,10 +364,13 @@ NSString *NSTaskDidTerminateNotification = @"NSTaskDidTerminateNotification";
|
|||
{
|
||||
if (hasCollected == NO) {
|
||||
if (waitpid(taskId, &terminationStatus, WNOHANG) == taskId) {
|
||||
hasCollected = YES;
|
||||
hasTerminated = YES;
|
||||
if (hasNotified == NO) {
|
||||
[self _sendNotification];
|
||||
if (WIFEXITED(terminationStatus)) {
|
||||
terminationStatus = WEXITSTATUS(terminationStatus);
|
||||
hasCollected = YES;
|
||||
hasTerminated = YES;
|
||||
if (hasNotified == NO) {
|
||||
[self _sendNotification];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue