Skip to content

Commit

Permalink
locale.c(): Use LC_ALL if available
Browse files Browse the repository at this point in the history
Now that we have code that works on platforms with differing ways of
representing LC_ALL, we can use it instead of looping through all the
subcomponents.
  • Loading branch information
khwilliamson committed Apr 23, 2023
1 parent 00b0fa0 commit f2952c1
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -7940,31 +7940,50 @@ Perl_sync_locale(pTHX)

/* Here, we are in the global locale. Get and save the values for each
* category. */

# ifdef LC_ALL

STDIZED_SETLOCALE_LOCK;
const char * lc_all_string = savepv(stdized_setlocale(LC_ALL, NULL));
STDIZED_SETLOCALE_UNLOCK;

# else

const char * current_globals[LC_ALL_INDEX_];
for (unsigned i = 0; i < LC_ALL_INDEX_; i++) {
STDIZED_SETLOCALE_LOCK;
current_globals[i] = savepv(stdized_setlocale(categories[i], NULL));
STDIZED_SETLOCALE_UNLOCK;
}

# endif

/* Now we have to convert the current thread to use them */

# if defined(WIN32)

/* On Windows, convert to per-thread behavior. This isn't necessary in
* POSIX 2008, as the conversion gets done automatically in the loop below.
* */
* POSIX 2008, as the conversion gets done automatically below in the
* void_X calls. */
if (_configthreadlocale(_ENABLE_PER_THREAD_LOCALE) == -1) {
locale_panic_("_configthreadlocale returned an error");
}

# endif
# ifdef LC_ALL

void_setlocale_c(LC_ALL, lc_all_string);
Safefree(lc_all_string);

# else

for (unsigned i = 0; i < LC_ALL_INDEX_; i++) {
void_setlocale_i(i, current_globals[i]);
Safefree(current_globals[i]);
}

# endif

/* And update our remaining records. 'true' => force recalculation */
new_LC_ALL(NULL, true);

Expand Down

0 comments on commit f2952c1

Please sign in to comment.