Skip to content

Commit 2fc8f38

Browse files
committed
locale.c: Remove use of localeconv_l()
Use plain localeconv() always. When I wrote this code several years ago, I was under the impression that localeconv_l() was thread-safe. Alas, stress testing on various platforms indicate that it isn't, nor do the current man pages I found indicate it is. I don't now know how I came to that (mistaken) belief. The reason to use localeconv_l() was that no locking was used. But now that I know locking is required anyway, that advantage is gone, and it is just a separate code path that would need to be retained.
1 parent 9cac334 commit 2fc8f38

File tree

1 file changed

+13
-53
lines changed

1 file changed

+13
-53
lines changed

locale.c

Lines changed: 13 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,6 @@ static const char C_thousands_sep[] = "";
215215
#if defined(HAS_NL_LANGINFO_L) || defined(HAS_NL_LANGINFO)
216216
# define HAS_SOME_LANGINFO
217217
#endif
218-
#if defined(HAS_LOCALECONV) || defined(HAS_LOCALECONV_L)
219-
# define HAS_SOME_LOCALECONV
220-
#endif
221218

222219
#define my_langinfo_c(item, category, locale, retbufp, retbuf_sizep, utf8ness) \
223220
my_langinfo_i(item, category##_INDEX_, locale, retbufp, \
@@ -1822,7 +1819,7 @@ S_setlocale_failure_panic_i(pTHX_
18221819

18231820
/* Any of these will allow us to find the RADIX */
18241821
# if defined(USE_LOCALE_NUMERIC) && ( defined(HAS_SOME_LANGINFO) \
1825-
|| defined(HAS_SOME_LOCALECONV) \
1822+
|| defined(HAS_LOCALECONV) \
18261823
|| defined(HAS_SNPRINTF))
18271824
# define CAN_CALCULATE_RADIX
18281825
# endif
@@ -3196,7 +3193,7 @@ HV *
31963193
Perl_localeconv(pTHX)
31973194
{
31983195

3199-
#if ! defined(HAS_SOME_LOCALECONV) \
3196+
#if ! defined(HAS_LOCALECONV) \
32003197
|| (! defined(USE_LOCALE_MONETARY) && ! defined(USE_LOCALE_NUMERIC))
32013198

32023199
return newHV();
@@ -3209,7 +3206,7 @@ Perl_localeconv(pTHX)
32093206

32103207
}
32113208

3212-
#if defined(HAS_SOME_LOCALECONV) \
3209+
#if defined(HAS_LOCALECONV) \
32133210
&& (defined(USE_LOCALE_MONETARY) || defined(USE_LOCALE_NUMERIC))
32143211

32153212
HV *
@@ -3292,50 +3289,13 @@ S_my_localeconv(pTHX_ const int item)
32923289
PERL_ARGS_ASSERT_MY_LOCALECONV;
32933290
/*--------------------------------------------------------------------------*/
32943291
/* Here, we are done with the common beginning of all the implementations of
3295-
* my_localeconv(). Below are the various terminations of the function (except
3292+
* my_localeconv(). Below are the two terminations of the function (except
32963293
* the closing '}'. They are separated out because the preprocessor directives
32973294
* were making the simple logic hard to follow. Each implementation ends with
32983295
* the same few lines. khw decided to keep those separate because he thought
32993296
* it was clearer to the reader.
3300-
*
3301-
* The first distinct termination (of the above common code) are the
3302-
* implementations when we have locale_conv_l() and can use it. These are the
3303-
* simplest cases, without any locking needed. */
3304-
# if defined(USE_POSIX_2008_LOCALE) && defined(HAS_LOCALECONV_L)
3305-
3306-
/* And there are two sub-cases: First (by far the most common) is where we
3307-
* are compiled to pay attention to LC_NUMERIC */
3308-
# ifdef USE_LOCALE_NUMERIC
3309-
3310-
const locale_t cur = use_curlocale_scratch();
3311-
locale_t with_numeric = duplocale(cur);
3312-
3313-
/* Just create a new locale object with what we've got, but using the
3314-
* underlying LC_NUMERIC locale */
3315-
with_numeric = newlocale(LC_NUMERIC_MASK, PL_numeric_name, with_numeric);
3316-
3317-
retval = copy_localeconv(aTHX_ localeconv_l(with_numeric),
3318-
item,
3319-
numeric_locale_is_utf8,
3320-
monetary_locale_is_utf8);
3321-
freelocale(with_numeric);
3322-
3323-
return retval;
3324-
3325-
/*--------------------------------------------------------------------------*/
3326-
# else /* Below not paying attention to LC_NUMERIC */
3327-
3328-
const locale_t cur = use_curlocale_scratch();
3329-
3330-
retval = copy_localeconv(aTHX_ localeconv_l(cur),
3331-
item,
3332-
numeric_locale_is_utf8,
3333-
monetary_locale_is_utf8);
3334-
return retval;
3335-
3336-
# endif /* Above, using lconv_l(); below plain lconv() */
3337-
/*--------------------------------------------------------------------------*/
3338-
# elif ! defined(TS_W32_BROKEN_LOCALECONV) /* Next is regular lconv() */
3297+
*--------------------------------------------------------------------------*/
3298+
# if ! defined(TS_W32_BROKEN_LOCALECONV) /* Regular lconv() */
33393299

33403300
/* There are so many locks because localeconv() deals with two
33413301
* categories, and returns in a single global static buffer. Some
@@ -3845,7 +3805,7 @@ Perl_langinfo8(const nl_item item, utf8ness_t * utf8ness)
38453805
case CRNCYSTR:
38463806

38473807
#if defined(USE_LOCALE_MONETARY) \
3848-
&& (defined(HAS_SOME_LANGINFO) || defined(HAS_SOME_LOCALECONV))
3808+
&& (defined(HAS_SOME_LANGINFO) || defined(HAS_LOCALECONV))
38493809

38503810
cat_index = LC_MONETARY_INDEX_;
38513811
break;
@@ -3866,7 +3826,7 @@ Perl_langinfo8(const nl_item item, utf8ness_t * utf8ness)
38663826
case THOUSEP:
38673827

38683828
#if defined(USE_LOCALE_NUMERIC) \
3869-
&& (defined(HAS_SOME_LANGINFO) || defined(HAS_SOME_LOCALECONV))
3829+
&& (defined(HAS_SOME_LANGINFO) || defined(HAS_LOCALECONV))
38703830

38713831
cat_index = LC_NUMERIC_INDEX_;
38723832
break;
@@ -4116,7 +4076,7 @@ S_my_langinfo_i(pTHX_
41164076
case RADIXCHAR:
41174077

41184078
# if defined(HAS_SNPRINTF) \
4119-
&& (! defined(HAS_SOME_LOCALECONV) || defined(TS_W32_BROKEN_LOCALECONV))
4079+
&& (! defined(HAS_LOCALECONV) || defined(TS_W32_BROKEN_LOCALECONV))
41204080

41214081
{
41224082
/* snprintf() can be used to find the radix character by outputting
@@ -4180,8 +4140,8 @@ S_my_langinfo_i(pTHX_
41804140
Safefree(floatbuf);
41814141
}
41824142

4183-
# ifdef HAS_SOME_LOCALECONV /* snprintf() failed; drop down to use
4184-
localeconv() */
4143+
# ifdef HAS_LOCALECONV /* snprintf() failed; drop down to use
4144+
localeconv() */
41854145

41864146
/* FALLTHROUGH */
41874147

@@ -4192,7 +4152,7 @@ S_my_langinfo_i(pTHX_
41924152

41934153
# endif
41944154
# endif
4195-
# ifdef HAS_SOME_LOCALECONV
4155+
# ifdef HAS_LOCALECONV
41964156

41974157
/* These items are available from localeconv(). (To avoid using
41984158
* TS_W32_BROKEN_LOCALECONV, one could use GetNumberFormat and
@@ -4436,7 +4396,7 @@ S_my_langinfo_i(pTHX_
44364396
utf8ness_t is_utf8 = UTF8NESS_UNKNOWN;
44374397
const char * scratch_buf = NULL;
44384398

4439-
# if defined(USE_LOCALE_MONETARY) && defined(HAS_SOME_LOCALECONV)
4399+
# if defined(USE_LOCALE_MONETARY) && defined(HAS_LOCALECONV)
44404400

44414401
/* Can't use this method unless localeconv() is available, as that's
44424402
* the way we find out the currency symbol. */

0 commit comments

Comments
 (0)