From ac3eb1fbce8038bcc494c6926ab9b50a2a5489b2 Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Tue, 23 Sep 2008 08:10:59 +0000 Subject: [PATCH] Make this a bit more robust git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@26864 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 +++++ Source/NSThread.m | 34 +++++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index aa513934e..cf4e03606 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-09-23 Richard Frith-Macdonald + + * Source/NSThread.m: add a couple of checks to ensure correct + initialisation of class. + 2008-09-21 00:05-EDT Gregory John Casamento * COPYINGv3: Adding back in. diff --git a/Source/NSThread.m b/Source/NSThread.m index b88d09384..3360c6458 100644 --- a/Source/NSThread.m +++ b/Source/NSThread.m @@ -51,8 +51,14 @@ #ifdef NeXT_RUNTIME #include "thr-mach.h" #endif -#include +#ifdef HAVE_SYS_FILE_H +#include +#endif +#ifdef HAVE_SYS_FCNTL_H #include +#endif + +#include #ifdef __POSIX_SOURCE #define NBLK_OPT O_NONBLOCK @@ -617,6 +623,12 @@ gnustep_base_thread_callback(void) - (void) dealloc { + if (self == defaultThread) + { + [self retain]; + [NSException raise: NSInternalInconsistencyException + format: @"Deallocating the default thread is not allowed!"]; + } if (_active == YES) { [NSException raise: NSInternalInconsistencyException @@ -658,10 +670,6 @@ gnustep_base_thread_callback(void) } } DESTROY(_gcontext); - if (self == defaultThread) - { - defaultThread = nil; - } NSDeallocateObject(self); GSNOSUPERDEALLOC; } @@ -1011,10 +1019,10 @@ GSRunLoopInfoForThread(NSThread *aThread) if (aThread == nil) { aThread = GSCurrentThread(); - if (((NSThread_ivars*)aThread)->_runLoopInfo == nil) - { - ((NSThread_ivars*)aThread)->_runLoopInfo = [GSRunLoopThreadInfo new]; - } + } + if (((NSThread_ivars*)aThread)->_runLoopInfo == nil) + { + ((NSThread_ivars*)aThread)->_runLoopInfo = [GSRunLoopThreadInfo new]; } info = ((NSThread_ivars*)aThread)->_runLoopInfo; return info; @@ -1114,6 +1122,14 @@ GSRunLoopInfoForThread(NSThread *aThread) waitUntilDone: (BOOL)aFlag modes: (NSArray*)anArray { + /* It's possible that this method could be called before the NSThread + * class is initialised, so we check and make sure it's initiailised + * if necessary. + */ + if (defaultThread == nil) + { + [NSThread currentThread]; + } [self performSelector: aSelector onThread: defaultThread withObject: anObject