From fe5d1b892a7150e1108c4f96844b29803ccd70dd Mon Sep 17 00:00:00 2001 From: theraven Date: Sat, 28 May 2011 14:38:02 +0000 Subject: [PATCH] Tweak GC check, make sure GC_init() is called even when ObjC code isn't using GC (stuff internal to the runtime may be) --- abi_version.c | 2 +- gc_boehm.c | 4 ++-- gc_ops.h | 2 +- loader.c | 6 ++++++ properties.m | 4 ++-- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/abi_version.c b/abi_version.c index 5321d57..5c3931f 100644 --- a/abi_version.c +++ b/abi_version.c @@ -61,7 +61,7 @@ static int known_abi_count = }\ } while(0) -PRIVATE enum objc_gc_mode current_gc_mode = GC_Optional; +static enum objc_gc_mode current_gc_mode = GC_Optional; static BOOL endsWith(const char *string, const char *suffix) { diff --git a/gc_boehm.c b/gc_boehm.c index 7ce2938..a74629d 100644 --- a/gc_boehm.c +++ b/gc_boehm.c @@ -511,7 +511,6 @@ static void runFinalizers(void) static void init(void) { - GC_INIT(); char *sigNumber; // Dump GC stats on exit - uncomment when debugging. if (getenv("LIBOBJC_DUMP_GC_STATUS_ON_EXIT")) @@ -532,7 +531,7 @@ static void init(void) BOOL objc_collecting_enabled(void) { - return current_gc_mode != GC_None; + return isGCEnabled; } void objc_startCollectorThread(void) @@ -580,6 +579,7 @@ PRIVATE struct gc_ops gc_ops_boehm = PRIVATE void enableGC(BOOL exclude) { + isGCEnabled = YES; if (__sync_bool_compare_and_swap(&gc, &gc_ops_none, &gc_ops_boehm)) { gc->init(); diff --git a/gc_ops.h b/gc_ops.h index 9cda3f0..54045c0 100644 --- a/gc_ops.h +++ b/gc_ops.h @@ -54,7 +54,7 @@ enum objc_gc_mode /** * The current Objective-C garbage collection mode. */ -extern enum objc_gc_mode current_gc_mode; +extern BOOL isGCEnabled; /** * The current set of garbage collector operations to use. diff --git a/loader.c b/loader.c index 6f3594f..d4c1552 100644 --- a/loader.c +++ b/loader.c @@ -4,6 +4,9 @@ #include "lock.h" #include "loader.h" #include "visibility.h" +#ifdef ENABLE_GC +#include +#endif /** * Runtime lock. This is exposed in @@ -32,6 +35,9 @@ void __objc_exec_class(struct objc_module_abi_8 *module) if (first_run) { +#if ENABLE_GC + GC_INIT(); +#endif // Create the main runtime lock. This is not safe in theory, but in // practice the first time that this function is called will be in the // loader, from the main thread. Future loaders may run concurrently, diff --git a/properties.m b/properties.m index 3e432a8..e205877 100644 --- a/properties.m +++ b/properties.m @@ -20,7 +20,7 @@ id objc_getProperty(id obj, SEL _cmd, ptrdiff_t offset, BOOL isAtomic) if (nil == obj) { return nil; } char *addr = (char*)obj; addr += offset; - if (current_gc_mode == GC_Required) + if (isGCEnabled) { return *(id*)addr; } @@ -47,7 +47,7 @@ void objc_setProperty(id obj, SEL _cmd, ptrdiff_t offset, id arg, BOOL isAtomic, char *addr = (char*)obj; addr += offset; - if (current_gc_mode == GC_Required) + if (isGCEnabled) { if (isCopy) {