Skip to content

Commit

Permalink
mismatched ctype
Browse files Browse the repository at this point in the history
  • Loading branch information
khwilliamson committed Nov 22, 2023
1 parent 3600f6c commit 017ae99
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions locale.c
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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. */
Expand All @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 017ae99

Please sign in to comment.