summaryrefslogtreecommitdiff
path: root/locale.c
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2022-09-07 20:59:41 -0600
committerKarl Williamson <khw@cpan.org>2022-09-10 09:45:59 -0600
commit3014c9721628fac7b68b2f59451f4515dcbae96a (patch)
treedcdc977a392e91bfaf8a3f516199daad684ca6a5 /locale.c
parente464e1ed069fae7acb29f65db0bf2c98c4af355a (diff)
downloadperl-3014c9721628fac7b68b2f59451f4515dcbae96a.tar.gz
locale.c: Use locale change subs at initialization
There are currently 4 functions that do special handling when the locale for their respective categories changes. One of these is for LC_ALL, which has and continues to be called at the end of initialization. But the other three have changed in recent commits to handle the trivial case specially of the locale being "C". These changes now avoid the complexities required for the general case (that needs everything to be set up at the time of the call). They can thus be called early in the initialization precess. This avoids having to duplicate their logics in the initialization code, which has led to some things being overlooked there. Now everything is guaranteed to stay in sync.
Diffstat (limited to 'locale.c')
-rw-r--r--locale.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/locale.c b/locale.c
index 1dfd5d6b96..00fcb022a8 100644
--- a/locale.c
+++ b/locale.c
@@ -1672,7 +1672,9 @@ S_new_numeric(pTHX_ const char *newnum)
Safefree(PL_numeric_name);
PL_numeric_name = savepv(newnum);
- /* Handle the trivial case */
+ /* Handle the trivial case. Since this is called at process
+ * initialization, be aware that this bit can't rely on much being
+ * available. */
if (isNAME_C_OR_POSIX(PL_numeric_name)) {
PL_numeric_standard = TRUE;
PL_numeric_underlying_is_standard = TRUE;
@@ -1849,7 +1851,9 @@ S_new_ctype(pTHX_ const char *newctype)
PL_in_utf8_turkic_locale = FALSE;
/* For the C locale, just use the standard folds, and we know there are no
- * glitches possible, so return early */
+ * glitches possible, so return early. Since this is called at process
+ * initialization, be aware that this bit can't rely on much being
+ * available. */
if (isNAME_C_OR_POSIX(newctype)) {
Copy(PL_fold, PL_fold_locale, 256, U8);
PL_ctype_name = savepv(newctype);
@@ -2286,11 +2290,11 @@ S_new_collate(pTHX_ const char *newcoll)
PL_collation_name = savepv(newcoll);
++PL_collation_ix;
- /* Set the new one up if trivial */
+ /* Set the new one up if trivial. Since this is called at process
+ * initialization, be aware that this bit can't rely on much being
+ * available. */
PL_collation_standard = isNAME_C_OR_POSIX(newcoll);
if (PL_collation_standard) {
-
- /* Do minimal set up now */
DEBUG_Lv(PerlIO_printf(Perl_debug_log, "Setting PL_collation name='%s'\n", PL_collation_name));
PL_collxfrm_base = 0;
PL_collxfrm_mult = 2;
@@ -4673,16 +4677,22 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
# endif
# ifdef USE_LOCALE_NUMERIC
- PL_numeric_radix_sv = newSVpvn(C_decimal_point, strlen(C_decimal_point));
- PL_underlying_radix_sv = newSVpvn(C_decimal_point, strlen(C_decimal_point));
- Newx(PL_numeric_name, 2, char);
- Copy("C", PL_numeric_name, 2, char);
+ PL_numeric_radix_sv = newSV(1);
+ PL_underlying_radix_sv = newSV(1);
+ Newxz(PL_numeric_name, 1, char); /* Single NUL character */
+ new_numeric("C");
# endif
# ifdef USE_LOCALE_COLLATE
- Newx(PL_collation_name, 2, char);
- Copy("C", PL_collation_name, 2, char);
+ Newxz(PL_collation_name, 1, char);
+ new_collate("C");
+
+# endif
+# ifdef USE_LOCALE_CTYPE
+
+ Newxz(PL_ctype_name, 1, char);
+ new_ctype("C");
# endif
# ifdef USE_PL_CURLOCALES