Skip to content

Commit

Permalink
locale.c: Remove use of nl_langinfo_l()
Browse files Browse the repository at this point in the history
I was wrong that it was feasible to determine at Configure time if this
was a thread safe implementation or not.  What could be determined was
if it was obviously not thread-safe.  lThe major advantage of using
this, is hence not valid, so remove the code that handled it specially.

perl.h comments are updated
  • Loading branch information
khwilliamson committed Jan 31, 2023
1 parent dec1204 commit 6025762
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 37 deletions.
31 changes: 2 additions & 29 deletions locale.c
Expand Up @@ -4694,37 +4694,10 @@ 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. */
# if defined(HAS_NL_LANGINFO) /* nl_langinfo() is available. */

/* The second version of my_langinfo() is if we have plain nl_langinfo()
*
* The only difference between the normal and emulation is the type of
/* The only difference between the normal and emulation is the type of
* locks. We have to always lock because this nl_langinfo() isn't thread
* safe */
# ifndef USE_THREAD_SAFE_LOCALE_EMULATION
Expand Down
18 changes: 10 additions & 8 deletions perl.h
Expand Up @@ -1365,20 +1365,22 @@ violations are fatal.

# include "perl_langinfo.h" /* Needed for _NL_LOCALE_NAME */

/* Allow use of glibc'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() */ \
/* Use querylocale if has it, or has the glibc internal \
* undocumented equivalent. */ \
|| ( defined(_NL_LOCALE_NAME) \
/* And asked for */ \
/* And is 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) \
/* nl_langinfo_l almost certainly will exist on systems that \
* have _NL_LOCALE_NAME, so there is nothing lost by \
* requiring it instead of also allowing plain nl_langinfo(). \
* And experience indicates that its glibc implementation is \
* thread-safe, eliminating code complications */ \
&& defined(HAS_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 */ \
* langinfo item, so we can't use it */ \
&& ! defined(SETLOCALE_ACCEPTS_ANY_LOCALE_NAME))
# define USE_QUERYLOCALE
# endif
Expand Down

0 comments on commit 6025762

Please sign in to comment.