Skip to content

Commit 2fcc0ca

Browse files
committed
locale.c: Fix some debugging so will output during init
Because the command line options are currently parsed after the locale initialization is done, an environment variable is read to allow debugging of the function that is called to do the initialization. However, any functions that it calls, prior to this commit, were unaware of this and so did not output debugging. This commit fixes most of them.
1 parent 78d5797 commit 2fcc0ca

File tree

1 file changed

+49
-24
lines changed

1 file changed

+49
-24
lines changed

locale.c

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@
4444

4545
#include "reentr.h"
4646

47+
/* If the environment says to, we can output debugging information during
48+
* initialization. This is done before option parsing, and before any thread
49+
* creation, so can be a file-level static */
50+
#ifdef DEBUGGING
51+
static bool debug_initialization = FALSE;
52+
#endif
53+
4754
#ifdef USE_LOCALE
4855

4956
/*
@@ -119,13 +126,17 @@ Perl_set_numeric_radix(pTHX)
119126
else
120127
PL_numeric_radix_sv = NULL;
121128

122-
DEBUG_L(PerlIO_printf(Perl_debug_log, "Locale radix is '%s', ?UTF-8=%d\n",
129+
#ifdef DEBUGGING
130+
if (DEBUG_L_TEST || debug_initialization) {
131+
PerlIO_printf(Perl_debug_log, "Locale radix is '%s', ?UTF-8=%d\n",
123132
(PL_numeric_radix_sv)
124133
? SvPVX(PL_numeric_radix_sv)
125134
: "NULL",
126135
(PL_numeric_radix_sv)
127136
? cBOOL(SvUTF8(PL_numeric_radix_sv))
128-
: 0));
137+
: 0);
138+
}
139+
#endif
129140

130141
# endif /* HAS_LOCALECONV */
131142
#endif /* USE_LOCALE_NUMERIC */
@@ -230,8 +241,12 @@ Perl_set_numeric_standard(pTHX)
230241
PL_numeric_standard = TRUE;
231242
PL_numeric_local = isNAME_C_OR_POSIX(PL_numeric_name);
232243
set_numeric_radix();
233-
DEBUG_L(PerlIO_printf(Perl_debug_log,
234-
"Underlying LC_NUMERIC locale now is C\n"));
244+
#ifdef DEBUGGING
245+
if (DEBUG_L_TEST || debug_initialization) {
246+
PerlIO_printf(Perl_debug_log,
247+
"Underlying LC_NUMERIC locale now is C\n");
248+
}
249+
#endif
235250

236251
#endif /* USE_LOCALE_NUMERIC */
237252
}
@@ -250,9 +265,13 @@ Perl_set_numeric_local(pTHX)
250265
PL_numeric_standard = isNAME_C_OR_POSIX(PL_numeric_name);
251266
PL_numeric_local = TRUE;
252267
set_numeric_radix();
253-
DEBUG_L(PerlIO_printf(Perl_debug_log,
268+
#ifdef DEBUGGING
269+
if (DEBUG_L_TEST || debug_initialization) {
270+
PerlIO_printf(Perl_debug_log,
254271
"Underlying LC_NUMERIC locale now is %s\n",
255-
PL_numeric_name));
272+
PL_numeric_name);
273+
}
274+
#endif
256275

257276
#endif /* USE_LOCALE_NUMERIC */
258277
}
@@ -884,24 +903,6 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
884903
const char * const setlocale_init = (PerlEnv_getenv("PERL_SKIP_LOCALE_INIT"))
885904
? NULL
886905
: "";
887-
#ifdef DEBUGGING
888-
const bool debug = (PerlEnv_getenv("PERL_DEBUG_LOCALE_INIT"))
889-
? TRUE
890-
: FALSE;
891-
# define DEBUG_LOCALE_INIT(category, locale, result) \
892-
STMT_START { \
893-
if (debug) { \
894-
PerlIO_printf(Perl_debug_log, \
895-
"%s:%d: %s\n", \
896-
__FILE__, __LINE__, \
897-
_setlocale_debug_string(category, \
898-
locale, \
899-
result)); \
900-
} \
901-
} STMT_END
902-
#else
903-
# define DEBUG_LOCALE_INIT(a,b,c)
904-
#endif
905906
const char* trial_locales[5]; /* 5 = 1 each for "", LC_ALL, LANG, "", C */
906907
unsigned int trial_locales_count;
907908
const char * const lc_all = savepv(PerlEnv_getenv("LC_ALL"));
@@ -932,6 +933,25 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
932933
const char *system_default_locale = NULL;
933934
#endif
934935

936+
#ifdef DEBUGGING
937+
debug_initialization = (PerlEnv_getenv("PERL_DEBUG_LOCALE_INIT"))
938+
? TRUE
939+
: FALSE;
940+
# define DEBUG_LOCALE_INIT(category, locale, result) \
941+
STMT_START { \
942+
if (debug_initialization) { \
943+
PerlIO_printf(Perl_debug_log, \
944+
"%s:%d: %s\n", \
945+
__FILE__, __LINE__, \
946+
_setlocale_debug_string(category, \
947+
locale, \
948+
result)); \
949+
} \
950+
} STMT_END
951+
#else
952+
# define DEBUG_LOCALE_INIT(a,b,c)
953+
#endif
954+
935955
#ifndef LOCALE_ENVIRON_REQUIRED
936956
PERL_UNUSED_VAR(done);
937957
PERL_UNUSED_VAR(locale_param);
@@ -1370,6 +1390,11 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
13701390
PERL_UNUSED_ARG(printwarn);
13711391
#endif /* USE_LOCALE */
13721392

1393+
#ifdef DEBUGGING
1394+
/* So won't continue to output stuff */
1395+
debug_initialization = FALSE;
1396+
#endif
1397+
13731398
return ok;
13741399
}
13751400

0 commit comments

Comments
 (0)