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
This commit is contained in:
Richard Frith-MacDonald 2007-02-07 08:46:07 +00:00
parent d85feda018
commit d3860e2d82
3 changed files with 32 additions and 36 deletions

View file

@ -1,3 +1,8 @@
2007-02-07 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSException.m: Only initialise modLock where stack module
symbol handling is supported (fix bug #18938)
2007-02-06 Richard Frith-Macdonald <rfm@gnu.org>
* Documentation/manual/manual.texi: fix format errors

View file

@ -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

View file

@ -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);