Skip to content

Smoke me/khw want #21549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -2755,11 +2755,17 @@ S_calculate_LC_ALL_string(pTHX_ const char ** category_locales_list,
*
* The caller sets 'returning' to
* WANT_TEMP_PV the function returns the calculated string
* as a mmortalized temporary, so the caller
* as a mortalized temporary, so the caller
* doesn't have to worry about it being
* per-thread, nor needs to arrange for its
* clean-up.
* WANT_VOID NULL is returned. This is used when the
* WANT_PL_setlocale_buf the function stores the calculated string
* into the per-thread buffer PL_setlocale_buf
* and returns a pointer to that. The buffer
* is cleaned up automatically in process
* destruction. This return method avoids
* extra copies in some circumstances.
* WANT_VOID NULL is returned. This is used when the
* function is being called only for its side
* effect of updating
* PL_curlocales[LC_ALL_INDEX_]
Expand Down Expand Up @@ -2899,12 +2905,18 @@ S_calculate_LC_ALL_string(pTHX_ const char ** category_locales_list,
}

bool free_if_void_return = false;

/* Done iterating through all the categories. */
const char * retval;

/* If all categories have the same locale, we already know the answer */
if (! disparate) {
if (returning == WANT_PL_setlocale_buf) {
save_to_buffer(locales_list[0],
&PL_setlocale_buf,
&PL_setlocale_bufsize);
retval = PL_setlocale_buf;
}
else {

retval = locales_list[0];

/* If a temporary is wanted for the return, and we had to create
Expand All @@ -2916,12 +2928,25 @@ S_calculate_LC_ALL_string(pTHX_ const char ** category_locales_list,
SAVEFREEPV(retval);
}

/* In all cases here, there's nothing we create that needs to be freed,
* so leave 'free_if_void_return' set to the default 'false'. */
/* In all cases here, there's nothing we create that needs to be
* freed, so leave 'free_if_void_return' set to the default
* 'false'. */
}
}
else { /* Here, not all categories have the same locale */

char * constructed;
char * constructed;

/* If returning to PL_setlocale_buf, set up to write directly to it,
* being sure it is resized to be large enough */
if (returning == WANT_PL_setlocale_buf) {
set_save_buffer_min_size(total_len,
&PL_setlocale_buf,
&PL_setlocale_bufsize);
constructed = PL_setlocale_buf;
}
else { /* Otherwise we need new memory to hold the calculated value. */

Newx(constructed, total_len, char);

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

constructed[0] = '\0';

Expand Down