From b0df5f479ec352c0a9775a4e7a0e60c27f6482c9 Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Sat, 13 Oct 2007 18:50:41 +0200 Subject: Objective-C layer: Make initialisation more robust. darcs-hash:306059409a7f77c02e046864f6bd3237b60b3a87 --- Objective-C/libobjcl.m | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/Objective-C/libobjcl.m b/Objective-C/libobjcl.m index de899e3..838e2eb 100644 --- a/Objective-C/libobjcl.m +++ b/Objective-C/libobjcl.m @@ -32,23 +32,37 @@ static NSAutoreleasePool *objcl_autorelease_pool = NULL; /* Preallocate an exception to throw when memory is all used up. */ -NSException *objcl_oom_exception; +NSException *objcl_oom_exception = NULL; void objcl_initialise_runtime (void) { - objcl_autorelease_pool = [[NSAutoreleasePool alloc] init]; - objcl_oom_exception = [NSException exceptionWithName: @"MLKOutOfMemoryException" - reason: @"Out of memory" - userInfo: nil]; + if (!objcl_autorelease_pool) + objcl_autorelease_pool = [[NSAutoreleasePool alloc] init]; + if (!objcl_oom_exception) + { + objcl_oom_exception = [NSException exceptionWithName: @"MLKOutOfMemoryException" + reason: @"Out of memory" + userInfo: nil]; + [objcl_oom_exception retain]; + } } void objcl_shutdown_runtime (void) { - [objcl_autorelease_pool release]; + if (objcl_autorelease_pool) + { + [objcl_autorelease_pool release]; + objcl_autorelease_pool = NULL; + } + if (objcl_oom_exception) + { + [objcl_oom_exception release]; + objcl_oom_exception = NULL; + } } -- cgit v1.2.3