summaryrefslogtreecommitdiff
path: root/locale.c
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2022-10-03 08:33:55 -0600
committerKarl Williamson <khw@cpan.org>2022-10-18 06:22:16 -0600
commit6a4065f28f30d59e3a6cea6504be34bdb5e5eb8b (patch)
tree6f7ebbc29f3e2463dd19d5800b6f7e0b557fdef7 /locale.c
parent7de8159af380f738facd9db4aa5455f02ba5af04 (diff)
downloadperl-6a4065f28f30d59e3a6cea6504be34bdb5e5eb8b.tar.gz
locale: Create special variable to hold current LC_ALL
Some configurations require us to store the current locale for each category. Prior to this commit, this was done in the array PL_curlocales, with the entry for LC_ALL being in the highest element. Future commits will need just the value for LC_ALL in some other configurations, without needing the rest of the array. This commit splits off the LC_ALL element into its own per-interpreter variable to accommodate those. It always had to have special handling anyway beyond the rest of the array elements,
Diffstat (limited to 'locale.c')
-rw-r--r--locale.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/locale.c b/locale.c
index a17c969243..03c1981585 100644
--- a/locale.c
+++ b/locale.c
@@ -848,12 +848,15 @@ S_my_querylocale_i(pTHX_ const unsigned int index)
/* But we do have up-to-date values when we keep our own records
* (except some times in initialization, where we get the value from
* the system. */
- if (PL_curlocales[index] == NULL) {
+ const char ** which = (index == LC_ALL_INDEX_)
+ ? &PL_cur_LC_ALL
+ : &PL_curlocales[index];
+ if (*which == NULL) {
retval = stdized_setlocale(category, NULL);
- PL_curlocales[index] = savepv(retval);
+ *which = savepv(retval);
}
else {
- retval = PL_curlocales[index];
+ retval = *which;
}
# endif
@@ -892,25 +895,23 @@ S_update_PL_curlocales_i(pTHX_
PL_curlocales[i] = savepv(new_locale);
}
- recalc_LC_ALL = YES_RECALC_LC_ALL;
+ Safefree(PL_cur_LC_ALL);
+ PL_cur_LC_ALL = savepv(calculate_LC_ALL(PL_curlocales));
+ return PL_cur_LC_ALL;
}
- else {
- /* Update the single category's record */
- Safefree(PL_curlocales[index]);
- PL_curlocales[index] = savepv(new_locale);
+ /* Update the single category's record */
+ Safefree(PL_curlocales[index]);
+ PL_curlocales[index] = savepv(new_locale);
- if (recalc_LC_ALL == RECALCULATE_LC_ALL_ON_FINAL_INTERATION) {
- recalc_LC_ALL = (index == NOMINAL_LC_ALL_INDEX - 1)
- ? YES_RECALC_LC_ALL
- : DONT_RECALC_LC_ALL;
- }
- }
-
- if (recalc_LC_ALL == YES_RECALC_LC_ALL) {
- Safefree(PL_curlocales[LC_ALL_INDEX_]);
- PL_curlocales[LC_ALL_INDEX_] =
- savepv(calculate_LC_ALL(PL_curlocales));
+ /* And also LC_ALL if the input says to, including if this is the final
+ * iteration of a loop updating all sub-categories */
+ if ( recalc_LC_ALL == YES_RECALC_LC_ALL
+ || ( recalc_LC_ALL == RECALCULATE_LC_ALL_ON_FINAL_INTERATION
+ && index == NOMINAL_LC_ALL_INDEX - 1))
+ {
+ Safefree(PL_cur_LC_ALL);
+ PL_cur_LC_ALL = savepv(calculate_LC_ALL(PL_curlocales));
}
return PL_curlocales[index];
@@ -1044,8 +1045,8 @@ S_setlocale_from_aggregate_LC_ALL(pTHX_ const char * locale, const line_t line)
* categories whose locale is 'C'. khw thinks it's better to store a
* complete LC_ALL. So calculate it. */
const char * retval = savepv(calculate_LC_ALL(PL_curlocales));
- Safefree(PL_curlocales[LC_ALL_INDEX_]);
- PL_curlocales[LC_ALL_INDEX_] = retval;
+ Safefree(PL_cur_LC_ALL);
+ PL_cur_LC_ALL = retval;
# else
@@ -1143,9 +1144,8 @@ S_emulate_setlocale_i(pTHX_
if (UNLIKELY( recalc_LC_ALL == RECALCULATE_LC_ALL_ON_FINAL_INTERATION
&& index == NOMINAL_LC_ALL_INDEX - 1))
{
- Safefree(PL_curlocales[LC_ALL_INDEX_]);
- PL_curlocales[LC_ALL_INDEX_] =
- savepv(calculate_LC_ALL(PL_curlocales));
+ Safefree(PL_cur_LC_ALL);
+ PL_cur_LC_ALL = savepv(calculate_LC_ALL(PL_curlocales));
}
# endif