From f9c1ccddf1200b614f3f457abcf23d9d73c8af6d Mon Sep 17 00:00:00 2001 From: rfm Date: Wed, 7 Feb 2007 08:46:07 +0000 Subject: [PATCH] only initialise lock on systems where symbol support is available. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@24487 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 +++++ Source/NSException.m | 48 ++++++++++++++++------------------------- Testing/thread-except.m | 15 +++++++------ 3 files changed, 32 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9c19d8004..0f8272e74 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-02-07 Richard Frith-Macdonald + + * Source/NSException.m: Only initialise modLock where stack module + symbol handling is supported (fix bug #18938) + 2007-02-06 Richard Frith-Macdonald * Documentation/manual/manual.texi: fix format errors diff --git a/Source/NSException.m b/Source/NSException.m index c2e7836bd..8ee28eede 100644 --- a/Source/NSException.m +++ b/Source/NSException.m @@ -416,16 +416,16 @@ static void find_address (bfd *abfd, asection *section, @end -static id GSLoadModule(NSString *fileName); +static NSRecursiveLock *modLock = nil; +static NSMutableDictionary *stackModules = nil; -/* - * This method automatically load the current process + GNUstep base & gui. - * Only call this when protected by modLock!! - */ -static NSMutableDictionary * -GSGetStackModules() +// initialize stack trace info +static id +GSLoadModule(NSString *fileName) { - static NSMutableDictionary *stackModules = nil; + GSBinaryFileInfo *module = nil; + + [modLock lock]; if (stackModules == nil) { @@ -453,25 +453,10 @@ GSGetStackModules() } } } - return stackModules; -} - -static NSRecursiveLock *modLock = nil; - -// initialize stack trace info -static id -GSLoadModule(NSString *fileName) -{ - GSBinaryFileInfo *module = nil; if ([fileName length] > 0) { - NSMutableDictionary *modules; - - [modLock lock]; - modules = GSGetStackModules(); - module = [modules objectForKey: fileName]; - [modLock unlock]; + module = [stackModules objectForKey: fileName]; if (module == nil); { module = [GSBinaryFileInfo infoWithBinaryFile: fileName]; @@ -479,18 +464,18 @@ GSLoadModule(NSString *fileName) { module = (id)[NSNull null]; } - [modLock lock]; - if ([modules objectForKey: fileName] == nil) + if ([stackModules objectForKey: fileName] == nil) { - [modules setObject: module forKey: fileName]; + [stackModules setObject: module forKey: fileName]; } else { - module = [modules objectForKey: fileName]; + module = [stackModules objectForKey: fileName]; } - [modLock unlock]; } } + [modLock unlock]; + if (module == (id)[NSNull null]) { module = nil; @@ -503,8 +488,9 @@ GSListModules() { NSArray *result; + GSLoadModule(nil); // initialise [modLock lock]; - result = [GSGetStackModules() allValues]; + result = [stackModules allValues]; [modLock unlock]; return result; } @@ -720,6 +706,7 @@ _NSFoundationUncaughtExceptionHandler (NSException *exception) @implementation NSException +#if defined(STACKSYMBOLS) + (void) initialize { if (modLock == nil) @@ -727,6 +714,7 @@ _NSFoundationUncaughtExceptionHandler (NSException *exception) modLock = [NSRecursiveLock new]; } } +#endif /* STACKSYMBOLS */ + (NSException*) exceptionWithName: (NSString*)name reason: (NSString*)reason diff --git a/Testing/thread-except.m b/Testing/thread-except.m index 4c6884e47..4020d1659 100644 --- a/Testing/thread-except.m +++ b/Testing/thread-except.m @@ -25,6 +25,7 @@ #define MAX_ITER 10000.0 /* Max number of iterations. */ FILE *file; +int counter; @interface SingleThread : NSObject { @@ -51,19 +52,17 @@ FILE *file; NS_DURING n = 1+(int)((MAX_ITER*rand())/(RAND_MAX+1.0)); - fflush(stdout); for (i = 0; i < n; i++) { fprintf(file, "%d ", i); fflush(file); } - fflush(stdout); [NSException raise: @"Some exception" format: @"thread %d", ident]; NS_HANDLER - printf("%s: %s for thread %d\n", [[localException name] cString], - [[localException reason] cString], ident); + NSLog(@"%@ for thread %d\n", localException, ident); NS_ENDHANDLER DESTROY(pool); + counter--; [NSThread exit]; } @@ -80,6 +79,9 @@ int main() printf("but the exception associated with each thread must match.\n"); file = fopen("/dev/null", "w"); srand(10); + + counter = N; + for (i = 0; i < N; i++) threads[i] = [[SingleThread alloc] initWithInt: i]; NS_DURING @@ -88,13 +90,14 @@ int main() toTarget: threads[i] withObject: nil]; // Hopefully this will end after all the other threads end. - for (i = 0; i < N*MAX_ITER; i++) + for (i = 0; i < N*MAX_ITER && counter > 0; i++) { + [NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 1.0]]; fprintf(file, "%d", i); fflush(file); } NS_HANDLER - printf("There's a runaway exception! Something is wrong!\n"); + fprintf(stderr, "There's a runaway exception! Something is wrong!\n"); NS_ENDHANDLER fclose(file); DESTROY(pool);