Skip to content

Commit bb7aa7d

Browse files
committed
locale.c: Handle input parameter
calculate_LC_ALL_string() takes an input parameter specifying where the caller wants the return value to be placed. It wasn't handling one of the possible values for that parameter. This was spotted by Tony Cook. I stashed the code that does the handling during a 'rebase -i', and forgot to unstash it. This fixes #20810
1 parent d992599 commit bb7aa7d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

locale.c

+26
Original file line numberDiff line numberDiff line change
@@ -2759,6 +2759,12 @@ S_calculate_LC_ALL_string(pTHX_ const char ** category_locales_list,
27592759
* doesn't have to worry about it being
27602760
* per-thread, nor needs to arrange for its
27612761
* clean-up.
2762+
* WANT_PL_setlocale_buf the function stores the calculated string
2763+
* into the per-thread buffer PL_setlocale_buf
2764+
* and returns a pointer to that. The buffer
2765+
* is cleaned up automatically in process
2766+
* destruction. This return method avoids
2767+
* extra copies in some circumstances.
27622768
* WANT_VOID NULL is returned. This is used when the
27632769
* function is being called only for its side
27642770
* effect of updating
@@ -2903,6 +2909,14 @@ S_calculate_LC_ALL_string(pTHX_ const char ** category_locales_list,
29032909

29042910
/* If all categories have the same locale, we already know the answer */
29052911
if (! disparate) {
2912+
if (returning == WANT_PL_setlocale_buf) {
2913+
save_to_buffer(locales_list[0],
2914+
&PL_setlocale_buf,
2915+
&PL_setlocale_bufsize);
2916+
retval = PL_setlocale_buf;
2917+
}
2918+
else {
2919+
29062920
retval = locales_list[0];
29072921

29082922
/* If a temporary is wanted for the return, and we had to create
@@ -2917,11 +2931,22 @@ S_calculate_LC_ALL_string(pTHX_ const char ** category_locales_list,
29172931
/* In all cases here, there's nothing we create that needs to be
29182932
* freed, so leave 'free_if_void_return' set to the default
29192933
* 'false'. */
2934+
}
29202935
}
29212936
else { /* Here, not all categories have the same locale */
29222937

29232938
char * constructed;
29242939

2940+
/* If returning to PL_setlocale_buf, set up to write directly to it,
2941+
* being sure it is resized to be large enough */
2942+
if (returning == WANT_PL_setlocale_buf) {
2943+
set_save_buffer_min_size(total_len,
2944+
&PL_setlocale_buf,
2945+
&PL_setlocale_bufsize);
2946+
constructed = PL_setlocale_buf;
2947+
}
2948+
else { /* Otherwise we need new memory to hold the calculated value. */
2949+
29252950
Newx(constructed, total_len, char);
29262951

29272952
/* If returning the new memory, it must be set up to be freed
@@ -2932,6 +2957,7 @@ S_calculate_LC_ALL_string(pTHX_ const char ** category_locales_list,
29322957
else {
29332958
free_if_void_return = true;
29342959
}
2960+
}
29352961

29362962
constructed[0] = '\0';
29372963

0 commit comments

Comments
 (0)