From d1199844cb3cc4d9edccf4cf0102b62ff334d69d Mon Sep 17 00:00:00 2001 From: theraven Date: Sat, 28 May 2011 15:10:03 +0000 Subject: [PATCH] Lock the GC mode once something has queried it. All of the GNUstep code that does run-time detection of whether to use GC calls objc_collecting_enabled() (sometimes indirectly, via NSGarbageCollector) to see if we're in GC mode. After any of these calls, it is not safe to switch modes. --- abi_version.c | 2 +- gc_boehm.c | 3 +++ gc_ops.h | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/abi_version.c b/abi_version.c index 5c3931f..5321d57 100644 --- a/abi_version.c +++ b/abi_version.c @@ -61,7 +61,7 @@ static int known_abi_count = }\ } while(0) -static enum objc_gc_mode current_gc_mode = GC_Optional; +PRIVATE 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 a74629d..c6d8b19 100644 --- a/gc_boehm.c +++ b/gc_boehm.c @@ -531,6 +531,9 @@ static void init(void) BOOL objc_collecting_enabled(void) { + // Lock the GC in the current state once it's been queried. This prevents + // the loading of any modules with an incompatible GC mode. + current_gc_mode = isGCEnabled ? GC_Required : GC_None; return isGCEnabled; } diff --git a/gc_ops.h b/gc_ops.h index 54045c0..2f84153 100644 --- a/gc_ops.h +++ b/gc_ops.h @@ -54,6 +54,10 @@ enum objc_gc_mode /** * The current Objective-C garbage collection mode. */ +extern enum objc_gc_mode current_gc_mode; +/** + * Have we loaded any code that triggers the ObjC GC support? + */ extern BOOL isGCEnabled; /**