From: Ivan Maidanski Date: Fri, 23 Jun 2017 11:06:11 +0000 (+0300) Subject: Make GC_INIT optional for clients even if thread-local allocations enabled X-Git-Tag: v8.0.0~663 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=360407b2586eb6a612cff3863f0286b133bdc197;p=gc Make GC_INIT optional for clients even if thread-local allocations enabled * tests/test.c (GC_OPT_INIT): Do not define to GC_INIT() even if THREAD_LOCAL_ALLOC; force define to GC_INIT() if TEST_EXPLICIT_GC_INIT macro defined. * thread_local_alloc.c [USE_PTHREAD_SPECIFIC || USE_WIN32_SPECIFIC] (GC_malloc_kind): Check keys_initialized before GC_getspecific call (fall back to GC_malloc_kind_global if keys_initialized is false). --- diff --git a/tests/test.c b/tests/test.c index b3b455c3..ef7e8095 100644 --- a/tests/test.c +++ b/tests/test.c @@ -135,8 +135,8 @@ /* Call GC_INIT only on platforms on which we think we really need it, */ /* so that we can test automatic initialization on the rest. */ -#if defined(CYGWIN32) || defined (AIX) || defined(DARWIN) \ - || defined(PLATFORM_ANDROID) || defined(THREAD_LOCAL_ALLOC) \ +#if defined(TEST_EXPLICIT_GC_INIT) || defined(AIX) || defined(CYGWIN32) \ + || defined(DARWIN) || defined(PLATFORM_ANDROID) \ || (defined(MSWINCE) && !defined(GC_WINMAIN_REDIRECT)) # define GC_OPT_INIT GC_INIT() #else diff --git a/thread_local_alloc.c b/thread_local_alloc.c index 0919935d..aacd855e 100644 --- a/thread_local_alloc.c +++ b/thread_local_alloc.c @@ -170,6 +170,8 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc_kind(size_t bytes, int knd) tsd = GC_getspecific(k); } # else + if (!EXPECT(keys_initialized, TRUE)) + return GC_malloc_kind_global(bytes, knd); tsd = GC_getspecific(GC_thread_key); # endif # if !defined(USE_COMPILER_TLS) && !defined(USE_WIN32_COMPILER_TLS)