Skip to content

Commit

Permalink
locale.c: Include the 'for' in the macro name
Browse files Browse the repository at this point in the history
This changes the previous commit so that instead of the interior of the
'for' header being replaced by a macro, the entire 'for (...)' is
replaced.

This could be squashed with the previous commit if desired.
  • Loading branch information
khwilliamson committed Sep 18, 2023
1 parent b71e033 commit 8d559df
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions locale.c
Expand Up @@ -448,20 +448,20 @@ S_wsetlocale(const int category, const wchar_t * wlocale)
#endif /* WIN32_USE_FAKE_OLD_MINGW_LOCALES */

/* 'for' loop headers to hide the necessary casts */
#define all_individual_category_indexes(i) \
locale_category_index i = (locale_category_index) 0; \
i < LC_ALL_INDEX_; \
i = (locale_category_index) ((int) i + 1)
#define for_all_individual_category_indexes(i) \
for (locale_category_index i = (locale_category_index) 0; \
i < LC_ALL_INDEX_; \
i = (locale_category_index) ((int) i + 1))

#define all_but_0th_individual_category_indexes(i) \
locale_category_index i = (locale_category_index) 1; \
i < LC_ALL_INDEX_; \
i = (locale_category_index) ((int) i + 1)
#define for_all_but_0th_individual_category_indexes(i) \
for (locale_category_index i = (locale_category_index) 1; \
i < LC_ALL_INDEX_; \
i = (locale_category_index) ((int) i + 1))

#define all_category_indexes(i) \
locale_category_index i = (locale_category_index) 0; \
i <= LC_ALL_INDEX_; \
i = (locale_category_index) ((int) i + 1)
#define for_all_category_indexes(i) \
for (locale_category_index i = (locale_category_index) 0; \
i <= LC_ALL_INDEX_; \
i = (locale_category_index) ((int) i + 1))

#ifdef USE_LOCALE
# if defined(USE_FAKE_LC_ALL_POSITIONAL_NOTATION) && defined(LC_ALL)
Expand Down Expand Up @@ -512,7 +512,7 @@ S_positional_name_value_xlation(const char * locale, bool direction)
WANT_TEMP_PV,
__LINE__);

for (all_individual_category_indexes(i)) {
for_all_individual_category_indexes(i) {
Safefree(individ_locales[i]);
}

Expand Down Expand Up @@ -1206,7 +1206,7 @@ S_parse_LC_ALL_string(pTHX_ const char * string,
* will be C for each ignored category and "" for the others. Then the
* caller can individually set each category, and get the right answer. */
if (single_component && ! isNAME_C_OR_POSIX(string)) {
for (all_individual_category_indexes(i)) {
for_all_individual_category_indexes(i) {
OVERRIDE_AND_SAVEPV(string, strlen(string), output[i], i, override);
}

Expand All @@ -1220,7 +1220,7 @@ S_parse_LC_ALL_string(pTHX_ const char * string,
return no_array;
}

for (all_individual_category_indexes(i)) {
for_all_individual_category_indexes(i) {
output[i] = savepv(string);
}

Expand Down Expand Up @@ -1355,7 +1355,7 @@ S_parse_LC_ALL_string(pTHX_ const char * string,
# endif

{ /* Here is the name=value notation */
for (all_individual_category_indexes(i)) {
for_all_individual_category_indexes(i) {
if (! seen[i]) {
error = incomplete;
goto failure;
Expand All @@ -1371,7 +1371,7 @@ S_parse_LC_ALL_string(pTHX_ const char * string,
}

/* Free the dangling ones */
for (all_but_0th_individual_category_indexes(i)) {
for_all_but_0th_individual_category_indexes(i) {
Safefree(output[i]);
output[i] = NULL;
}
Expand All @@ -1381,7 +1381,7 @@ S_parse_LC_ALL_string(pTHX_ const char * string,
failure:

/* Don't leave memory dangling that we allocated before the failure */
for (all_individual_category_indexes(i)) {
for_all_individual_category_indexes(i) {
if (seen[i]) {
Safefree(output[i]);
output[i] = NULL;
Expand Down Expand Up @@ -1521,7 +1521,7 @@ S_posix_setlocale_with_complications(pTHX_ const int cat,
WANT_TEMP_PV,
caller_line);

for (all_individual_category_indexes(i)) {
for_all_individual_category_indexes(i) {
Safefree(new_locales[i]);
}

Expand Down Expand Up @@ -2486,7 +2486,7 @@ S_bool_setlocale_2008_i(pTHX_
/* Loop, using the previous iteration's result as the basis for the
* next one. (The first time we effectively use the locale in
* force upon entry to this function.) */
for (all_individual_category_indexes(i)) {
for_all_individual_category_indexes(i) {
new_obj = newlocale(category_masks[i],
new_locales[i],
basis_obj);
Expand All @@ -2510,15 +2510,15 @@ S_bool_setlocale_2008_i(pTHX_
* failed */
freelocale(basis_obj);

for (all_individual_category_indexes(j)) {
for_all_individual_category_indexes(j) {
Safefree(new_locales[j]);
}

goto must_restore_state;
}

/* Success for all categories. */
for (all_individual_category_indexes(i)) {
for_all_individual_category_indexes(i) {
update_PL_curlocales_i(i, new_locales[i], caller_line);
Safefree(new_locales[i]);
}
Expand Down Expand Up @@ -2812,12 +2812,12 @@ S_calculate_LC_ALL_string(pTHX_ const char ** category_locales_list,
locales_list = my_category_locales_list;

if (format == EXTERNAL_FORMAT_FOR_QUERY) {
for (all_individual_category_indexes(i)) {
for_all_individual_category_indexes(i) {
locales_list[i] = query_nominal_locale_i(i);
}
}
else {
for (all_individual_category_indexes(i)) {
for_all_individual_category_indexes(i) {
locales_list[i] = querylocale_i(i);
}
}
Expand Down Expand Up @@ -2889,7 +2889,7 @@ S_calculate_LC_ALL_string(pTHX_ const char ** category_locales_list,

/* The total length then is just the sum of the above boiler-plate plus the
* total strlen()s of the locale name of each individual category. */
for (all_individual_category_indexes(i)) {
for_all_individual_category_indexes(i) {
const char * entry = ENTRY(i, locales_list, format);

total_len += strlen(entry);
Expand Down Expand Up @@ -2936,7 +2936,7 @@ S_calculate_LC_ALL_string(pTHX_ const char ** category_locales_list,
constructed[0] = '\0';

/* Loop through all the categories */
for (all_individual_category_indexes(j)) {
for_all_individual_category_indexes(j) {

/* Add a separator, except before the first one */
if (j != 0) {
Expand Down Expand Up @@ -3981,7 +3981,7 @@ S_new_LC_ALL(pTHX_ const char ** individ_locales, bool force)

# endif

for (all_individual_category_indexes(i)) {
for_all_individual_category_indexes(i) {
if (update_functions[i]) {
const char * this_locale = individ_locales[i];
update_functions[i](aTHX_ this_locale, force);
Expand Down Expand Up @@ -6841,7 +6841,7 @@ S_give_perl_locale_control(pTHX_

# else

for (all_individual_category_indexes(i)) {
for_all_individual_category_indexes(i) {
void_setlocale_i_with_caller(i, locales[i], __FILE__, caller_line);
}

Expand Down Expand Up @@ -6886,7 +6886,7 @@ S_output_check_environment_warning(pTHX_ const char * const language,
lc_all ? lc_all : "unset",
lc_all ? '"' : ')');

for (all_individual_category_indexes(i)) {
for_all_individual_category_indexes(i) {
const char * value = PerlEnv_getenv(category_names[i]);
PerlIO_printf(Perl_error_log,
"\t%s = %c%s%c,\n",
Expand Down Expand Up @@ -7042,7 +7042,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
# endif
# endif

for (all_individual_category_indexes(i)) {
for_all_individual_category_indexes(i) {
assert(category_name_lengths[i] == strlen(category_names[i]));
}

Expand Down Expand Up @@ -7305,7 +7305,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
bool setlocale_failure = FALSE; /* This trial hasn't failed so far */
bool dowarn = trial == 0 && locwarn;

for (all_individual_category_indexes(j)) {
for_all_individual_category_indexes(j) {
STDIZED_SETLOCALE_LOCK;
curlocales[j] = savepv(stdized_setlocale(categories[j], locale));
STDIZED_SETLOCALE_UNLOCK;
Expand Down Expand Up @@ -7334,7 +7334,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
PerlIO_printf(Perl_error_log,
"perl: warning: Setting locale failed for the categories:\n");

for (all_individual_category_indexes(j)) {
for_all_individual_category_indexes(j) {
if (! curlocales[j]) {
PerlIO_printf(Perl_error_log, "\t%s\n", category_names[j]);
}
Expand Down Expand Up @@ -7414,7 +7414,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
INTERNAL_FORMAT,
WANT_TEMP_PV,
__LINE__);
for (all_individual_category_indexes(j)) {
for_all_individual_category_indexes(j) {
Safefree(individ_locales[j]);
}
}
Expand Down Expand Up @@ -7448,7 +7448,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn)

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

for (all_individual_category_indexes(j)) {
for_all_individual_category_indexes(j) {
STDIZED_SETLOCALE_LOCK;
system_locales[j] = savepv(stdized_setlocale(categories[j],
NULL));
Expand All @@ -7467,7 +7467,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
__LINE__);
description = "what the system says";

for (all_individual_category_indexes(j)) {
for_all_individual_category_indexes(j) {
Safefree(system_locales[j]);
}
# endif
Expand All @@ -7493,7 +7493,7 @@ Perl_init_i18nl10n(pTHX_ int printwarn)

give_perl_locale_control((const char **) &curlocales, __LINE__);

for (all_individual_category_indexes(j)) {
for_all_individual_category_indexes(j) {
Safefree(curlocales[j]);
}

Expand Down Expand Up @@ -8865,15 +8865,15 @@ Perl_switch_to_global_locale(pTHX)
const char * cur_thread_locales[LC_ALL_INDEX_];

/* Save each category's current per-thread state */
for (all_individual_category_indexes(i)) {
for_all_individual_category_indexes(i) {
cur_thread_locales[i] = querylocale_i(i);
}

CHANGE_SYSTEM_LOCALE_TO_GLOBAL;

/* Set the global to what was our per-thread state */
POSIX_SETLOCALE_LOCK;
for (all_individual_category_indexes(i)) {
for_all_individual_category_indexes(i) {
posix_setlocale(categories[i], cur_thread_locales[i]);
}
POSIX_SETLOCALE_UNLOCK;
Expand Down Expand Up @@ -8978,15 +8978,15 @@ Perl_sync_locale(pTHX)
# else

const char * current_globals[LC_ALL_INDEX_];
for (all_individual_category_indexes(i)) {
for_all_individual_category_indexes(i) {
STDIZED_SETLOCALE_LOCK;
current_globals[i] = savepv(stdized_setlocale(categories[i], NULL));
STDIZED_SETLOCALE_UNLOCK;
}

give_perl_locale_control((const char **) &current_globals, __LINE__);

for (all_individual_category_indexes(i)) {
for_all_individual_category_indexes(i) {
Safefree(current_globals[i]);
}

Expand Down

0 comments on commit 8d559df

Please sign in to comment.