From 6d2b78b3973206d0312fe62679fd0e0af4133808 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Fri, 25 Dec 2020 19:01:23 -0700 Subject: [PATCH] DEBUG_L now also looks at environment variable Because locale initialization happens before command line processing, one can't pass a -DL argument to enable debugging of locale initialization. Instead, an environment variable is read then, and is used to enable debugging or not. In the past, code specifically had to test for this being set. This commit changes that so that debugging can automatically be enabled without having to write special code. Future commits will strip out those special checks. --- locale.c | 24 +++++++++++++----------- perl.h | 14 ++++++++++++-- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/locale.c b/locale.c index b26322a6b2d2..57f6611b4c6b 100644 --- a/locale.c +++ b/locale.c @@ -43,6 +43,19 @@ * this end, and is retained, #ifdef'd out. */ +/* If the environment says to, we can output debugging information during + * initialization. This is done before option parsing, and before any thread + * creation, so can be a file-level static. (Must come before #including + * perl.h) */ +#ifdef DEBUGGING +static int debug_initialization = 0; +# define DEBUG_INITIALIZATION_set(v) (debug_initialization = v) +# define DEBUG_LOCALE_INITIALIZATION_ debug_initialization +#else +# define debug_initialization 0 +# define DEBUG_INITIALIZATION_set(v) +#endif + #include "EXTERN.h" #define PERL_IN_LOCALE_C #include "perl_langinfo.h" @@ -57,17 +70,6 @@ # include #endif -/* If the environment says to, we can output debugging information during - * initialization. This is done before option parsing, and before any thread - * creation, so can be a file-level static */ -#if ! defined(DEBUGGING) -# define debug_initialization 0 -# define DEBUG_INITIALIZATION_set(v) -#else -static bool debug_initialization = FALSE; -# define DEBUG_INITIALIZATION_set(v) (debug_initialization = v) -#endif - /* Returns the Unix errno portion; ignoring any others. This is a macro here * instead of putting it into perl.h, because unclear to khw what should be diff --git a/perl.h b/perl.h index 17a21a1c420f..a16be2095193 100644 --- a/perl.h +++ b/perl.h @@ -4417,13 +4417,23 @@ Gid_t getegid (void); # define DEBUG_q_TEST_ UNLIKELY(PL_debug & DEBUG_q_FLAG) # define DEBUG_M_TEST_ UNLIKELY(PL_debug & DEBUG_M_FLAG) # define DEBUG_B_TEST_ UNLIKELY(PL_debug & DEBUG_B_FLAG) -# define DEBUG_L_TEST_ UNLIKELY(PL_debug & DEBUG_L_FLAG) + +/* Locale initialization comes earlier than PL_debug gets set, + * DEBUG_LOCALE_INITIALIZATION_, if defined, will be set early enough */ +# ifndef DEBUG_LOCALE_INITIALIZATION_ +# define DEBUG_LOCALE_INITIALIZATION_ 0 +# endif +# define DEBUG_L_TEST_ \ + ( UNLIKELY(DEBUG_LOCALE_INITIALIZATION_) \ + || UNLIKELY(PL_debug & DEBUG_L_FLAG)) +# define DEBUG_Lv_TEST_ \ + ( UNLIKELY(DEBUG_LOCALE_INITIALIZATION_) \ + || UNLIKELY(DEBUG_BOTH_FLAGS_TEST_(DEBUG_L_FLAG, DEBUG_v_FLAG))) # define DEBUG_i_TEST_ UNLIKELY(PL_debug & DEBUG_i_FLAG) # define DEBUG_y_TEST_ UNLIKELY(PL_debug & DEBUG_y_FLAG) # define DEBUG_Xv_TEST_ DEBUG_BOTH_FLAGS_TEST_(DEBUG_X_FLAG, DEBUG_v_FLAG) # define DEBUG_Uv_TEST_ DEBUG_BOTH_FLAGS_TEST_(DEBUG_U_FLAG, DEBUG_v_FLAG) # define DEBUG_Pv_TEST_ DEBUG_BOTH_FLAGS_TEST_(DEBUG_P_FLAG, DEBUG_v_FLAG) -# define DEBUG_Lv_TEST_ DEBUG_BOTH_FLAGS_TEST_(DEBUG_L_FLAG, DEBUG_v_FLAG) # define DEBUG_yv_TEST_ DEBUG_BOTH_FLAGS_TEST_(DEBUG_y_FLAG, DEBUG_v_FLAG) #ifdef DEBUGGING