Skip to content

Commit

Permalink
Properly handle broken setlocale(LC_ALL, NULL)
Browse files Browse the repository at this point in the history
Early AIX versions could return a truncated value in this case.
https://www.ibm.com/support/pages/apar/IV22097

Tests were skipped as a result by
59b4d29.

This commit adds an easy workaround for this bug, changes the AIX hints
page to enable it; the next commit will revert the test skipping.
  • Loading branch information
khwilliamson committed May 22, 2023
1 parent d8daac4 commit 6318081
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions locale.c
Expand Up @@ -1360,14 +1360,18 @@ S_parse_LC_ALL_string(pTHX_ const char * string,
* Any necessary mutex locking needs to be done at a higher level.
*
* On most platforms this layer is empty, expanding to just the layer
* below. To enable it, call Configure with:
* below. To enable it, call Configure with either or both:
* -Accflags=-DHAS_LF_IN_SETLOCALE_RETURN
* to indicate that extraneous \n characters can be returned
* by setlocale()
* -Accflags=-DHAS_BROKEN_SETLOCALE_QUERY_LC_ALL
* to indicate that setlocale(LC_ALL, NULL) cannot be relied
* on
*/

#if ! defined(USE_LOCALE) \
|| ! defined(HAS_LF_IN_SETLOCALE_RETURN)
|| ! ( defined(HAS_LF_IN_SETLOCALE_RETURN) \
|| defined(HAS_BROKEN_SETLOCALE_QUERY_LC_ALL))
# define stdized_setlocale(cat, locale) posix_setlocale(cat, locale)
# define stdize_locale(cat, locale) (locale)
#else
Expand Down Expand Up @@ -1404,6 +1408,22 @@ S_stdize_locale(pTHX_ const int category,
}

char * retval = (char *) input_locale;

# if defined(LC_ALL) && defined(HAS_BROKEN_SETLOCALE_QUERY_LC_ALL)

/* If setlocale(LC_ALL, NULL) is broken, compute what the system
* actually thinks it should be from its individual components */
if (category == LC_ALL) {
retval = (char *) calculate_LC_ALL_string(
NULL, /* query each individ locale */
EXTERNAL_FORMAT_FOR_SET,
false, /* Return a mortalized temporary */
caller_line);
}

# endif
# ifdef HAS_NL_IN_SETLOCALE_RETURN

char * first_bad = NULL;

# ifndef LC_ALL
Expand Down Expand Up @@ -1501,6 +1521,7 @@ S_stdize_locale(pTHX_ const int category,
# endif
# undef INPUT_LOCALE
# undef MARK_CHANGED
# endif /* HAS_NL_IN_SETLOCALE_RETURN */

return (const char *) retval;
}
Expand Down

0 comments on commit 6318081

Please sign in to comment.