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
This commit is contained in:
Richard Frith-MacDonald 2008-09-23 08:10:59 +00:00
parent 5613ece3f6
commit ac3eb1fbce
2 changed files with 30 additions and 9 deletions

View file

@ -1,3 +1,8 @@
2008-09-23 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSThread.m: add a couple of checks to ensure correct
initialisation of class.
2008-09-21 00:05-EDT Gregory John Casamento <greg_casamento@yahoo.com> 2008-09-21 00:05-EDT Gregory John Casamento <greg_casamento@yahoo.com>
* COPYINGv3: Adding back in. * COPYINGv3: Adding back in.

View file

@ -51,8 +51,14 @@
#ifdef NeXT_RUNTIME #ifdef NeXT_RUNTIME
#include "thr-mach.h" #include "thr-mach.h"
#endif #endif
#include <errno.h> #ifdef HAVE_SYS_FILE_H
#include <sys/file.h>
#endif
#ifdef HAVE_SYS_FCNTL_H
#include <sys/fcntl.h> #include <sys/fcntl.h>
#endif
#include <errno.h>
#ifdef __POSIX_SOURCE #ifdef __POSIX_SOURCE
#define NBLK_OPT O_NONBLOCK #define NBLK_OPT O_NONBLOCK
@ -617,6 +623,12 @@ gnustep_base_thread_callback(void)
- (void) dealloc - (void) dealloc
{ {
if (self == defaultThread)
{
[self retain];
[NSException raise: NSInternalInconsistencyException
format: @"Deallocating the default thread is not allowed!"];
}
if (_active == YES) if (_active == YES)
{ {
[NSException raise: NSInternalInconsistencyException [NSException raise: NSInternalInconsistencyException
@ -658,10 +670,6 @@ gnustep_base_thread_callback(void)
} }
} }
DESTROY(_gcontext); DESTROY(_gcontext);
if (self == defaultThread)
{
defaultThread = nil;
}
NSDeallocateObject(self); NSDeallocateObject(self);
GSNOSUPERDEALLOC; GSNOSUPERDEALLOC;
} }
@ -1011,10 +1019,10 @@ GSRunLoopInfoForThread(NSThread *aThread)
if (aThread == nil) if (aThread == nil)
{ {
aThread = GSCurrentThread(); aThread = GSCurrentThread();
if (((NSThread_ivars*)aThread)->_runLoopInfo == nil) }
{ if (((NSThread_ivars*)aThread)->_runLoopInfo == nil)
((NSThread_ivars*)aThread)->_runLoopInfo = [GSRunLoopThreadInfo new]; {
} ((NSThread_ivars*)aThread)->_runLoopInfo = [GSRunLoopThreadInfo new];
} }
info = ((NSThread_ivars*)aThread)->_runLoopInfo; info = ((NSThread_ivars*)aThread)->_runLoopInfo;
return info; return info;
@ -1114,6 +1122,14 @@ GSRunLoopInfoForThread(NSThread *aThread)
waitUntilDone: (BOOL)aFlag waitUntilDone: (BOOL)aFlag
modes: (NSArray*)anArray 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 [self performSelector: aSelector
onThread: defaultThread onThread: defaultThread
withObject: anObject withObject: anObject