summaryrefslogtreecommitdiff
path: root/Objective-C
diff options
context:
space:
mode:
authorMatthias Benkard <code@mail.matthias.benkard.de>2007-10-13 18:50:41 +0200
committerMatthias Benkard <code@mail.matthias.benkard.de>2007-10-13 18:50:41 +0200
commitb0df5f479ec352c0a9775a4e7a0e60c27f6482c9 (patch)
tree8ab490f44960715d5b0bdb162e2065a67022579d /Objective-C
parent5b0be258009220af661ba877b17c3ebf33972409 (diff)
Objective-C layer: Make initialisation more robust.
darcs-hash:306059409a7f77c02e046864f6bd3237b60b3a87
Diffstat (limited to 'Objective-C')
-rw-r--r--Objective-C/libobjcl.m26
1 files 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;
+ }
}