summaryrefslogtreecommitdiff
path: root/locale.c
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2023-03-04 19:19:14 -0700
committerKarl Williamson <khw@cpan.org>2023-03-13 08:14:56 -0600
commitcb9df13091578d029ab318ba946310831d2e1912 (patch)
treebdfc557f644b788de70daf1a1eb924585e675fd6 /locale.c
parent2740baa993c22d700ed17566bbfddb5ac8173168 (diff)
downloadperl-cb9df13091578d029ab318ba946310831d2e1912.tar.gz
locale.c: Remove one use of nl_langinfo_l()
The limited POSIX guarantees of thread safety for nl_langinfo_l() aren't enough for our uses, and I was naive to think that a simple Configure probe could rule out all possible thread-safety issues that might exist in a libc call. I don't remember what the platforms were that falsely tested ok for the probe, but if it were necessary to find out, revert this patch, and start a smoke-me test. What that Configure probe did was find one particular point of non-safety. And it turns out various platforms pass that, but don't have a thread-safe nl_langinfo_l() generally. There are two calls to nl_langinfo_l() in the code. This commit removes one, where the major advantage of using nl_langinfo_l() over plain nl_langinfo() was efficiency. There still had to be an alternate implementation available that used plain nl_langinfo(). Since we can't guarantee that the _l implementation doesn't have bugs, simply remove it, and the existing alternative gets automatically used. The remaining use of nl_langinfo_l() is only when using glibc, and is disabled by default, requiring an explicit Configure parameter to enable. I have never seen a case where the glibc implementation failed to be thread-safe. This use may be enabled by default at some point, but not until early in a development cycle.
Diffstat (limited to 'locale.c')
-rw-r--r--locale.c33
1 files changed, 3 insertions, 30 deletions
diff --git a/locale.c b/locale.c
index 92f461b011..427ca261c1 100644
--- a/locale.c
+++ b/locale.c
@@ -767,7 +767,8 @@ S_less_dicey_bool_setlocale_r(pTHX_ const int cat, const char * locale)
* all instances of that have been removed */
# define QUERYLOCALE_ASSERT(index) \
__ASSERT_(isSINGLE_BIT_SET(category_masks[index]))
-# if ! defined(HAS_QUERYLOCALE) && defined(_NL_LOCALE_NAME)
+# if ! defined(HAS_QUERYLOCALE) && ( defined(_NL_LOCALE_NAME) \
+ && defined(HAS_NL_LANGINFO_L))
# define querylocale_l(index, locale_obj) \
(QUERYLOCALE_ASSERT(index) \
mortalized_pv_copy(nl_langinfo_l( \
@@ -4185,36 +4186,8 @@ S_my_langinfo_i(pTHX_
* implementation doesn't currently worry about it. But it is a problem on
* Windows boxes, which don't have nl_langinfo(). */
-# if defined(HAS_THREAD_SAFE_NL_LANGINFO_L) && defined(USE_POSIX_2008_LOCALE)
-
- /* Simplest is if we can use nl_langinfo_l()
- *
- * With it, we can change LC_CTYPE in the same call as the other category */
-# ifdef USE_LOCALE_CTYPE
-# define CTYPE_SAFETY_MASK LC_CTYPE_MASK
-# else
-# define CTYPE_SAFETY_MASK 0
-# endif
-
- locale_t cur = newlocale((category_masks[cat_index] | CTYPE_SAFETY_MASK),
- locale, (locale_t) 0);
-
- retval = save_to_buffer(nl_langinfo_l(item, cur), retbufp, retbuf_sizep);
-
- if (utf8ness) {
- *utf8ness = get_locale_string_utf8ness_i(retval,
- LOCALE_UTF8NESS_UNKNOWN,
- locale, cat_index);
- }
-
- freelocale(cur);
-
- return retval;
/*--------------------------------------------------------------------------*/
-# elif defined(HAS_NL_LANGINFO) /* nl_langinfo() is available. */
-
- /* The second version of my_langinfo() is if we have plain nl_langinfo() */
-
+# if defined(HAS_NL_LANGINFO) /* nl_langinfo() is available. */
# ifdef USE_LOCALE_CTYPE
/* Ths function sorts out if things actually have to be switched or not,