Index: NSRunLoop.m =================================================================== RCS file: /cvsroot/gnustep/gnustep/core/base/Source/NSRunLoop.m,v retrieving revision 1.111 diff -u -r1.111 NSRunLoop.m --- NSRunLoop.m 28 Oct 2003 11:10:23 -0000 1.111 +++ NSRunLoop.m 14 Mar 2004 00:42:49 -0000 @@ -1705,13 +1705,12 @@ */ - (NSDate*) limitDateForMode: (NSString*)mode { - extern NSTimer *GSHousekeeper(); + extern NSTimer *GSHousekeeper(void); GSRunLoopCtxt *context = NSMapGet(_contextMap, mode); NSDate *when = nil; if (context != nil) { - NSTimer *min_timer = nil; GSRunLoopWatcher *min_watcher = nil; NSString *savedMode = _currentMode; CREATE_AUTORELEASE_POOL(arp); @@ -1724,7 +1723,7 @@ while (GSIArrayCount(timers) != 0) { - min_timer = GSIArrayItemAtIndex(timers, 0).obj; + NSTimer *min_timer = GSIArrayItemAtIndex(timers, 0).obj; if (timerInvalidated(min_timer) == YES) { GSIArrayRemoveItemAtIndex(timers, 0); @@ -1732,6 +1731,9 @@ continue; } + if (!when) + when = [timerDate(min_timer) copy]; + if ([timerDate(min_timer) timeIntervalSinceNow] > 0) { break; @@ -1749,7 +1751,6 @@ { RELEASE(min_timer); } - min_timer = nil; GSNotifyASAP(); /* Post notifications. */ } @@ -1825,12 +1826,11 @@ /* * If there is nothing being watched, and no valid timers - * other than the housekeeper, we set min_timer to nil so + * other than the housekeeper, we set when to nil so * that the housekeeper timer does not keep the runloop * active. It's a special case set up in NSThread.m */ - if (min_watcher == nil && min_timer != nil - && min_timer == GSHousekeeper()) + if (min_watcher == nil && when) { unsigned count = GSIArrayCount(timers); @@ -1844,7 +1844,7 @@ } if (GSIArrayCount(timers) == 1) { - min_timer = nil; + DESTROY(when); } } @@ -1860,19 +1860,22 @@ RELEASE(arp); /* - * If there are timers - set limit date to the earliest of them. + * If there are timers, when is already set to the limit date of the + * earliest of them (and retained!). * If there are watchers, set the limit date to that of the earliest * watcher (or leave it as the date of the earliest timer if that is * before the watchers limit). */ - if (min_timer != nil) + if (when) { - when = timerDate(min_timer); if (min_watcher != nil && [min_watcher->_date compare: when] == NSOrderedAscending) { + RELEASE(when); when = min_watcher->_date; } + else + AUTORELEASE(when); } else if (min_watcher != nil) {