From 017ae99f55be63ddb5b159f9c6c5fe977adbea82 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Fri, 17 Nov 2023 06:27:22 -0700 Subject: [PATCH] mismatched ctype --- locale.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/locale.c b/locale.c index 4bb91e687205..167025326f03 100644 --- a/locale.c +++ b/locale.c @@ -414,6 +414,13 @@ static int debug_initialization = 0; #define PERL_IN_LOCALE_C #include "perl.h" +/* Some platforms require LC_CTYPE to be congruent with the category we are + * looking for. XXX This still presumes that we have to match COLLATE and + * CTYPE even on platforms that apparently handle this. */ +#if defined(USE_LOCALE_CTYPE) && ! defined(LIBC_HANDLES_MISMATCHED_CTYPE) +# define WE_MUST_DEAL_WITH_MISMATCHED_CTYPE +#endif + #if PERL_VERSION_GT(5,39,9) # error Revert the commit that added this line #endif @@ -5890,10 +5897,8 @@ S_populate_hash_from_localeconv(pTHX_ HV * hv, * global static buffer. Some locks might be no-ops on this platform, but * not others. We need to lock if any one isn't a no-op. */ -# ifdef USE_LOCALE_CTYPE +# ifdef WE_MUST_DEAL_WITH_MISMATCHED_CTYPE - /* Some platforms require LC_CTYPE to be congruent with the category we are - * looking for */ const char * orig_CTYPE_locale = toggle_locale_c(LC_CTYPE, locale); LC_CTYPE_LOCK; @@ -6117,8 +6122,8 @@ S_populate_hash_from_localeconv(pTHX_ HV * hv, LC_NUMERIC_UNLOCK; } -# endif -# ifdef USE_LOCALE_CTYPE +# endif +# ifdef WE_MUST_DEAL_WITH_MISMATCHED_CTYPE restore_toggled_locale_c(LC_CTYPE, orig_CTYPE_locale); LC_CTYPE_UNLOCK; @@ -6543,7 +6548,7 @@ S_my_langinfo_i(pTHX_ # define NL_LANGINFO_LOCK(cat_index) LC_CATEGORY_LOCK_i_(cat_index) # define NL_LANGINFO_UNLOCK(cat_index) LC_CATEGORY_UNLOCK_i_(cat_index) # endif -# ifdef USE_LOCALE_CTYPE +# ifdef WE_MUST_DEAL_WITH_MISMATCHED_CTYPE /* This function sorts out if things actually have to be switched or not, * for both save and restore. */ @@ -6565,7 +6570,7 @@ S_my_langinfo_i(pTHX_ restore_toggled_locale_i(cat_index, orig_switched_locale); -# ifdef USE_LOCALE_CTYPE +# ifdef WE_MUST_DEAL_WITH_MISMATCHED_CTYPE restore_toggled_locale_c(LC_CTYPE, orig_CTYPE_locale); @@ -6578,7 +6583,7 @@ S_my_langinfo_i(pTHX_ /* The other completion is where we have to emulate nl_langinfo(). There * are various possibilities depending on the Configuration */ -# ifdef USE_LOCALE_CTYPE +# ifdef WE_MUST_DEAL_WITH_MISMATCHED_CTYPE const char * orig_CTYPE_locale = toggle_locale_c(LC_CTYPE, locale); @@ -7328,7 +7333,7 @@ S_my_langinfo_i(pTHX_ restore_toggled_locale_i(cat_index, orig_switched_locale); -# ifdef USE_LOCALE_CTYPE +# ifdef WE_MUST_DEAL_WITH_MISMATCHED_CTYPE restore_toggled_locale_c(LC_CTYPE, orig_CTYPE_locale); # endif @@ -7440,7 +7445,7 @@ S_strftime_tm(pTHX_ const char *fmt, const struct tm *mytm) #ifndef HAS_STRFTIME Perl_croak(aTHX_ "panic: no strftime"); #else -# if defined(USE_LOCALE_CTYPE) && defined(USE_LOCALE_TIME) +# if defined(WE_MUST_DEAL_WITH_MISMATCHED_CTYPE) && defined(USE_LOCALE_TIME) const char * orig_CTYPE_LOCALE = toggle_locale_c(LC_CTYPE, querylocale_c(LC_TIME)); @@ -7521,7 +7526,7 @@ S_strftime_tm(pTHX_ const char *fmt, const struct tm *mytm) strftime_return: -# if defined(USE_LOCALE_CTYPE) && defined(USE_LOCALE_TIME) +# if defined(WE_MUST_DEAL_WITH_MISMATCHED_CTYPE) && defined(USE_LOCALE_TIME) restore_toggled_locale_c(LC_CTYPE, orig_CTYPE_LOCALE);