diff --git a/locale.c b/locale.c index 31af3a600d18..2b81fd832c7c 100644 --- a/locale.c +++ b/locale.c @@ -498,13 +498,19 @@ S_category_name(const int category) # define querylocale_c(cat) querylocale_i(cat##_INDEX_) # define querylocale_r(cat) querylocale_i(get_category_index(cat,NULL)) -# ifndef HAS_QUERYLOCALE +# ifndef USE_QUERYLOCALE # define USE_PL_CURLOCALES +# else +# if ! defined(HAS_QUERYLOCALE) && defined(_NL_LOCALE_NAME) +# define querylocale_l(index, locale_obj) \ + nl_langinfo_l(_NL_LOCALE_NAME(categories[index]), locale_obj) +# else +# define querylocale_l(index, locale_obj) \ + querylocale(category_masks[index], locale_obj) +# endif # endif # if ! defined(__GLIBC__) || ! defined(USE_LOCALE_MESSAGES) - # define FIX_GLIBC_LC_MESSAGES_BUG(i) - # else /* Invalidate glibc cache of loaded translations, see [perl #134264] */ # include @@ -605,9 +611,9 @@ S_my_querylocale_i(pTHX_ const unsigned int index) return porcelain_setlocale(category, NULL); } -# ifdef HAS_QUERYLOCALE +# ifdef USE_QUERYLOCALE - return (char *) querylocale(category_masks[index], cur_obj); + return (char *) querylocale_l(index, cur_obj); # else @@ -734,7 +740,7 @@ S_emulate_setlocale_i(pTHX_ const unsigned int index, const char * locale) return my_querylocale_i(index); } -# ifndef HAS_QUERYLOCALE +# ifndef USE_QUERYLOCALE if (strEQ(locale, "")) { @@ -1065,10 +1071,10 @@ S_emulate_setlocale_i(pTHX_ const unsigned int index, const char * locale) * locale that got switched to is, as it came from the environment. So * have to find it */ -# ifdef HAS_QUERYLOCALE +# ifdef USE_QUERYLOCALE if (strEQ(locale, "")) { - locale = querylocale(mask, new_obj); + locale = querylocale_l(index, new_obj); } # else diff --git a/perl.h b/perl.h index a606f39fa1dc..41d388ba1dba 100644 --- a/perl.h +++ b/perl.h @@ -1099,6 +1099,25 @@ Example usage: # endif # endif +/* Allow use of glib's undocumented querylocale() equivalent if asked for, and + * appropriate */ +# ifdef USE_POSIX_2008_LOCALE +# if defined(HAS_QUERYLOCALE) \ + /* Has this internal undocumented item for nl_langinfo() */ \ + || ( defined(_NL_LOCALE_NAME) \ + /* And asked for */ \ + && defined(USE_NL_LOCALE_NAME) \ + /* We need the below because we will be calling it within a \ + * macro, can't have it get messed up by another thread. */ \ + && defined(HAS_THREAD_SAFE_NL_LANGINFO_L) \ + /* On systems that accept any locale name, the real \ + * underlying locale is often returned by this internal \ + * item, so we can't use it */ \ + && ! defined(SETLOCALE_ACCEPTS_ANY_LOCALE_NAME)) +# define USE_QUERYLOCALE +# endif +# endif + /* Microsoft documentation reads in the change log for VS 2015: * "The localeconv function declared in locale.h now works correctly when * per-thread locale is enabled. In previous versions of the library, this