Skip to content

Commit a7ff7ac

Browse files
committed
locale.c: Use setlocale() for init, not P2008
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 or 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
1 parent 50ffb02 commit a7ff7ac

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

locale.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3604,7 +3604,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
36043604

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

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

36303630
# ifdef LC_ALL
36313631

3632-
sl_result[LC_ALL_INDEX_] = setlocale_c(LC_ALL, trial_locale);
3632+
sl_result[LC_ALL_INDEX_] = stdized_setlocale(LC_ALL, trial_locale);
36333633
DEBUG_LOCALE_INIT(LC_ALL_INDEX_, trial_locale, sl_result[LC_ALL_INDEX_]);
36343634
if (! sl_result[LC_ALL_INDEX_]) {
36353635
setlocale_failure = TRUE;
@@ -3651,7 +3651,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
36513651
unsigned int j;
36523652
for (j = 0; j < NOMINAL_LC_ALL_INDEX; j++) {
36533653
Safefree(curlocales[j]);
3654-
curlocales[j] = setlocale_i(j, trial_locale);
3654+
curlocales[j] = stdized_setlocale(categories[j], trial_locale);
36553655
if (! curlocales[j]) {
36563656
setlocale_failure = TRUE;
36573657
}
@@ -3835,7 +3835,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
38353835

38363836
for (j = 0; j < NOMINAL_LC_ALL_INDEX; j++) {
38373837
Safefree(curlocales[j]);
3838-
curlocales[j] = savepv(querylocale_i(j));
3838+
curlocales[j] = savepv(stdized_setlocale(categories[j], NULL));
38393839
DEBUG_LOCALE_INIT(j, NULL, curlocales[j]);
38403840
}
38413841
}
@@ -3874,6 +3874,16 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
38743874
}
38753875
} /* End of tried to fallback */
38763876

3877+
# ifdef USE_POSIX_2008_LOCALE
3878+
3879+
/* The stdized setlocales haven't affected the P2008 locales. Initialize
3880+
* them now, */
3881+
for (i = 0; i < NOMINAL_LC_ALL_INDEX; i++) {
3882+
void_setlocale_i(i, curlocales[i]);
3883+
}
3884+
3885+
# endif
3886+
38773887
/* Done with finding the locales; update our records */
38783888
new_LC_ALL(NULL);
38793889

0 commit comments

Comments
 (0)