From: Ivan Maidanski Date: Tue, 6 Mar 2012 16:26:24 +0000 (+0400) Subject: Fix gctest (for Win32) to avoid GC_print_stats internal variable usage X-Git-Tag: gc7_2~38 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d952e32f2864c157cfa2583355a17c5cf7796663;p=gc Fix gctest (for Win32) to avoid GC_print_stats internal variable usage (Apply commit 9dc445d from 'master' branch) * include/private/gc_priv.h (GC_print_stats): Update the comment. * tests/test.c (GC_print_stats, run_one_test, check_heap_stats): Rename GC_print_stats to print_stats (since the former is used internally by GC and not exported). * tests/test.c (print_stats): Always define (either as a macro or a static int variable) regardless of GC_DLL and SMALL_CONFIG. * tests/test.c (INIT_PRINT_STATS): New macro (used to initialize print_stats if needed); GETENV is used if needed and available. * tests/test.c (GC_COND_INIT): Invoke INIT_PRINT_STATS. --- diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index 65570dc6..ef2650cf 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -1805,7 +1805,7 @@ GC_EXTERN GC_bool GC_have_errors; /* We saw a smashed or leaked object. */ /* without acquiring the lock. */ #ifndef SMALL_CONFIG - /* GC_print_stats should be visible outside the GC in some cases. */ + /* GC_print_stats should be visible to extra/MacOS.c. */ extern int GC_print_stats; /* Nonzero generates basic GC log. */ /* VERBOSE generates add'l messages. */ #else diff --git a/tests/test.c b/tests/test.c index 70d77333..8d20479e 100644 --- a/tests/test.c +++ b/tests/test.c @@ -56,14 +56,25 @@ # include # endif -# ifdef GC_DLL -# ifdef GC_PRINT_VERBOSE_STATS -# define GC_print_stats VERBOSE -# else -# define GC_print_stats 0 /* Not exported from DLL */ - /* Redefine to 1 to generate output. */ -# endif +#ifdef GC_PRINT_VERBOSE_STATS +# define print_stats VERBOSE +# define INIT_PRINT_STATS /* empty */ +#else + /* Use own variable as GC_print_stats might not be exported. */ + static int print_stats = 0; +# ifdef GC_READ_ENV_FILE + /* GETENV uses GC internal function in this case. */ +# define INIT_PRINT_STATS /* empty */ +# else +# define INIT_PRINT_STATS \ + { \ + if (0 != GETENV("GC_PRINT_VERBOSE_STATS")) \ + print_stats = VERBOSE; \ + else if (0 != GETENV("GC_PRINT_STATS")) \ + print_stats = 1; \ + } # endif +#endif /* !GC_PRINT_VERBOSE_STATS */ # ifdef PCR # include "th/PCR_ThCrSec.h" @@ -98,9 +109,9 @@ #if defined(CYGWIN32) || defined (AIX) || defined(DARWIN) \ || defined(THREAD_LOCAL_ALLOC) \ || (defined(MSWINCE) && !defined(GC_WINMAIN_REDIRECT)) -# define GC_COND_INIT() GC_INIT(); CHECH_GCLIB_VERSION +# define GC_COND_INIT() GC_INIT(); CHECH_GCLIB_VERSION; INIT_PRINT_STATS #else -# define GC_COND_INIT() CHECH_GCLIB_VERSION +# define GC_COND_INIT() CHECH_GCLIB_VERSION; INIT_PRINT_STATS #endif #define CHECK_OUT_OF_MEMORY(p) \ @@ -1204,7 +1215,7 @@ void run_one_test(void) /* Repeated list reversal test. */ GET_TIME(start_time); reverse_test(); - if (GC_print_stats) { + if (print_stats) { GET_TIME(reverse_time); time_diff = MS_TIME_DIFF(reverse_time, start_time); GC_log_printf("-------------Finished reverse_test at time %u (%p)\n", @@ -1212,7 +1223,7 @@ void run_one_test(void) } # ifndef DBG_HDRS_ALL typed_test(); - if (GC_print_stats) { + if (print_stats) { GET_TIME(typed_time); time_diff = MS_TIME_DIFF(typed_time, start_time); GC_log_printf("-------------Finished typed_test at time %u (%p)\n", @@ -1220,7 +1231,7 @@ void run_one_test(void) } # endif /* DBG_HDRS_ALL */ tree_test(); - if (GC_print_stats) { + if (print_stats) { GET_TIME(tree_time); time_diff = MS_TIME_DIFF(tree_time, start_time); GC_log_printf("-------------Finished tree_test at time %u (%p)\n", @@ -1228,7 +1239,7 @@ void run_one_test(void) } /* Run reverse_test a second time, so we hopefully notice corruption. */ reverse_test(); - if (GC_print_stats) { + if (print_stats) { GET_TIME(reverse_time); time_diff = MS_TIME_DIFF(reverse_time, start_time); GC_log_printf( @@ -1247,12 +1258,12 @@ void run_one_test(void) GC_gcollect(); tiny_reverse_test(0); GC_gcollect(); - if (GC_print_stats) + if (print_stats) GC_log_printf("Finished a child process\n"); exit(0); } # endif - if (GC_print_stats) + if (print_stats) GC_log_printf("Finished %p\n", &start_time); } @@ -1308,7 +1319,7 @@ void check_heap_stats(void) # endif GC_invoke_finalizers(); } - if (GC_print_stats) { + if (print_stats) { GC_log_printf("Primordial thread stack bottom: %p\n", GC_stackbottom); }