From cad501339951bac8067503324ecd9c470813ec29 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Sun, 14 Mar 2021 04:46:54 -0600 Subject: [PATCH] locale.c: Move #define to perl.h; use it elsewhere Rather than recalculate this combined conditional, do it once in perl.h. --- intrpvar.h | 4 +--- locale.c | 4 +--- makedef.pl | 8 +++++++- perl.c | 4 +--- perl.h | 5 +++++ sv.c | 4 +--- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/intrpvar.h b/intrpvar.h index 45bce66d9c47..886efb661b6a 100644 --- a/intrpvar.h +++ b/intrpvar.h @@ -717,9 +717,7 @@ PERLVAR(I, constpadix, PADOFFSET) /* lowest unused for constants */ PERLVAR(I, padix_floor, PADOFFSET) /* how low may inner block reset padix */ -#if defined(USE_POSIX_2008_LOCALE) \ - && defined(USE_THREAD_SAFE_LOCALE) \ - && ! defined(HAS_QUERYLOCALE) +#ifdef USE_PL_CURLOCALES /* This is the most number of categories we've encountered so far on any * platform */ diff --git a/locale.c b/locale.c index a46f8adc435b..bf0866cc6e24 100644 --- a/locale.c +++ b/locale.c @@ -571,9 +571,7 @@ Perl_locale_panic(const char * msg, # define querylocale_c(cat) querylocale_i(cat##_INDEX_) # define querylocale_r(cat) querylocale_i(get_category_index(cat,NULL)) -# ifndef USE_QUERYLOCALE -# define USE_PL_CURLOCALES -# else +# ifdef USE_QUERYLOCALE # define isSINGLE_BIT_SET(mask) isPOWER_OF_2(mask) /* This code used to think querylocale() was valid on LC_ALL. Make sure diff --git a/makedef.pl b/makedef.pl index 4f3d98596fdb..737e605ddba3 100644 --- a/makedef.pl +++ b/makedef.pl @@ -159,6 +159,12 @@ BEGIN $define{USE_POSIX_2008_LOCALE} = 1 if $define{HAS_POSIX_2008_LOCALE}; } +if ( ($define{USE_POSIX_2008_LOCALE} && ! $define{HAS_QUERYLOCALE}) + || ($define{USE_LOCALE_THREADS} && ! $define{USE_THREAD_SAFE_LOCALE})) +{ + $define{USE_PL_CURLOCALES} = 1; +} + if ( $ARGS{PLATFORM} eq 'win32' && $define{USE_THREAD_SAFE_LOCALE} && $cctype < 140) @@ -417,7 +423,7 @@ sub readvar { PL_underlying_numeric_obj ); } -unless ($define{USE_POSIX_2008_LOCALE} && ! $define{HAS_QUERY_LOCALE}) +unless ($define{USE_PL_CURLOCALES}) { ++$skip{$_} foreach qw( PL_curlocales diff --git a/perl.c b/perl.c index 6cfe2f5a750e..36a5ebccd14d 100644 --- a/perl.c +++ b/perl.c @@ -1109,9 +1109,7 @@ perl_destruct(pTHXx) Safefree(PL_collation_name); PL_collation_name = NULL; #endif -#if defined(USE_POSIX_2008_LOCALE) \ - && defined(USE_THREAD_SAFE_LOCALE) \ - && ! defined(HAS_QUERYLOCALE) +#if defined(USE_PL_CURLOCALES) for (i = 0; i < (int) C_ARRAY_LENGTH(PL_curlocales); i++) { Safefree(PL_curlocales[i]); PL_curlocales[i] = NULL; diff --git a/perl.h b/perl.h index 65e54cbb9bc8..4e0148dca17d 100644 --- a/perl.h +++ b/perl.h @@ -1118,6 +1118,11 @@ Example usage: # endif # endif +# if (defined(USE_POSIX_2008_LOCALE) && ! defined(USE_QUERYLOCALE)) \ + || (defined(USE_LOCALE_THREADS) && ! defined(USE_THREAD_SAFE_LOCALE)) +# define USE_PL_CURLOCALES +# endif + /* Microsoft documentation reads in the change log for VS 2015: * "The localeconv function declared in locale.h now works correctly when * per-thread locale is enabled. In previous versions of the library, this diff --git a/sv.c b/sv.c index 23c955bf2af6..a89d47db55f5 100644 --- a/sv.c +++ b/sv.c @@ -15645,9 +15645,7 @@ perl_clone_using(PerlInterpreter *proto_perl, UV flags, PL_subname = sv_dup_inc(proto_perl->Isubname, param); -#if defined(USE_POSIX_2008_LOCALE) \ - && defined(USE_THREAD_SAFE_LOCALE) \ - && ! defined(HAS_QUERYLOCALE) +#ifdef USE_PL_CURLOCALES for (i = 0; i < (int) C_ARRAY_LENGTH(PL_curlocales); i++) { PL_curlocales[i] = SAVEPV(proto_perl->Icurlocales[i]); }