Skip to content

Commit

Permalink
XXX why: locale.c: revise new_LC_ALL
Browse files Browse the repository at this point in the history
This is because we don't want to use querylocale which is expecting
things to already be set up; instead pass what should happen to finish
the setup.
  • Loading branch information
khwilliamson committed May 22, 2023
1 parent 3488beb commit 7b0fbfd
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 15 deletions.
7 changes: 4 additions & 3 deletions embed.fnc
Expand Up @@ -4342,9 +4342,6 @@ Ri |const char *|mortalized_pv_copy \
|NULLOK const char * const pv
S |const char *|native_querylocale_i \
|const unsigned int cat_index
S |void |new_LC_ALL |NULLOK const char *unused \
|bool force
void
S |void |output_check_environment_warning \
|NULLOK const char * const language \
|NULLOK const char * const lc_all \
Expand Down Expand Up @@ -4397,6 +4394,8 @@ S |const char *|my_langinfo_i \
S |void |give_perl_locale_control \
|NN const char *lc_all_string \
|const line_t caller_line
S |void |new_LC_ALL |NN const char *lc_all \
|bool force
S |parse_LC_ALL_string_return|parse_LC_ALL_string \
|NN const char *string \
|NN const char **output \
Expand All @@ -4408,6 +4407,8 @@ S |parse_LC_ALL_string_return|parse_LC_ALL_string \
S |void |give_perl_locale_control \
|NN const char **curlocales \
|const line_t caller_line
S |void |new_LC_ALL |NN const char **individ_locales \
|bool force
# endif
# if defined(USE_LOCALE_COLLATE)
S |void |new_collate |NN const char *newcoll \
Expand Down
3 changes: 2 additions & 1 deletion embed.h
Expand Up @@ -1273,7 +1273,6 @@
# define get_category_index_helper(a,b,c) S_get_category_index_helper(aTHX_ a,b,c)
# define mortalized_pv_copy(a) S_mortalized_pv_copy(aTHX_ a)
# define native_querylocale_i(a) S_native_querylocale_i(aTHX_ a)
# define new_LC_ALL(a,b) S_new_LC_ALL(aTHX_ a,b)
# define output_check_environment_warning(a,b,c) S_output_check_environment_warning(aTHX_ a,b,c)
# define save_to_buffer S_save_to_buffer
# define setlocale_failure_panic_via_i(a,b,c,d,e,f,g) S_setlocale_failure_panic_via_i(aTHX_ a,b,c,d,e,f,g)
Expand All @@ -1287,9 +1286,11 @@
# endif
# if defined(LC_ALL)
# define give_perl_locale_control(a,b) S_give_perl_locale_control(aTHX_ a,b)
# define new_LC_ALL(a,b) S_new_LC_ALL(aTHX_ a,b)
# define parse_LC_ALL_string(a,b,c,d,e,f) S_parse_LC_ALL_string(aTHX_ a,b,c,d,e,f)
# else
# define give_perl_locale_control(a,b) S_give_perl_locale_control(aTHX_ a,b)
# define new_LC_ALL(a,b) S_new_LC_ALL(aTHX_ a,b)
# endif
# if defined(USE_LOCALE_COLLATE)
# define new_collate(a,b) S_new_collate(aTHX_ a,b)
Expand Down
73 changes: 67 additions & 6 deletions locale.c
Expand Up @@ -2457,7 +2457,7 @@ S_bool_setlocale_2008_i(pTHX_
freelocale(entry_obj);
}

update_PL_curlocales_i(index, "C", caller_line);
update_PL_curlocales_i(index, new_locale, caller_line);
}
else { /* Here is the general case, not to LC_ALL => C */

Expand Down Expand Up @@ -4013,21 +4013,61 @@ Perl__warn_problematic_locale()
}

STATIC void
S_new_LC_ALL(pTHX_ const char *unused, bool force)

# ifdef LC_ALL

S_new_LC_ALL(pTHX_ const char *lc_all, bool force)

# else

S_new_LC_ALL(pTHX_ const char ** individ_locales, bool force)

# endif

{
PERL_ARGS_ASSERT_NEW_LC_ALL;
PERL_UNUSED_ARG(unused);

/* new_LC_ALL() updates all the things we care about. Note that this is
* called just after a change, so uses the actual underlying locale just
* set, and not the nominal one (should they differ, as they may in
* LC_NUMERIC). */

# ifdef LC_ALL

const char * individ_locales[LC_ALL_INDEX_] = { NULL };

switch (parse_LC_ALL_string(lc_all,
(const char **) &individ_locales,
override_if_ignored, /* Override any ignored
categories */
true, /* Always fill array */
true, /* Panic if fails, as to get here it
earlier had to have succeeded */
__LINE__))
{
case invalid:
case no_array:
case only_element_0:
locale_panic_("Unexpected return from parse_LC_ALL_string");

case full_array:
break;
}

# endif

for (unsigned int i = 0; i < LC_ALL_INDEX_; i++) {
if (update_functions[i]) {
const char * this_locale = querylocale_i(i);
const char * this_locale = individ_locales[i];
update_functions[i](aTHX_ this_locale, force);
}

# ifdef LC_ALL

Safefree(individ_locales[i]);

# endif

}
}

Expand Down Expand Up @@ -6687,7 +6727,16 @@ S_give_perl_locale_control(pTHX_
# endif

/* Finally, update our remaining records. 'true' => force recalculation */
new_LC_ALL(NULL, true);

# if defined(LC_ALL)

new_LC_ALL(lc_all_string, true);

# else

new_LC_ALL(locales, true);

# endif
}

STATIC void
Expand Down Expand Up @@ -7168,8 +7217,20 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
}

# endif
# ifdef LC_ALL

new_LC_ALL("C", true /* Don't shortcut */);

# elif defined(USE_PL_CURLOCALES)

new_LC_ALL(NULL, true /* Don't shortcut */);
new_LC_ALL(PL_curlocales, true /* Don't shortcut */);

# else

const char C_locales[LC_ALL_INDEX_] = { "C" };
new_LC_ALL(C_locales, true /* Don't shortcut */);

# endif

/*===========================================================================*/

Expand Down
16 changes: 11 additions & 5 deletions proto.h

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

0 comments on commit 7b0fbfd

Please sign in to comment.