Skip to content

Commit

Permalink
mismatched ctype
Browse files Browse the repository at this point in the history
  • Loading branch information
khwilliamson committed Nov 20, 2023
1 parent 8791a4b commit 9f25f93
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions locale.c
Expand Up @@ -414,6 +414,12 @@ 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 */
#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 @@ -5882,10 +5888,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 @@ -6078,8 +6082,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 @@ -6504,7 +6508,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 @@ -6526,7 +6530,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 @@ -6539,7 +6543,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 @@ -7289,7 +7293,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 @@ -7401,7 +7405,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 @@ -7482,7 +7486,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 9f25f93

Please sign in to comment.