In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/7aaa36b196e5a478a3d1bd32506797db7cebf0b2?hp=106ab961dc7ce210c7a4d36b055daffe9c0f76ce>

- Log -----------------------------------------------------------------
commit 7aaa36b196e5a478a3d1bd32506797db7cebf0b2
Author: Karl Williamson <k...@cpan.org>
Date:   Sat Jul 15 18:18:47 2017 -0600

    locale.c: Use strerror_l if platform has it
    
    strerror_l makes the my_strerror function trivial, as it doesn't have to
    worry about critical sections, etc.  Even on unthreaded perls, it avoids
    having to change the current locale, and then change it back.

M       locale.c

commit 52770946b48e2fbf46e592f4c7273c83e949d89e
Author: Karl Williamson <k...@cpan.org>
Date:   Mon Jul 24 12:34:29 2017 -0600

    locale.c: Refactor some #if clauses
    
    This moves all the handling of the case where there are no locale
    messages, instead of splitting it up across long stretches of
    conditionally compiled code.  This code is essentially trivial, and seen
    to be so when it isn't split up; this prepares for the next commit.
    
    The final return of the function is still split off so that all branches
    go through it, and the debugging code adjacent to it.

M       locale.c

commit 6affbbf0c5da73de79daa8090d9e831997d2828a
Author: Karl Williamson <k...@cpan.org>
Date:   Sun Jul 23 22:28:30 2017 -0600

    locale.c: Move some DEBUGGING code
    
    This is moved so it gets executed for all branches.

M       locale.c

commit 5acc3fa5267fc7ad812f1bcfa7638acb4fd45c13
Author: Karl Williamson <k...@cpan.org>
Date:   Tue Jul 25 12:46:00 2017 -0600

    Initialize locale object even in unthreaded perls
    
    This commit will now initialize the thread-safe C locale object if the
    POSIX 2008 functions are available, regardless of whether the perl is
    threaded or not.  This will allow for a future commit that uses
    them, and which is a win on unthreaded builds.

M       makedef.pl
M       perl.c
M       perl.h
M       perlvars.h

commit f1d2176bc7ecf5a51b9faeb6e2a2b2e6c900283e
Author: Karl Williamson <k...@cpan.org>
Date:   Mon Jul 24 16:02:34 2017 -0600

    locales: Add #define; change how to override
    
    This changes the controlling #define for using the POSIX 2008 locale
    functions to "USE_POSIX_2008_LOCALE".  The previous controlling name
    "USE_THREAD_SAFE_LOCALE" is retained for backward compatibility.
    
    The reason for this change is that we may add thread-safe locale
    handling even on platforms that don't have Posix 2008, so the name
    USE_THREAD_SAFE_LOCALE would be used for controlling things in that
    situation.
    
    In other words, the concepts may become distinct, and so prepare for
    that.

M       locale.c
M       perl.c
M       perl.h
-----------------------------------------------------------------------

Summary of changes:
 locale.c   | 82 +++++++++++++++++++++++++++++++++++++-------------------------
 makedef.pl |  3 +--
 perl.c     |  2 +-
 perl.h     | 48 ++++++++++++++++++++++++------------
 perlvars.h |  7 +++---
 5 files changed, 87 insertions(+), 55 deletions(-)

diff --git a/locale.c b/locale.c
index 17022031d2..8f5cfd1f39 100644
--- a/locale.c
+++ b/locale.c
@@ -2715,17 +2715,40 @@ Perl_my_strerror(pTHX_ const int errnum)
      * to the C locale */
 
     char *errstr;
+    dVAR;
+
+#ifndef USE_LOCALE_MESSAGES
+
+    /* If platform doesn't have messages category, we don't do any switching to
+     * the C locale; we just use whatever strerror() returns */
+
+    errstr = savepv(Strerror(errnum));
+
+#else   /* Has locale messages */
 
-#ifdef USE_LOCALE_MESSAGES  /* If platform doesn't have messages category, we
-                               don't do any switching to the C locale; we just
-                               use whatever strerror() returns */
     const bool within_locale_scope = IN_LC(LC_MESSAGES);
 
-    dVAR;
+#  if defined(HAS_POSIX_2008_LOCALE) && defined(HAS_STRERROR_L)
+
+    /* This function is trivial if we have strerror_l() */
+
+    if (within_locale_scope) {
+        errstr = strerror(errnum);
+    }
+    else {
+        errstr = strerror_l(errnum, PL_C_locale_obj);
+    }
+
+    errstr = savepv(errstr);
+
+#  else /* Doesn't have strerror_l(). */
+
+#    ifdef USE_POSIX_2008_LOCALE
 
-#  ifdef USE_THREAD_SAFE_LOCALE
     locale_t save_locale = NULL;
-#  else
+
+#    else
+
     char * save_locale = NULL;
     bool locale_is_C = FALSE;
 
@@ -2734,14 +2757,14 @@ Perl_my_strerror(pTHX_ const int errnum)
      * setlocale() ) */
     LOCALE_LOCK;
 
-#  endif
+#    endif
 
     DEBUG_Lv(PerlIO_printf(Perl_debug_log,
                             "my_strerror called with errnum %d\n", errnum));
     if (! within_locale_scope) {
         errno = 0;
 
-#  ifdef USE_THREAD_SAFE_LOCALE /* Use the thread-safe locale functions */
+#  ifdef USE_POSIX_2008_LOCALE /* Use the thread-safe locale functions */
 
         DEBUG_Lv(PerlIO_printf(Perl_debug_log,
                                     "Not within locale scope, about to call"
@@ -2756,7 +2779,7 @@ Perl_my_strerror(pTHX_ const int errnum)
                                     "uselocale returned 0x%p\n", save_locale));
         }
 
-#  else    /* Not thread-safe build */
+#    else    /* Not thread-safe build */
 
         save_locale = setlocale(LC_MESSAGES, NULL);
         if (! save_locale) {
@@ -2776,7 +2799,7 @@ Perl_my_strerror(pTHX_ const int errnum)
             }
         }
 
-#  endif
+#    endif
 
     }   /* end of ! within_locale_scope */
     else {
@@ -2784,33 +2807,14 @@ Perl_my_strerror(pTHX_ const int errnum)
                                                __FILE__, __LINE__));
     }
 
-#endif
-
     DEBUG_Lv(PerlIO_printf(Perl_debug_log,
              "Any locale change has been done; about to call Strerror\n"));
-    errstr = Strerror(errnum);
-    if (errstr) {
-
-#ifdef DEBUGGING
-
-        if (DEBUG_Lv_TEST) {
-            PerlIO_printf(Perl_debug_log, "Strerror returned; saving a copy: 
'");
-            print_bytes_for_locale(errstr, errstr + strlen(errstr), 0);
-            PerlIO_printf(Perl_debug_log, "'\n");
-        }
-
-#endif
-
-        errstr = savepv(errstr);
-        SAVEFREEPV(errstr);
-    }
-
-#ifdef USE_LOCALE_MESSAGES
+    errstr = savepv(Strerror(errnum));
 
     if (! within_locale_scope) {
         errno = 0;
 
-#  ifdef USE_THREAD_SAFE_LOCALE
+#  ifdef USE_POSIX_2008_LOCALE
 
         DEBUG_Lv(PerlIO_printf(Perl_debug_log,
                     "%s: %d: not within locale scope, restoring the locale\n",
@@ -2821,7 +2825,7 @@ Perl_my_strerror(pTHX_ const int errnum)
         }
     }
 
-#  else
+#    else
 
         if (save_locale && ! locale_is_C) {
             if (! setlocale(LC_MESSAGES, save_locale)) {
@@ -2834,9 +2838,21 @@ Perl_my_strerror(pTHX_ const int errnum)
 
     LOCALE_UNLOCK;
 
-#  endif
+#    endif
+#  endif /* End of doesn't have strerror_l */
+#endif   /* End of does have locale messages */
+
+#ifdef DEBUGGING
+
+    if (DEBUG_Lv_TEST) {
+        PerlIO_printf(Perl_debug_log, "Strerror returned; saving a copy: '");
+        print_bytes_for_locale(errstr, errstr + strlen(errstr), 0);
+        PerlIO_printf(Perl_debug_log, "'\n");
+    }
+
 #endif
 
+    SAVEFREEPV(errstr);
     return errstr;
 }
 
diff --git a/makedef.pl b/makedef.pl
index 6e9ea5f0fb..2af197fa43 100644
--- a/makedef.pl
+++ b/makedef.pl
@@ -399,8 +399,7 @@ unless ($define{'USE_ITHREADS'}) {
                         );
 }
 
-unless (   $define{'USE_ITHREADS'}
-        && $define{'HAS_NEWLOCALE'})
+unless ($define{'HAS_NEWLOCALE'} && ! $define{'NO_POSIX_2008_LOCALE'})
 {
     ++$skip{$_} foreach qw(
         PL_C_locale_obj
diff --git a/perl.c b/perl.c
index 563fb3ba51..3ef2cb0ffd 100644
--- a/perl.c
+++ b/perl.c
@@ -456,7 +456,7 @@ perl_construct(pTHXx)
     PL_WB_invlist = _new_invlist_C_array(_Perl_WB_invlist);
     PL_LB_invlist = _new_invlist_C_array(_Perl_LB_invlist);
     PL_Assigned_invlist = _new_invlist_C_array(Assigned_invlist);
-#ifdef USE_THREAD_SAFE_LOCALE
+#ifdef HAS_POSIX_2008_LOCALE
     PL_C_locale_obj = newlocale(LC_ALL_MASK, "C", NULL);
 #endif
 
diff --git a/perl.h b/perl.h
index c5d1923e5e..f9d7dd0492 100644
--- a/perl.h
+++ b/perl.h
@@ -5889,26 +5889,27 @@ typedef struct am_table_short AMTS;
 #ifdef USE_LOCALE
 /* These locale things are all subject to change */
 
-#  if      defined(USE_ITHREADS)                \
-      &&   defined(HAS_NEWLOCALE)               \
+
+#  if      defined(HAS_NEWLOCALE)               \
       &&   defined(LC_ALL_MASK)                 \
       &&   defined(HAS_FREELOCALE)              \
       &&   defined(HAS_USELOCALE)               \
-      && ! defined(NO_THREAD_SAFE_USELOCALE)
+      && ! defined(NO_POSIX_2008_LOCALE)
 
     /* The code is written for simplicity to assume that any platform advanced
      * enough to have the Posix 2008 locale functions has LC_ALL.  The test
      * above makes sure that assumption is valid */
 
-#    define USE_THREAD_SAFE_LOCALE
+#    define HAS_POSIX_2008_LOCALE
 #  endif
 
-#   define LOCALE_INIT   MUTEX_INIT(&PL_locale_mutex)
-
-#   ifdef USE_THREAD_SAFE_LOCALE
-#       define LOCALE_TERM                                                  \
+/* We create a C locale object unconditionally if we have the functions to do
+ * so; hence must destroy it unconditionally at the end */
+#  ifndef HAS_POSIX_2008_LOCALE
+#    define _LOCALE_TERM_POSIX_2008  NOOP
+#  else
+#    define _LOCALE_TERM_POSIX_2008                                         \
                     STMT_START {                                            \
-                        MUTEX_DESTROY(&PL_locale_mutex);                    \
                         if (PL_C_locale_obj) {                              \
                             /* Make sure we aren't using the locale         \
                              * space we are about to free */                \
@@ -5916,13 +5917,28 @@ typedef struct am_table_short AMTS;
                             freelocale(PL_C_locale_obj);                    \
                             PL_C_locale_obj = (locale_t) NULL;              \
                         }                                                   \
-                     } STMT_END
-#   else
-#       define LOCALE_TERM   MUTEX_DESTROY(&PL_locale_mutex)
-#   endif
-
-#   define LOCALE_LOCK   MUTEX_LOCK(&PL_locale_mutex)
-#   define LOCALE_UNLOCK MUTEX_UNLOCK(&PL_locale_mutex)
+                    } STMT_END
+#  endif
+
+#  ifndef USE_ITHREADS
+#    define LOCALE_INIT
+#    define LOCALE_LOCK
+#    define LOCALE_UNLOCK
+#    define LOCALE_TERM  STMT_START { _LOCALE_TERM_POSIX_2008; } STMT_END
+#  else /* Below is do use threads */
+#    define LOCALE_INIT         MUTEX_INIT(&PL_locale_mutex)
+#    define LOCALE_LOCK         MUTEX_LOCK(&PL_locale_mutex)
+#    define LOCALE_UNLOCK       MUTEX_UNLOCK(&PL_locale_mutex)
+#    define LOCALE_TERM                                                     \
+                    STMT_START {                                            \
+                        MUTEX_DESTROY(&PL_locale_mutex);                    \
+                        _LOCALE_TERM_POSIX_2008;                            \
+                    } STMT_END
+#    ifdef HAS_POSIX_2008_LOCALE
+#      define USE_POSIX_2008_LOCALE
+#      define USE_THREAD_SAFE_LOCALE
+#    endif
+#  endif
 
 /* Returns TRUE if the plain locale pragma without a parameter is in effect
  */
diff --git a/perlvars.h b/perlvars.h
index bdc8467902..b184b89419 100644
--- a/perlvars.h
+++ b/perlvars.h
@@ -101,10 +101,11 @@ PERLVARI(G, mmap_page_size, IV, 0)
 PERLVAR(G, hints_mutex, perl_mutex)    /* Mutex for refcounted he refcounting 
*/
 PERLVAR(G, locale_mutex, perl_mutex)   /* Mutex for setlocale() changing */
 
-#   ifdef HAS_NEWLOCALE
-PERLVAR(G, C_locale_obj, locale_t)
-#   endif
+#endif
 
+/* Proxy for HAS_POSIX_2008_LOCALE, since that is not defined in time for this 
*/
+#if defined(HAS_NEWLOCALE) && ! defined(NO_POSIX_2008_LOCALE)
+PERLVAR(G, C_locale_obj, locale_t)
 #endif
 
 #ifdef DEBUGGING

--
Perl5 Master Repository

Reply via email to