Tweak GC check, make sure GC_init() is called even when ObjC code isn't using GC (stuff internal to the runtime may be)

main
theraven 15 years ago
parent d73eb8f634
commit fe5d1b892a

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

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

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

@ -4,6 +4,9 @@
#include "lock.h"
#include "loader.h"
#include "visibility.h"
#ifdef ENABLE_GC
#include <gc/gc.h>
#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,

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

Loading…
Cancel
Save