Skip to content

Commit

Permalink
S_setlocale_2008_i(): Use single newlocale() if available
Browse files Browse the repository at this point in the history
On some platforms the newlocale() libc function when setting LC_ALL can
handle an input locale that sets some categories to one thing; and
others to another; etc.  On such platforms, we don't have to loop
through all categories individually.

This commit changes to use that if the #define indicating its
availability is set.
  • Loading branch information
khwilliamson committed May 6, 2023
1 parent fa980da commit de78e8c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions locale.c
Expand Up @@ -1944,6 +1944,11 @@ S_bool_setlocale_2008_i(pTHX_
}

# endif
# ifdef NEWLOCALE_HANDLES_DISPARATE_LC_ALL

const bool need_loop = false;

# else

bool need_loop = false;
const char * new_locales[LC_ALL_INDEX_] = { NULL };
Expand Down Expand Up @@ -1978,6 +1983,7 @@ S_bool_setlocale_2008_i(pTHX_
}
}

# endif
# ifdef HAS_GLIBC_LC_MESSAGES_BUG

/* For this bug, if the LC_MESSAGES locale changes, we have to do an
Expand Down Expand Up @@ -2094,8 +2100,17 @@ S_bool_setlocale_2008_i(pTHX_
* you can set PERL_DESTRUCT_LEVEL=2 to cause it to be freed.
*/

# ifdef NEWLOCALE_HANDLES_DISPARATE_LC_ALL

/* Some platforms have a newlocale() that can handle disparate LC_ALL
* input, so on these a single call to newlocale() always works */
# else

/* If a single call to newlocale() will do */
if (! need_loop)

# endif

{
new_obj = newlocale(mask, new_locale, basis_obj);
if (! new_obj) {
Expand All @@ -2118,6 +2133,9 @@ S_bool_setlocale_2008_i(pTHX_

update_PL_curlocales_i(index, new_locale, caller_line);
}

# ifndef NEWLOCALE_HANDLES_DISPARATE_LC_ALL

else { /* Need multiple newlocale() calls */

/* Loop through the individual categories, setting the locale of
Expand Down Expand Up @@ -2176,6 +2194,9 @@ S_bool_setlocale_2008_i(pTHX_
freelocale(entry_obj);
}
}

# endif /* End of newlocale can't handle disparate LC_ALL input */

}

# undef DEBUG_NEW_OBJECT_CREATED
Expand Down

0 comments on commit de78e8c

Please sign in to comment.