Skip to content

Commit

Permalink
S_parse_LC_ALL_string(): Add parameter
Browse files Browse the repository at this point in the history
This tells the function to panic instead of returning failure upon
encountering an error.
  • Loading branch information
khwilliamson committed May 6, 2023
1 parent d8f9d06 commit 108d513
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions embed.fnc
Expand Up @@ -4393,6 +4393,7 @@ S |void |give_perl_locale_control \
S |parse_LC_ALL_string_return|parse_LC_ALL_string \
|NN const char *string \
|NN const char **output \
|const bool panic_on_error \
|const line_t caller_line
# else
S |void |give_perl_locale_control \
Expand Down
2 changes: 1 addition & 1 deletion embed.h
Expand Up @@ -1295,7 +1295,7 @@
# endif
# if defined(LC_ALL)
# define give_perl_locale_control(a,b) S_give_perl_locale_control(aTHX_ a,b)
# define parse_LC_ALL_string(a,b,c,d) S_parse_LC_ALL_string(aTHX_ a,b,c,d)
# define parse_LC_ALL_string(a,b,c,d,e) S_parse_LC_ALL_string(aTHX_ a,b,c,d,e)
# else
# define give_perl_locale_control(a,b) S_give_perl_locale_control(aTHX_ a,b)
# endif
Expand Down
11 changes: 11 additions & 0 deletions locale.c
Expand Up @@ -234,6 +234,7 @@ S_positional_name_value_xlation(const char * locale, bool direction)
/* This parses either notation */
switch (parse_LC_ALL_string(locale,
(const char **) &individ_locales,
false, /* Don't panic on error */
__LINE__))
{
case invalid:
Expand Down Expand Up @@ -1087,6 +1088,7 @@ Perl_locale_panic(const char * msg,
STATIC parse_LC_ALL_string_return
S_parse_LC_ALL_string(pTHX_ const char * string,
const char ** output,
const bool panic_on_error,
const line_t caller_line)
{
/* This function parses the value of the input 'string' which is expected
Expand Down Expand Up @@ -1119,6 +1121,8 @@ S_parse_LC_ALL_string(pTHX_ const char * string,
* syntactic errors, and if found, returns 'invalid'. 'output' will not be
* filled in that case, but the input state of it isn't necessarily
* preserved. Turning on -DL debugging will give details as to the error.
* If 'panic_on_error' is 'true', the function panics instead of returning
* on error, with a message giving the details.
*
*/

Expand Down Expand Up @@ -1322,6 +1326,10 @@ S_parse_LC_ALL_string(pTHX_ const char * string,

DEBUG_L(PerlIO_printf(Perl_debug_log, "%s", msg));

if (panic_on_error) {
locale_panic_via_(msg, __FILE__, caller_line);
}

return invalid;
}

Expand Down Expand Up @@ -1414,6 +1422,7 @@ S_stdize_locale(pTHX_ const int category,
else {
switch (parse_LC_ALL_string(input_locale,
(const char **) & individ_locales,
false, /* Don't panic on error */
caller_line))
{
case invalid:
Expand Down Expand Up @@ -1893,6 +1902,7 @@ S_bool_setlocale_2008_i(pTHX_
if (index == LC_ALL_INDEX_) {
switch (parse_LC_ALL_string(new_locale,
(const char **) &new_locales,
false, /* Don't panic on error */
caller_line))
{
case invalid:
Expand Down Expand Up @@ -2557,6 +2567,7 @@ S_find_locale_from_environment(pTHX_ const unsigned int index)
* component of it. Split the result into its individual components */
switch (parse_LC_ALL_string(lc_all,
(const char **) &locale_names,
false, /* Don't panic on error */
__LINE__))
{
case invalid:
Expand Down
2 changes: 1 addition & 1 deletion proto.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 108d513

Please sign in to comment.