Skip to content

Commit

Permalink
locale.c: Use setlocale() for init, not P2008
Browse files Browse the repository at this point in the history
We have found bugs in the POSIX 2008 libc implementations on various
platforms.  This code, which does the initialization of locale handling
has always been very conservative, expecting possible failures due to
bugs in it our the libc implementations, and backing out if necessary to
a crippled, but workable state, if something goes wrong.

I think we should use the oldest, most stable locale implementation in
these circumstances
  • Loading branch information
khwilliamson committed May 5, 2021
1 parent f8b74de commit 6b0fdae
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions locale.c
Expand Up @@ -3590,7 +3590,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
{
bool done = FALSE;
if (lang) {
sl_result[LC_ALL_INDEX_] = setlocale_c(LC_ALL, setlocale_init);
sl_result[LC_ALL_INDEX_] = stdized_setlocale(LC_ALL, setlocale_init);
DEBUG_LOCALE_INIT(LC_ALL_INDEX_, setlocale_init,
sl_result[LC_ALL_INDEX_]);
if (sl_result[LC_ALL_INDEX_])
Expand All @@ -3605,7 +3605,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
&& (lang || PerlEnv_getenv(category_names[i])))
? setlocale_init
: NULL;
sl_result[i] = setlocale_i(i, locale_param);
sl_result[i] = stdized_setlocale(categories[i], locale_param);
if (! sl_result[i]) {
setlocale_failure = TRUE;
}
Expand Down Expand Up @@ -3644,7 +3644,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn)

/* Note that this may change the locale, but we are going to do
* that anyway just below */
system_default_locale = setlocale_c(LC_ALL, "");
system_default_locale = stdized_setlocale(LC_ALL, "");
DEBUG_LOCALE_INIT(LC_ALL_INDEX_, "", system_default_locale);

/* Skip if invalid or if it's already on the list of locales to
Expand All @@ -3669,7 +3669,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn)

# ifdef LC_ALL

sl_result[LC_ALL_INDEX_] = setlocale_c(LC_ALL, trial_locale);
sl_result[LC_ALL_INDEX_] = stdized_setlocale(LC_ALL, trial_locale);
DEBUG_LOCALE_INIT(LC_ALL_INDEX_, trial_locale, sl_result[LC_ALL_INDEX_]);
if (! sl_result[LC_ALL_INDEX_]) {
setlocale_failure = TRUE;
Expand All @@ -3690,7 +3690,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
if (! setlocale_failure) {
unsigned int j;
for (j = 0; j < NOMINAL_LC_ALL_INDEX; j++) {
curlocales[j] = setlocale_i(j, trial_locale);
curlocales[j] = stdized_setlocale(categories[j], trial_locale);
if (! curlocales[j]) {
setlocale_failure = TRUE;
}
Expand Down Expand Up @@ -3877,7 +3877,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn)

for (j = 0; j < NOMINAL_LC_ALL_INDEX; j++) {
Safefree(curlocales[j]);
curlocales[j] = savepv(querylocale_i(j));
curlocales[j] = savepv(stdized_setlocale(categories[j], NULL));
DEBUG_LOCALE_INIT(j, NULL, curlocales[j]);
}
}
Expand Down Expand Up @@ -3916,6 +3916,16 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
}
} /* End of tried to fallback */

# ifdef USE_POSIX_2008_LOCALE

/* The stdized setlocales haven't affected the P2008 locales. Initialize
* them now, */
for (i = 0; i < NOMINAL_LC_ALL_INDEX; i++) {
void_setlocale_i(i, curlocales[i]);
}

# endif

/* Done with finding the locales; update our records */
new_LC_ALL(NULL);

Expand Down

0 comments on commit 6b0fdae

Please sign in to comment.