Skip to content

Commit

Permalink
locale.c: Rmv no longer used param from static fnc
Browse files Browse the repository at this point in the history
Previous commits have gotten rid of this parameter to S_save_to_buffer
  • Loading branch information
khwilliamson committed Aug 10, 2022
1 parent a92a41d commit 8510814
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
3 changes: 1 addition & 2 deletions embed.fnc
Expand Up @@ -3307,8 +3307,7 @@ iR |const char *|mortalized_pv_copy|NULLOK const char * const pv
# ifdef USE_LOCALE
ST |const char *|save_to_buffer|NULLOK const char * string \
|NULLOK const char **buf \
|NULLOK Size_t *buf_size \
|const Size_t offset
|NULLOK Size_t *buf_size
ST |const char*|category_name |const int category
ST |unsigned int|get_category_index|const int category|NULLOK const char * locale
S |const char*|switch_category_locale_to_template|const int switch_category|const int template_category|NULLOK const char * template_locale
Expand Down
60 changes: 43 additions & 17 deletions locale.c
Expand Up @@ -1358,7 +1358,7 @@ S_stdize_locale(pTHX_ const int category,
retval = input_locale; /* The input can be returned unchanged */
}
else {
retval = save_to_buffer(querylocale_c(LC_ALL), buf, buf_size, 0);
retval = save_to_buffer(querylocale_c(LC_ALL), buf, buf_size);
}

for (i = 0; i < NOMINAL_LC_ALL_INDEX; i++) {
Expand All @@ -1377,7 +1377,7 @@ S_stdize_locale(pTHX_ const int category,

/* Here, there was a problem in an individual category. This means that at
* least one adjustment will be necessary. Create a modifiable copy */
retval = save_to_buffer(input_locale, buf, buf_size, 0);
retval = save_to_buffer(input_locale, buf, buf_size);

if (*first_bad != '=') {

Expand Down Expand Up @@ -2642,7 +2642,7 @@ Perl_setlocale(const int category, const char * locale)

/* This toggling back could destroy 'retval' */
retval = save_to_buffer(retval,
&PL_setlocale_buf, &PL_setlocale_bufsize, 0);
&PL_setlocale_buf, &PL_setlocale_bufsize);
set_numeric_standard();
}

Expand Down Expand Up @@ -2680,7 +2680,7 @@ Perl_setlocale(const int category, const char * locale)

/* Here, an actual change is being requested. Do it */
retval = save_to_buffer(setlocale_i(cat_index, locale),
&PL_setlocale_buf, &PL_setlocale_bufsize, 0);
&PL_setlocale_buf, &PL_setlocale_bufsize);
if (! retval) {
DEBUG_L(PerlIO_printf(Perl_debug_log, "%s\n",
setlocale_debug_string_i(cat_index, locale, "NULL")));
Expand All @@ -2695,7 +2695,7 @@ Perl_setlocale(const int category, const char * locale)
* returning, so the value will be restored to what it is now. */
if (affects_LC_NUMERIC(category)) {
retval = save_to_buffer(retval,
&PL_setlocale_buf, &PL_setlocale_bufsize, 0);
&PL_setlocale_buf, &PL_setlocale_bufsize);
}

/* Now that have changed locales, we have to update our records to
Expand All @@ -2715,11 +2715,27 @@ Perl_setlocale(const int category, const char * locale)
#ifdef USE_LOCALE

STATIC const char *
S_save_to_buffer(const char * string, const char **buf, Size_t *buf_size,
const Size_t offset)
S_save_to_buffer(const char * string, const char **buf, Size_t *buf_size)
{
/* Copy the NUL-terminated 'string' to 'buf' + 'offset'. 'buf' has size
* 'buf_size', growing it if necessary */
/* Copy the NUL-terminated 'string' to a buffer whose address before this
* call began at *buf, and whose available length before this call was
* *buf_size.
*
* If the length of 'string' is greater than the space available, the
* buffer is grown accordingly, which may mean that it gets relocated.
* *buf and *buf_size will be updated to reflect this.
*
* Regardless, the function returns a pointer to where 'string' is now
* stored.
*
* 'string' may be NULL, which means no action gets taken, and NULL is
* returned.
*
* If *buf or 'buf_size' are NULL or *buf_size is 0, the buffer is assumed
* empty, and memory is malloc'd. 'buf-size' being NULL is to be used
* when this is a single use buffer, which will shortly be freed by the
* caller.
*/

Size_t string_size;

Expand All @@ -2729,7 +2745,7 @@ S_save_to_buffer(const char * string, const char **buf, Size_t *buf_size,
return NULL;
}

string_size = strlen(string) + offset + 1;
string_size = strlen(string) + 1;

if (buf_size == NULL) {
Newx(*buf, string_size, char);
Expand All @@ -2743,7 +2759,17 @@ S_save_to_buffer(const char * string, const char **buf, Size_t *buf_size,
*buf_size = string_size;
}

Copy(string, *buf + offset, string_size - offset, char);
{
dTHX_DEBUGGING;
DEBUG_Lv(PerlIO_printf(Perl_debug_log,
"Copying '%s' to %p\n",
((is_utf8_string((U8 *) string, 0))
? string
:_byte_dump_string((U8 *) string, strlen(string), 0)),
*buf));
}

Copy(string, *buf, string_size, char);
return *buf;
}

Expand Down Expand Up @@ -3111,7 +3137,7 @@ S_my_langinfo(const nl_item item, bool toggle)
* RESTORE_LC_NUMERIC may do just below. */
retval = save_to_buffer(nl_langinfo(item),
((const char **) &PL_langinfo_buf),
&PL_langinfo_bufsize, 0);
&PL_langinfo_bufsize);
NL_LANGINFO_UNLOCK;

if (toggle) {
Expand Down Expand Up @@ -3142,7 +3168,7 @@ S_my_langinfo(const nl_item item, bool toggle)
* can invalidate the internal one */
retval = save_to_buffer(nl_langinfo_l(item, cur),
((const char **) &PL_langinfo_buf),
&PL_langinfo_bufsize, 0);
&PL_langinfo_bufsize);
}

# endif
Expand Down Expand Up @@ -3229,7 +3255,7 @@ S_my_langinfo(const nl_item item, bool toggle)

retval = save_to_buffer(Perl_form(aTHX_ "%c%s", precedes, currency),
((const char **) &PL_langinfo_buf),
&PL_langinfo_bufsize, 0);
&PL_langinfo_bufsize);
}

# ifdef TS_W32_BROKEN_LOCALECONV
Expand Down Expand Up @@ -3358,7 +3384,7 @@ S_my_langinfo(const nl_item item, bool toggle)

retval = save_to_buffer(temp,
((const char **) &PL_langinfo_buf),
&PL_langinfo_bufsize, 0);
&PL_langinfo_bufsize);

# ifdef TS_W32_BROKEN_LOCALECONV

Expand Down Expand Up @@ -3488,7 +3514,7 @@ S_my_langinfo(const nl_item item, bool toggle)
const char * temp = my_strftime(format, 30, 30, hour, mday, mon,
2011, 0, 0, 0);
retval = save_to_buffer(temp, (const char **) &PL_langinfo_buf,
&PL_langinfo_bufsize, 0);
&PL_langinfo_bufsize);
Safefree(temp);

/* If the item is 'ALT_DIGITS', 'PL_langinfo_buf' contains the
Expand Down Expand Up @@ -3569,7 +3595,7 @@ S_my_langinfo(const nl_item item, bool toggle)

retval = save_to_buffer(retval,
((const char **) &PL_langinfo_buf),
&PL_langinfo_bufsize, 0);
&PL_langinfo_bufsize);
}

break;
Expand Down
2 changes: 1 addition & 1 deletion proto.h
Expand Up @@ -5641,7 +5641,7 @@ STATIC void S_new_numeric(pTHX_ const char* newnum);
#define PERL_ARGS_ASSERT_NEW_NUMERIC
STATIC void S_restore_switched_locale(pTHX_ const int category, const char * const original_locale);
#define PERL_ARGS_ASSERT_RESTORE_SWITCHED_LOCALE
STATIC const char * S_save_to_buffer(const char * string, const char **buf, Size_t *buf_size, const Size_t offset);
STATIC const char * S_save_to_buffer(const char * string, const char **buf, Size_t *buf_size);
#define PERL_ARGS_ASSERT_SAVE_TO_BUFFER
STATIC void S_set_numeric_radix(pTHX_ const bool use_locale);
#define PERL_ARGS_ASSERT_SET_NUMERIC_RADIX
Expand Down

0 comments on commit 8510814

Please sign in to comment.