Skip to content

Commit

Permalink
locale.c: Slight refactor of switch_to_global_locale()
Browse files Browse the repository at this point in the history
Now that we can better handle any legal LC_ALL string, we can just use
LC_ALL when available.
  • Loading branch information
khwilliamson committed May 6, 2023
1 parent 0994462 commit d7d161e
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions locale.c
Expand Up @@ -7920,24 +7920,20 @@ Perl_switch_to_global_locale(pTHX)
DEBUG_L(PerlIO_printf(Perl_debug_log, "Entering switch_to_global; %s\n",
get_LC_ALL_display()));

# ifdef USE_THREAD_SAFE_LOCALE

/* In these cases, we use the system state to determine if we are in the
* global locale or not. */

# ifdef USE_POSIX_2008_LOCALE
# ifdef USE_POSIX_2008_LOCALE

const bool perl_controls = (LC_GLOBAL_LOCALE != uselocale((locale_t) 0));

# elif defined(WIN32)
# elif defined(USE_THREAD_SAFE_LOCALE) && defined(WIN32)

int config_return = _configthreadlocale(0);
if (config_return == -1) {
locale_panic_("_configthreadlocale returned an error");
}
const bool perl_controls = (config_return == _ENABLE_PER_THREAD_LOCALE);

# endif
# else

const bool perl_controls = false;
Expand All @@ -7949,14 +7945,14 @@ Perl_switch_to_global_locale(pTHX)
return;
}

# ifdef USE_THREAD_SAFE_LOCALE
# if defined(WIN32)
# ifdef LC_ALL

const char * thread_locale = querylocale_c(LC_ALL);

const char * thread_locale = posix_setlocale(LC_ALL, NULL);
CHANGE_SYSTEM_LOCALE_TO_GLOBAL;
posix_setlocale(LC_ALL, thread_locale);

# else /* Must be USE_POSIX_2008_LOCALE) */
# else /* Must be USE_POSIX_2008_LOCALE) */

const char * cur_thread_locales[LC_ALL_INDEX_];

Expand All @@ -7974,7 +7970,6 @@ Perl_switch_to_global_locale(pTHX)
}
POSIX_SETLOCALE_UNLOCK;

# endif
# endif
# ifdef USE_LOCALE_NUMERIC

Expand Down

0 comments on commit d7d161e

Please sign in to comment.