Skip to content

Commit

Permalink
DEBUG_L now also looks at environment variable
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
khwilliamson committed May 6, 2021
1 parent 09187ab commit 76d34fc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
24 changes: 13 additions & 11 deletions locale.c
Expand Up @@ -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"
Expand All @@ -57,17 +70,6 @@
# include <wctype.h>
#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
Expand Down
14 changes: 12 additions & 2 deletions perl.h
Expand Up @@ -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
Expand Down

0 comments on commit 76d34fc

Please sign in to comment.