Merge pull request #95 from gnustep/fix_timer_blocks_bug

Fix timer blocks bug
This commit is contained in:
Fred Kiefer 2020-01-20 09:36:15 +01:00 committed by GitHub
commit 788595363f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -116,7 +116,6 @@ static Class NSDate_class;
userInfo: (id)info userInfo: (id)info
repeats: (BOOL)f repeats: (BOOL)f
{ {
_block = nil;
if (ti <= 0.0) if (ti <= 0.0)
{ {
ti = 0.0001; ti = 0.0001;
@ -146,18 +145,18 @@ static Class NSDate_class;
return self; return self;
} }
- (instancetype) initWithFireDate: (NSDate *)date - (instancetype) initWithFireDate: (NSDate *)date
interval: (NSTimeInterval)interval interval: (NSTimeInterval)interval
repeats: (BOOL)repeats repeats: (BOOL)repeats
block: (GSTimerBlock)block block: (GSTimerBlock)block
{ {
ASSIGN(_block, block);
return [self initWithFireDate: date return [self initWithFireDate: date
interval: interval interval: interval
target: nil target: nil
selector: NULL selector: NULL
userInfo: nil userInfo: nil
repeats: repeats]; repeats: repeats];
ASSIGN(_block, block);
} }
/** /**
@ -254,7 +253,7 @@ static Class NSDate_class;
block: block]; block: block];
[[NSRunLoop currentRunLoop] addTimer: t forMode: NSDefaultRunLoopMode]; [[NSRunLoop currentRunLoop] addTimer: t forMode: NSDefaultRunLoopMode];
RELEASE(t); RELEASE(t);
return t; return t;
} }
- (void) dealloc - (void) dealloc
@ -286,12 +285,12 @@ static Class NSDate_class;
else else
{ {
id target; id target;
/* We retain the target so it won't be deallocated while we are using /* We retain the target so it won't be deallocated while we are using
* it (if this timer gets invalidated while we are firing). * it (if this timer gets invalidated while we are firing).
*/ */
target = RETAIN(_target); target = RETAIN(_target);
if (_selector == 0) if (_selector == 0)
{ {
NS_DURING NS_DURING
@ -328,7 +327,7 @@ static Class NSDate_class;
} }
RELEASE(target); RELEASE(target);
} }
if (_repeats == NO) if (_repeats == NO)
{ {
[self invalidate]; [self invalidate];