Skip to content

Commit

Permalink
locale.c: Define S_update_PL_curlocales_i under more conditions
Browse files Browse the repository at this point in the history
This is in preparation for a future commit
  • Loading branch information
khwilliamson committed Jan 31, 2023
1 parent f1fa85b commit 1e9a211
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 66 deletions.
13 changes: 7 additions & 6 deletions embed.fnc
Expand Up @@ -4353,6 +4353,12 @@ S |void |new_numeric |NN const char *newnum \
# if defined(USE_PERL_SWITCH_LOCALE_CONTEXT) || defined(DEBUGGING)
S |const char *|get_LC_ALL_display
# endif /* defined(USE_PERL_SWITCH_LOCALE_CONTEXT) || defined(DEBUGGING) */
# if defined(USE_PL_CURLOCALES)
S |const char *|update_PL_curlocales_i \
|const unsigned int index \
|NN const char *new_locale \
|recalc_lc_all_t recalc_LC_ALL
# endif /* defined(USE_PL_CURLOCALES) */
# if defined(USE_POSIX_2008_LOCALE)
S |const char *|emulate_setlocale_i \
|const unsigned int index \
Expand All @@ -4371,12 +4377,7 @@ S |const char *|calculate_LC_ALL \
S |const char *|querylocale_l \
|const unsigned int index \
|const locale_t locale_obj
# else /* if !defined(USE_QUERYLOCALE) */
S |const char *|update_PL_curlocales_i \
|const unsigned int index \
|NN const char *new_locale \
|recalc_lc_all_t recalc_LC_ALL
# endif /* !defined(USE_QUERYLOCALE) */
# endif /* defined(USE_QUERYLOCALE) */
# elif defined(USE_LOCALE_THREADS) && !defined(USE_THREAD_SAFE_LOCALE) && \
!defined(USE_THREAD_SAFE_LOCALE_EMULATION) /* && \
!defined(USE_POSIX_2008_LOCALE) */
Expand Down
7 changes: 4 additions & 3 deletions embed.h
Expand Up @@ -1304,6 +1304,9 @@
# define get_LC_ALL_display() S_get_LC_ALL_display(aTHX)
# endif /* defined(USE_PERL_SWITCH_LOCALE_CONTEXT) || \
defined(DEBUGGING) */
# if defined(USE_PL_CURLOCALES)
# define update_PL_curlocales_i(a,b,c) S_update_PL_curlocales_i(aTHX_ a,b,c)
# endif /* defined(USE_PL_CURLOCALES) */
# if defined(USE_POSIX_2008_LOCALE)
# define emulate_setlocale_i(a,b,c,d) S_emulate_setlocale_i(aTHX_ a,b,c,d)
# define my_querylocale_i(a) S_my_querylocale_i(aTHX_ a)
Expand All @@ -1312,9 +1315,7 @@
# if defined(USE_QUERYLOCALE)
# define calculate_LC_ALL(a) S_calculate_LC_ALL(aTHX_ a)
# define querylocale_l(a,b) S_querylocale_l(aTHX_ a,b)
# else /* if !defined(USE_QUERYLOCALE) */
# define update_PL_curlocales_i(a,b,c) S_update_PL_curlocales_i(aTHX_ a,b,c)
# endif /* !defined(USE_QUERYLOCALE) */
# endif /* defined(USE_QUERYLOCALE) */
# elif defined(USE_LOCALE_THREADS) && !defined(USE_THREAD_SAFE_LOCALE) \
&& !defined(USE_THREAD_SAFE_LOCALE_EMULATION) /* && \
!defined(USE_POSIX_2008_LOCALE) */
Expand Down
109 changes: 59 additions & 50 deletions locale.c
Expand Up @@ -1067,56 +1067,6 @@ S_my_querylocale_i(pTHX_ const unsigned int index)
return retval;
}

# ifdef USE_PL_CURLOCALES

STATIC const char *
S_update_PL_curlocales_i(pTHX_
const unsigned int index,
const char * new_locale,
recalc_lc_all_t recalc_LC_ALL)
{
/* This is a helper function for emulate_setlocale_i(), mostly used to
* make that function easier to read. */

PERL_ARGS_ASSERT_UPDATE_PL_CURLOCALES_I;
assert(index <= NOMINAL_LC_ALL_INDEX);

if (index == LC_ALL_INDEX_) {
unsigned int i;

/* For LC_ALL, we change all individual categories to correspond */
/* PL_curlocales is a parallel array, so has same
* length as 'categories' */
for (i = 0; i < LC_ALL_INDEX_; i++) {
Safefree(PL_curlocales[i]);
PL_curlocales[i] = savepv(new_locale);
}

Safefree(PL_curlocales[LC_ALL_INDEX_]);
PL_curlocales[LC_ALL_INDEX_] = savepv(calculate_LC_ALL(PL_curlocales));
DEBUG_U(PerlIO_printf(Perl_debug_log, "%s\n", PL_curlocales[LC_ALL_INDEX_]));
return PL_curlocales[LC_ALL_INDEX_];
}

/* Update the single category's record */
Safefree(PL_curlocales[index]);
PL_curlocales[index] = savepv(new_locale);

/* And also LC_ALL if the input says to, including if this is the final
* iteration of a loop updating all sub-categories */
if ( recalc_LC_ALL == YES_RECALC_LC_ALL
|| ( recalc_LC_ALL == RECALCULATE_LC_ALL_ON_FINAL_INTERATION
&& index == NOMINAL_LC_ALL_INDEX - 1))
{
Safefree(PL_curlocales[LC_ALL_INDEX_]);
PL_curlocales[LC_ALL_INDEX_] = savepv(calculate_LC_ALL(PL_curlocales));
DEBUG_U(PerlIO_printf(Perl_debug_log, "%s\n", PL_curlocales[LC_ALL_INDEX_]));
}

return PL_curlocales[index];
}

# endif /* Need PL_curlocales[] */
# ifdef USE_QUERYLOCALE
# define isSINGLE_BIT_SET(mask) isPOWER_OF_2(mask)

Expand Down Expand Up @@ -1603,6 +1553,65 @@ S_emulate_setlocale_i(pTHX_
#endif /* End of the various implementations of the setlocale and
querylocale macros used in the remainder of this program */

#ifdef USE_PL_CURLOCALES

STATIC const char *
S_update_PL_curlocales_i(pTHX_
const unsigned int index,
const char * new_locale,
recalc_lc_all_t recalc_LC_ALL)
{
PERL_ARGS_ASSERT_UPDATE_PL_CURLOCALES_I;
assert(index <= NOMINAL_LC_ALL_INDEX);

/* Updates PL_curlocales[] */

# ifdef LC_ALL

if (index == LC_ALL_INDEX_) {
unsigned int i;

/* For LC_ALL, we change all individual categories to correspond */
/* PL_curlocales is a parallel array, so has same
* length as 'categories' */
for (i = 0; i < LC_ALL_INDEX_; i++) {
Safefree(PL_curlocales[i]);
PL_curlocales[i] = savepv(new_locale);
}

Safefree(PL_curlocales[LC_ALL_INDEX_]);
PL_curlocales[LC_ALL_INDEX_] = savepv(calculate_LC_ALL(PL_curlocales));
DEBUG_U(PerlIO_printf(Perl_debug_log, "%s\n",
PL_curlocales[LC_ALL_INDEX_]));
return PL_curlocales[LC_ALL_INDEX_];
}

# endif

/* Update the single category's record */
Safefree(PL_curlocales[index]);
PL_curlocales[index] = savepv(new_locale);

# ifdef LC_ALL

/* And also LC_ALL if the input says to, including if this is the final
* iteration of a loop updating all sub-categories */
if ( recalc_LC_ALL == YES_RECALC_LC_ALL
|| ( recalc_LC_ALL == RECALCULATE_LC_ALL_ON_FINAL_INTERATION
&& index == NOMINAL_LC_ALL_INDEX - 1))
{
Safefree(PL_curlocales[LC_ALL_INDEX_]);
PL_curlocales[LC_ALL_INDEX_] = savepv(calculate_LC_ALL(PL_curlocales));
DEBUG_U(PerlIO_printf(Perl_debug_log, "%s\n",
PL_curlocales[LC_ALL_INDEX_]));
}

# endif

return PL_curlocales[index];
}

#endif /* Need PL_curlocales[] */
#ifdef USE_LOCALE

/* So far, the locale strings returned by modern 2008-compliant systems have
Expand Down
15 changes: 8 additions & 7 deletions proto.h

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

0 comments on commit 1e9a211

Please sign in to comment.