Skip to content

Commit 6a4065f

Browse files
committed
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,
1 parent 7de8159 commit 6a4065f

File tree

7 files changed

+55
-26
lines changed

7 files changed

+55
-26
lines changed

embedvar.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

intrpvar.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,8 +741,13 @@ PERLVAR(I, padix_floor, PADOFFSET) /* how low may inner block reset padix */
741741
#ifdef USE_PL_CURLOCALES
742742

743743
/* This is the most number of categories we've encountered so far on any
744-
* platform */
745-
PERLVARA(I, curlocales, 12, const char *)
744+
* platform, doesn't include LC_ALL */
745+
PERLVARA(I, curlocales, 11, const char *)
746+
747+
#endif
748+
#ifdef USE_PL_CUR_LC_ALL
749+
750+
PERLVARI(I, cur_LC_ALL, const char *, NULL)
746751

747752
#endif
748753
#ifdef USE_LOCALE_COLLATE

locale.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -848,12 +848,15 @@ S_my_querylocale_i(pTHX_ const unsigned int index)
848848
/* But we do have up-to-date values when we keep our own records
849849
* (except some times in initialization, where we get the value from
850850
* the system. */
851-
if (PL_curlocales[index] == NULL) {
851+
const char ** which = (index == LC_ALL_INDEX_)
852+
? &PL_cur_LC_ALL
853+
: &PL_curlocales[index];
854+
if (*which == NULL) {
852855
retval = stdized_setlocale(category, NULL);
853-
PL_curlocales[index] = savepv(retval);
856+
*which = savepv(retval);
854857
}
855858
else {
856-
retval = PL_curlocales[index];
859+
retval = *which;
857860
}
858861

859862
# endif
@@ -892,25 +895,23 @@ S_update_PL_curlocales_i(pTHX_
892895
PL_curlocales[i] = savepv(new_locale);
893896
}
894897

895-
recalc_LC_ALL = YES_RECALC_LC_ALL;
898+
Safefree(PL_cur_LC_ALL);
899+
PL_cur_LC_ALL = savepv(calculate_LC_ALL(PL_curlocales));
900+
return PL_cur_LC_ALL;
896901
}
897-
else {
898902

899-
/* Update the single category's record */
900-
Safefree(PL_curlocales[index]);
901-
PL_curlocales[index] = savepv(new_locale);
903+
/* Update the single category's record */
904+
Safefree(PL_curlocales[index]);
905+
PL_curlocales[index] = savepv(new_locale);
902906

903-
if (recalc_LC_ALL == RECALCULATE_LC_ALL_ON_FINAL_INTERATION) {
904-
recalc_LC_ALL = (index == NOMINAL_LC_ALL_INDEX - 1)
905-
? YES_RECALC_LC_ALL
906-
: DONT_RECALC_LC_ALL;
907-
}
908-
}
909-
910-
if (recalc_LC_ALL == YES_RECALC_LC_ALL) {
911-
Safefree(PL_curlocales[LC_ALL_INDEX_]);
912-
PL_curlocales[LC_ALL_INDEX_] =
913-
savepv(calculate_LC_ALL(PL_curlocales));
907+
/* And also LC_ALL if the input says to, including if this is the final
908+
* iteration of a loop updating all sub-categories */
909+
if ( recalc_LC_ALL == YES_RECALC_LC_ALL
910+
|| ( recalc_LC_ALL == RECALCULATE_LC_ALL_ON_FINAL_INTERATION
911+
&& index == NOMINAL_LC_ALL_INDEX - 1))
912+
{
913+
Safefree(PL_cur_LC_ALL);
914+
PL_cur_LC_ALL = savepv(calculate_LC_ALL(PL_curlocales));
914915
}
915916

916917
return PL_curlocales[index];
@@ -1044,8 +1045,8 @@ S_setlocale_from_aggregate_LC_ALL(pTHX_ const char * locale, const line_t line)
10441045
* categories whose locale is 'C'. khw thinks it's better to store a
10451046
* complete LC_ALL. So calculate it. */
10461047
const char * retval = savepv(calculate_LC_ALL(PL_curlocales));
1047-
Safefree(PL_curlocales[LC_ALL_INDEX_]);
1048-
PL_curlocales[LC_ALL_INDEX_] = retval;
1048+
Safefree(PL_cur_LC_ALL);
1049+
PL_cur_LC_ALL = retval;
10491050

10501051
# else
10511052

@@ -1143,9 +1144,8 @@ S_emulate_setlocale_i(pTHX_
11431144
if (UNLIKELY( recalc_LC_ALL == RECALCULATE_LC_ALL_ON_FINAL_INTERATION
11441145
&& index == NOMINAL_LC_ALL_INDEX - 1))
11451146
{
1146-
Safefree(PL_curlocales[LC_ALL_INDEX_]);
1147-
PL_curlocales[LC_ALL_INDEX_] =
1148-
savepv(calculate_LC_ALL(PL_curlocales));
1147+
Safefree(PL_cur_LC_ALL);
1148+
PL_cur_LC_ALL = savepv(calculate_LC_ALL(PL_curlocales));
11491149
}
11501150

11511151
# endif

makedef.pl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ BEGIN
172172
if ($define{USE_POSIX_2008_LOCALE} && ! $define{USE_QUERYLOCALE})
173173
{
174174
$define{USE_PL_CURLOCALES} = 1;
175+
$define{USE_PL_CUR_LC_ALL} = 1;
175176
}
176177

177178
if ($ARGS{PLATFORM} eq 'win32' && $define{USE_THREAD_SAFE_LOCALE})
@@ -441,6 +442,13 @@ sub readvar {
441442
);
442443
}
443444

445+
unless ($define{USE_PL_CUR_LC_ALL})
446+
{
447+
++$skip{$_} foreach qw(
448+
PL_cur_LC_ALL
449+
);
450+
}
451+
444452
unless ($define{'MULTIPLICITY'}) {
445453
++$skip{$_} foreach qw(
446454
PL_my_cxt_index

perl.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,17 @@ perl_destruct(pTHXx)
11401140
freelocale(old_locale);
11411141
}
11421142
}
1143+
1144+
# ifdef USE_PL_CUR_LC_ALL
1145+
1146+
if (PL_cur_LC_ALL) {
1147+
DEBUG_L( PerlIO_printf(Perl_debug_log, "PL_cur_LC_ALL=%p\n", PL_cur_LC_ALL));
1148+
Safefree(PL_cur_LC_ALL);
1149+
PL_cur_LC_ALL = NULL;
1150+
}
1151+
1152+
# endif
1153+
11431154
if (PL_scratch_locale_obj) {
11441155
freelocale(PL_scratch_locale_obj);
11451156
PL_scratch_locale_obj = NULL;

perl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,7 @@ violations are fatal.
12671267
* querylocale; so must keep track of it ourselves */
12681268
# if (defined(USE_POSIX_2008_LOCALE) && ! defined(USE_QUERYLOCALE))
12691269
# define USE_PL_CURLOCALES
1270+
# define USE_PL_CUR_LC_ALL
12701271
# endif
12711272

12721273
# if defined(WIN32) && defined(USE_THREAD_SAFE_LOCALE)

sv.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15892,6 +15892,9 @@ perl_clone_using(PerlInterpreter *proto_perl, UV flags,
1589215892
PL_curlocales[i] = SAVEPV("C");
1589315893
}
1589415894
#endif
15895+
#ifdef USE_PL_CUR_LC_ALL
15896+
PL_cur_LC_ALL = SAVEPV("C");
15897+
#endif
1589515898
#ifdef USE_LOCALE_CTYPE
1589615899
Copy(PL_fold, PL_fold_locale, 256, U8);
1589715900

0 commit comments

Comments
 (0)