In perl.git, the branch blead has been updated <https://perl5.git.perl.org/perl.git/commitdiff/ab340fffd3aab332a1b31d7cf502274d67d1d4a5?hp=301bcfdaa73a979264d6ee1845c40043ddd464eb>
- Log ----------------------------------------------------------------- commit ab340fffd3aab332a1b31d7cf502274d67d1d4a5 Author: Karl Williamson <k...@cpan.org> Date: Thu Oct 26 08:29:50 2017 -0600 Use nl_langinfo_l() if available This function allows us to avoid using a mutex and changing the locale. ----------------------------------------------------------------------- Summary of changes: locale.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/locale.c b/locale.c index 86a5a257f2..485dfe74ae 100644 --- a/locale.c +++ b/locale.c @@ -1197,9 +1197,10 @@ Perl_langinfo(const int item) bool toggle = TRUE; dTHX; -#if defined(HAS_NL_LANGINFO) +#if defined(HAS_NL_LANGINFO) /* nl_langinfo() is available. */ +#if ! defined(HAS_POSIX_2008_LOCALE) - /* nl_langinfo() is available. Call it, switching to underlying LC_NUMERIC + /* Here, use plain nl_langinfo(), switching to the underlying LC_NUMERIC * for those items dependent on it. This must be copied to a buffer before * switching back, as some systems destroy the buffer when setlocale() is * called */ @@ -1225,6 +1226,32 @@ Perl_langinfo(const int item) return PL_langinfo_buf; +# else /* Use nl_langinfo_l(), avoiding both a mutex and changing the locale */ + + bool do_free = FALSE; + locale_t cur = uselocale((locale_t) 0); + + if (cur == LC_GLOBAL_LOCALE) { + cur = duplocale(LC_GLOBAL_LOCALE); + do_free = TRUE; + } + + if ( toggle + && (item == PERL_RADIXCHAR || item == PERL_THOUSEP)) + { + cur = newlocale(LC_NUMERIC_MASK, PL_numeric_name, cur); + do_free = TRUE; + } + + save_to_buffer(nl_langinfo_l(item, cur), + &PL_langinfo_buf, &PL_langinfo_bufsize, 0); + if (do_free) { + freelocale(cur); + } + + return PL_langinfo_buf; + +# endif #else /* Below, emulate nl_langinfo as best we can */ # ifdef HAS_LOCALECONV -- Perl5 Master Repository