summaryrefslogtreecommitdiff
path: root/locale.c
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2022-12-16 08:19:24 -0700
committerKarl Williamson <khw@cpan.org>2022-12-20 05:53:42 -0700
commitdf08369eedb6c7ccdea859fb0edd7cbfc82930cd (patch)
treec9d5078770f12bde1ae8e6d9b7bd17f545267801 /locale.c
parentabf1aa2b099b9613c2e6901d3f61eb8da735d934 (diff)
downloadperl-df08369eedb6c7ccdea859fb0edd7cbfc82930cd.tar.gz
locale.c: Clarifications
This commit adds/improves some comments, changes a variable name, and adds some parentheses, and moves a declaration (since we now use C99).
Diffstat (limited to 'locale.c')
-rw-r--r--locale.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/locale.c b/locale.c
index 5417e67c75..d2117d2ca3 100644
--- a/locale.c
+++ b/locale.c
@@ -6786,10 +6786,9 @@ Perl_switch_to_global_locale(pTHX)
#ifdef USE_LOCALE
- bool perl_controls = false;
-
DEBUG_L(PerlIO_printf(Perl_debug_log, "Entering switch_to_global; %s\n",
get_LC_ALL_display()));
+ bool perl_controls = false;
# ifdef USE_THREAD_SAFE_LOCALE
@@ -6798,11 +6797,11 @@ Perl_switch_to_global_locale(pTHX)
# ifdef USE_POSIX_2008_LOCALE
- perl_controls = LC_GLOBAL_LOCALE != uselocale((locale_t) 0);
+ perl_controls = (LC_GLOBAL_LOCALE != uselocale((locale_t) 0));
# elif defined(WIN32)
- perl_controls = _configthreadlocale(0) == _ENABLE_PER_THREAD_LOCALE;
+ perl_controls = (_configthreadlocale(0) == _ENABLE_PER_THREAD_LOCALE);
# else
# error Unexpected Configuration
@@ -6821,19 +6820,21 @@ Perl_switch_to_global_locale(pTHX)
# elif defined(USE_POSIX_2008_LOCALE)
- const char * curlocales[NOMINAL_LC_ALL_INDEX + 1];
+ const char * cur_thread_locales[NOMINAL_LC_ALL_INDEX + 1];
- /* Save each category's current state */
+ /* Save each category's current per-thread state */
for (unsigned i = 0; i < NOMINAL_LC_ALL_INDEX; i++) {
- curlocales[i] = querylocale_i(i);
+ cur_thread_locales[i] = querylocale_i(i);
}
- /* Switch to global */
+ /* Now switch to global */
+
locale_t old_locale = uselocale(LC_GLOBAL_LOCALE);
if (! old_locale) {
locale_panic_(Perl_form(aTHX_ "Could not change to global locale"));
}
+ /* Free the per-thread memory */
if (old_locale != LC_GLOBAL_LOCALE && old_locale != PL_C_locale_obj) {
freelocale(old_locale);
}
@@ -6841,7 +6842,7 @@ Perl_switch_to_global_locale(pTHX)
/* Set the global to what was our per-thread state */
POSIX_SETLOCALE_LOCK;
for (unsigned int i = 0; i < NOMINAL_LC_ALL_INDEX; i++) {
- posix_setlocale(categories[i], curlocales[i]);
+ posix_setlocale(categories[i], cur_thread_locales[i]);
}
POSIX_SETLOCALE_UNLOCK;