Skip to content

Commit

Permalink
locale.c: Clean up thread_locale_init()
Browse files Browse the repository at this point in the history
We can use internal functions to this file instead of the API ones here.
This commit also calls  sync_locale() to avoid repeated logic.
  • Loading branch information
khwilliamson committed May 6, 2021
1 parent 7fd0636 commit c28bfa9
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions locale.c
Expand Up @@ -6343,26 +6343,40 @@ Perl_thread_locale_init()
{
/* Called from a thread on startup*/

#ifdef USE_THREAD_SAFE_LOCALE

dTHX_DEBUGGING;
#if defined(USE_LOCALE_THREADS) \
\
/* It can cause races and totally wrong results to use threads and \
* locales unless there is locale thread safety. So avoid \
* exacerbating that */ \
&& defined(USE_THREAD_SAFE_LOCALE)

dTHX;

DEBUG_L(PerlIO_printf(Perl_debug_log,
"%s:%d: new thread, initial locale is %s; calling setlocale\n",
__FILE__, __LINE__, setlocale(LC_ALL, NULL)));
"%s:%d: new thread, initial locale is %s\n",
__FILE__, __LINE__, porcelain_setlocale(LC_ALL, NULL)));

# ifdef WIN32
if (! sync_locale()) { /* Side effect of going to per-thread if avail */
locale_panic_("Thread unexpectedly started not in global locale");
}

/* On Windows, make sure new thread has per-thread locales enabled */
_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
# ifdef LC_ALL

void_setlocale_c(LC_ALL, "C");

# else

/* This thread starts off in the C locale */
Perl_setlocale(LC_ALL, "C");
{
unsigned int i;
for (i = 0; i < NOMINAL_LC_ALL_INDEX; i++) {
void_setlocale_i(i, "C");
}
}

# endif

new_LC_ALL(NULL);

#endif

}
Expand Down

0 comments on commit c28bfa9

Please sign in to comment.