From 360407b2586eb6a612cff3863f0286b133bdc197 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Fri, 23 Jun 2017 14:06:11 +0300 Subject: [PATCH] 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). --- tests/test.c | 4 ++-- thread_local_alloc.c | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) 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) -- 2.40.0