Skip to content

Commit

Permalink
locale.c: strxfrm() requires LC_CTYPE eq LC_COLLATE
Browse files Browse the repository at this point in the history
The libc functions strxfrm() on some platforms requires the LC_CTYPE
locale to be the same as the LC_COLLATE locale (or rather, probably that
they have the same code set, but checking for locale is cheaper).
Otherwise mojibake would result, or more likely the function will fail,
setting errno.

This commit brings the locales into alignment if necessary
  • Loading branch information
khwilliamson committed May 5, 2021
1 parent 72ae42b commit 926ab66
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions locale.c
Expand Up @@ -5448,6 +5448,16 @@ Perl__mem_collxfrm(pTHX_ const char *input_string,
/* Store the collation id */
*(U32*)xbuf = PL_collation_ix;

# ifdef USE_LOCALE_CTYPE

orig_CTYPE_locale = toggle_locale_c(LC_CTYPE, PL_collation_name);

# define CLEANUP_STRXFRM \
restore_toggled_locale_c(LC_CTYPE, orig_CTYPE_locale)
# else
# define CLEANUP_STRXFRM NOOP
# endif

/* Then the transformation of the input. We loop until successful, or we
* give up */
for (;;) {
Expand Down Expand Up @@ -5581,6 +5591,8 @@ Perl__mem_collxfrm(pTHX_ const char *input_string,
first_time = FALSE;
}

CLEANUP_STRXFRM;

DEBUG_Lv((print_collxfrm_input_and_return(s, s + len, xlen, utf8),
PerlIO_printf(Perl_debug_log, "Its xfrm is:"),
PerlIO_printf(Perl_debug_log, "%s\n",
Expand All @@ -5598,6 +5610,7 @@ Perl__mem_collxfrm(pTHX_ const char *input_string,

bad:

CLEANUP_STRXFRM;
DEBUG_Lv(print_collxfrm_input_and_return(s, s + len, NULL, utf8));

Safefree(xbuf);
Expand Down

0 comments on commit 926ab66

Please sign in to comment.