This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
locale.c: toggle LC_CTYPE in S_override
authorKarl Williamson <khw@cpan.org>
Wed, 27 Dec 2023 13:10:57 +0000 (06:10 -0700)
committerKarl Williamson <khw@cpan.org>
Wed, 3 Jan 2024 04:05:47 +0000 (21:05 -0700)
Commit 0b60dbbe529b372662069aaadf3dfcf18f85c1cc missed this.  Most of
this function must be done in the requested locale so that the libc
functions work on the correct underlying locale.

locale.c

index af58f7d..0c8094a 100644 (file)
--- a/locale.c
+++ b/locale.c
@@ -6556,6 +6556,8 @@ S_override_codeset_if_utf8_found(pTHX_ const char * codeset,
         lean_towards_being_utf8 |= NAME_INDICATES_UTF8;
     }
 
+    const char * orig_CTYPE_locale = toggle_locale_c(LC_CTYPE, locale);
+
     /* For this portion of the file to compile, some C99 functions aren't
      * available to us, even though we now require C99.  So, something must be
      * wrong with them.  The code here should be good enough to work around
@@ -6583,12 +6585,14 @@ S_override_codeset_if_utf8_found(pTHX_ const char * codeset,
             return "";    /* The name is wrong; override */
         }
 
+        restore_toggled_locale_c(LC_CTYPE, orig_CTYPE_locale);
         return codeset;
     }
 
     /* But if the locale could be UTF-8, and also the name corroborates this,
      * assume it is so */
     if (lean_towards_being_utf8 & NAME_INDICATES_UTF8) {
+        restore_toggled_locale_c(LC_CTYPE, orig_CTYPE_locale);
         return codeset;
     }
 
@@ -6748,6 +6752,8 @@ S_override_codeset_if_utf8_found(pTHX_ const char * codeset,
 
 #    endif
 
+    restore_toggled_locale_c(LC_CTYPE, orig_CTYPE_locale);
+
     Safefree(scratch_buf);
     scratch_buf = NULL;