Skip to content

Commit

Permalink
Add USE_LOCALE_THREADS #define
Browse files Browse the repository at this point in the history
This is in preparation for supporting configurations where there threads
are available, but the locale handling code should ignore that fact.

This stems from the unusual locale handling of z/OS, where any attempt
is ignored to change locales after the first thread is created.
  • Loading branch information
khwilliamson committed Apr 29, 2021
1 parent 684a42c commit 9f00008
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
8 changes: 4 additions & 4 deletions locale.c
Expand Up @@ -3572,7 +3572,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn)

for (i = 0; i < NOMINAL_LC_ALL_INDEX; i++) {

# if defined(USE_ITHREADS) && ! defined(USE_THREAD_SAFE_LOCALE)
# if defined(USE_LOCALE_THREADS) && ! defined(USE_THREAD_SAFE_LOCALE)

/* This caches whether each category's locale is UTF-8 or not. This
* may involve changing the locale. It is ok to do this at
Expand Down Expand Up @@ -4472,7 +4472,7 @@ Perl__is_cur_LC_category_utf8(pTHX_ int category)
int len;
dSAVEDERRNO;

# if defined(HAS_MBRTOWC) && defined(USE_ITHREADS)
# if defined(HAS_MBRTOWC) && defined(USE_LOCALE_THREADS)

mbstate_t ps;

Expand All @@ -4482,7 +4482,7 @@ Perl__is_cur_LC_category_utf8(pTHX_ int category)
* character. Feed a byte string to one of them and check that the
* result is the expected Unicode code point */

# if defined(HAS_MBRTOWC) && defined(USE_ITHREADS)
# if defined(HAS_MBRTOWC) && defined(USE_LOCALE_THREADS)
/* Prefer this function if available, as it's reentrant */

memzero(&ps, sizeof(ps));;
Expand Down Expand Up @@ -4933,7 +4933,7 @@ Perl_my_strerror(pTHX_ const int errnum)

const bool within_locale_scope = IN_LC(LC_MESSAGES);

# ifndef USE_ITHREADS
# ifndef USE_LOCALE_THREADS

/* This function is trivial without threads. */
if (within_locale_scope) {
Expand Down
8 changes: 5 additions & 3 deletions makedef.pl
Expand Up @@ -142,11 +142,14 @@ BEGIN

# https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B#Internal_version_numbering
my $cctype = $ARGS{CCTYPE} =~ s/MSVC//r;
if ($define{USE_ITHREADS} && ! $define{NO_LOCALE_THREADS}) {
$define{USE_LOCALE_THREADS} = 1;
}
if (! $define{HAS_SETLOCALE} && $define{HAS_POSIX_2008_LOCALE}) {
$define{USE_POSIX_2008_LOCALE} = 1;
$define{USE_THREAD_SAFE_LOCALE} = 1;
}
elsif ( ($define{USE_ITHREADS} || $define{USE_THREAD_SAFE_LOCALE})
elsif ( ($define{USE_LOCALE_THREADS} || $define{USE_THREAD_SAFE_LOCALE})
&& ( $define{HAS_POSIX_2008_LOCALE}
|| ($ARGS{PLATFORM} eq 'win32' && ( $cctype !~ /\D/
&& $cctype >= 80)))
Expand Down Expand Up @@ -407,8 +410,7 @@ sub readvar {
);
}

if ( $define{NO_LOCALE}
|| (! $define{USE_ITHREADS} && ! $define{USE_THREAD_SAFE_LOCALE}))
unless ($define{USE_POSIX_2008_LOCALE})
{
++$skip{$_} foreach qw(
PL_C_locale_obj
Expand Down
9 changes: 6 additions & 3 deletions perl.h
Expand Up @@ -1076,6 +1076,9 @@ Example usage:
/* XXX The next few defines are unfortunately duplicated in makedef.pl, and
* changes here MUST also be made there */

# if defined(USE_ITHREADS) && ! defined(NO_LOCALE_THREADS)
# define USE_LOCALE_THREADS
# endif
# if ! defined(HAS_SETLOCALE) && defined(HAS_POSIX_2008_LOCALE)
# define USE_POSIX_2008_LOCALE
# ifndef USE_THREAD_SAFE_LOCALE
Expand All @@ -1084,7 +1087,7 @@ Example usage:
/* If compiled with
* -DUSE_THREAD_SAFE_LOCALE, will do so even
* on unthreaded builds */
# elif (defined(USE_ITHREADS) || defined(USE_THREAD_SAFE_LOCALE)) \
# elif (defined(USE_LOCALE_THREADS) || defined(USE_THREAD_SAFE_LOCALE)) \
&& ( defined(HAS_POSIX_2008_LOCALE) \
|| (defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1400)) \
&& ! defined(NO_THREAD_SAFE_LOCALE)
Expand Down Expand Up @@ -6629,7 +6632,7 @@ the plain locale pragma without a parameter (S<C<use locale>>) is in effect.

/* Locale/thread synchronization macros. */
#if ! ( defined(USE_LOCALE) \
&& defined(USE_ITHREADS) \
&& defined(USE_LOCALE_THREADS) \
&& ( ! defined(USE_THREAD_SAFE_LOCALE) \
|| ( defined(HAS_LOCALECONV) \
&& ( ! defined(HAS_LOCALECONV_L) \
Expand Down Expand Up @@ -7151,7 +7154,7 @@ cannot have changed since the precalculation.

#endif /* !USE_LOCALE_NUMERIC */

#ifdef USE_ITHREADS
#ifdef USE_LOCALE_THREADS
# define ENV_LOCK PERL_WRITE_LOCK(&PL_env_mutex)
# define ENV_UNLOCK PERL_WRITE_UNLOCK(&PL_env_mutex)
# define ENV_READ_LOCK PERL_READ_LOCK(&PL_env_mutex)
Expand Down

0 comments on commit 9f00008

Please sign in to comment.