Skip to content

Commit

Permalink
Regularize HAS_POSIX_2008_LOCALE, USE_POSIX_2008_LOCALE
Browse files Browse the repository at this point in the history
A platform shouldn't be required to use the Posix 2008 locale handling
functions if they are present.  Perhaps they are buggy.  So, a separate
define for using them was introduced, USE_POSIX_2008_LOCALE.  But until
this commit there were cases that were looking at the underlying
availability of the functions, not if the Configuration called for their
use.
  • Loading branch information
khwilliamson committed May 9, 2021
1 parent 7e68e55 commit ff0ac8f
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 25 deletions.
6 changes: 3 additions & 3 deletions ext/POSIX/POSIX.xs
Expand Up @@ -2138,7 +2138,7 @@ localeconv()
#else
struct lconv *lcbuf;
# if defined(USE_ITHREADS) \
&& defined(HAS_POSIX_2008_LOCALE) \
&& defined(USE_POSIX_2008_LOCALE) \
&& defined(HAS_LOCALECONV_L) /* Prefer this thread-safe version */
bool do_free = FALSE;
locale_t cur = NULL;
Expand Down Expand Up @@ -2166,7 +2166,7 @@ localeconv()
RETVAL = newHV();
sv_2mortal((SV*)RETVAL);
# if defined(USE_ITHREADS) \
&& defined(HAS_POSIX_2008_LOCALE) \
&& defined(USE_POSIX_2008_LOCALE) \
&& defined(HAS_LOCALECONV_L)

cur = uselocale((locale_t) 0);
Expand Down Expand Up @@ -2247,7 +2247,7 @@ localeconv()
}
}
# if defined(USE_ITHREADS) \
&& defined(HAS_POSIX_2008_LOCALE) \
&& defined(USE_POSIX_2008_LOCALE) \
&& defined(HAS_LOCALECONV_L)
if (do_free) {
freelocale(cur);
Expand Down
2 changes: 1 addition & 1 deletion ext/POSIX/lib/POSIX.pm
Expand Up @@ -4,7 +4,7 @@ use warnings;

our ($AUTOLOAD, %SIGRT);

our $VERSION = '1.97';
our $VERSION = '1.98';

require XSLoader;

Expand Down
2 changes: 1 addition & 1 deletion intrpvar.h
Expand Up @@ -805,7 +805,7 @@ PERLVARI(I, numeric_standard, int, TRUE)
PERLVAR(I, numeric_name, char *) /* Name of current numeric locale */
PERLVAR(I, numeric_radix_sv, SV *) /* The radix separator if not '.' */

# ifdef HAS_POSIX_2008_LOCALE
# ifdef USE_POSIX_2008_LOCALE

PERLVARI(I, underlying_numeric_obj, locale_t, NULL)

Expand Down
9 changes: 3 additions & 6 deletions locale.c
Expand Up @@ -1166,7 +1166,7 @@ S_new_numeric(pTHX_ const char *newnum)

PL_numeric_underlying_is_standard = PL_numeric_standard;

# ifdef HAS_POSIX_2008_LOCALE
# ifdef USE_POSIX_2008_LOCALE

PL_underlying_numeric_obj = newlocale(LC_NUMERIC_MASK,
PL_numeric_name,
Expand Down Expand Up @@ -2290,7 +2290,7 @@ S_my_nl_langinfo(const int item, bool toggle)

#if defined(HAS_NL_LANGINFO) /* nl_langinfo() is available. */
# if ! defined(HAS_THREAD_SAFE_NL_LANGINFO_L) \
|| ! defined(HAS_POSIX_2008_LOCALE)
|| ! defined(USE_POSIX_2008_LOCALE)

/* 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
Expand Down Expand Up @@ -5359,21 +5359,18 @@ Perl_thread_locale_term()
{
/* Called from a thread as it gets ready to terminate */

#ifdef USE_THREAD_SAFE_LOCALE
#ifdef USE_POSIX_2008_LOCALE

/* C starts the new thread in the global C locale. If we are thread-safe,
* we want to not be in the global locale */

# ifndef WIN32

{ /* Free up */
locale_t cur_obj = uselocale(LC_GLOBAL_LOCALE);
if (cur_obj != LC_GLOBAL_LOCALE && cur_obj != PL_C_locale_obj) {
freelocale(cur_obj);
}
}

# endif
#endif

}
Expand Down
10 changes: 0 additions & 10 deletions makedef.pl
Expand Up @@ -415,16 +415,6 @@ sub readvar {
++$skip{$_} foreach qw(
PL_C_locale_obj
PL_curlocales
);
}

unless ( $define{'HAS_NEWLOCALE'}
&& $define{'HAS_FREELOCALE'}
&& $define{'HAS_USELOCALE'}
&& ! $define{'NO_POSIX_2008_LOCALE'})
{
++$skip{$_} foreach qw(
PL_C_locale_obj
PL_underlying_numeric_obj
);
}
Expand Down
2 changes: 1 addition & 1 deletion perl.c
Expand Up @@ -1117,7 +1117,7 @@ perl_destruct(pTHXx)
PL_curlocales[i] = NULL;
}
#endif
#ifdef HAS_POSIX_2008_LOCALE
#ifdef USE_POSIX_2008_LOCALE
{
/* This also makes sure we aren't using a locale object that gets freed
* below */
Expand Down
4 changes: 2 additions & 2 deletions perl.h
Expand Up @@ -6711,14 +6711,14 @@ the plain locale pragma without a parameter (S<C<use locale>>) is in effect.
* separate mutexes for some of them, the only changes needed are here.
* Define just the necessary macros. The compiler should then croak if the
* #ifdef's in the code are incorrect */
# if defined(HAS_LOCALECONV) && ( ! defined(HAS_POSIX_2008_LOCALE) \
# if defined(HAS_LOCALECONV) && ( ! defined(USE_POSIX_2008_LOCALE) \
|| ! defined(HAS_LOCALECONV_L) \
|| defined(TS_W32_BROKEN_LOCALECONV))
# define LOCALECONV_LOCK LOCALE_LOCK_
# define LOCALECONV_UNLOCK LOCALE_UNLOCK_
# endif
# if defined(HAS_NL_LANGINFO) && ( ! defined(HAS_THREAD_SAFE_NL_LANGINFO_L) \
|| ! defined(HAS_POSIX_2008_LOCALE))
|| ! defined(USE_POSIX_2008_LOCALE))
# define NL_LANGINFO_LOCK LOCALE_LOCK_
# define NL_LANGINFO_UNLOCK LOCALE_UNLOCK_
# endif
Expand Down
2 changes: 1 addition & 1 deletion sv.c
Expand Up @@ -15663,7 +15663,7 @@ perl_clone_using(PerlInterpreter *proto_perl, UV flags,
PL_numeric_name = SAVEPV(proto_perl->Inumeric_name);
PL_numeric_radix_sv = sv_dup_inc(proto_perl->Inumeric_radix_sv, param);

# if defined(HAS_POSIX_2008_LOCALE)
# if defined(USE_POSIX_2008_LOCALE)
PL_underlying_numeric_obj = NULL;
# endif
#endif /* !USE_LOCALE_NUMERIC */
Expand Down

0 comments on commit ff0ac8f

Please sign in to comment.