develooper Front page | perl.perl5.changes | Postings from March 2018

[perl.git] branch blead updated. v5.27.8-419-gb2f82b5200

From:
Karl Williamson
Date:
March 2, 2018 01:47
Subject:
[perl.git] branch blead updated. v5.27.8-419-gb2f82b5200
Message ID:
E1erZn2-0007uf-FR@git.dc.perl.space
In perl.git, the branch blead has been updated

<https://perl5.git.perl.org/perl.git/commitdiff/b2f82b52000c3bfe6e6df200c775e2a639d91552?hp=4ac5f10b7537a9008856dd6cd7a9fd94e0dffc32>

- Log -----------------------------------------------------------------
commit b2f82b52000c3bfe6e6df200c775e2a639d91552
Author: Karl Williamson <khw@cpan.org>
Date:   Sun Feb 25 21:38:21 2018 -0700

    Silence wrong clang warnings
    
    Clang thread-safety analysis fails to correctly work in this situation
    (and is documented as failing), so turn off that warning here.

commit f0dafd73171c0c953273ca301e81fe2b7a040cc2
Author: Karl Williamson <khw@cpan.org>
Date:   Thu Mar 1 18:09:42 2018 -0700

    numeric.c: Refactor code to use only one RESTORE
    
    This code saves and restores the LC_NUMERIC locale.  This commit
    refactors it so that only one RESTORE is done.  The reason is because
    having two, depending on various data confuses clang's static analysis
    of thread safety, leading to false positive scary warnings.

-----------------------------------------------------------------------

Summary of changes:
 numeric.c | 34 +++++++++++++++++++++++-----------
 perl.h    |  6 ++++--
 sv.c      |  5 +++++
 3 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/numeric.c b/numeric.c
index 04df0cfa48..8754a9f649 100644
--- a/numeric.c
+++ b/numeric.c
@@ -523,27 +523,39 @@ Perl_grok_numeric_radix(pTHX_ const char **sp, const char *send)
 #ifdef USE_LOCALE_NUMERIC
 
     if (IN_LC(LC_NUMERIC)) {
+        STRLEN len;
+        char * radix;
+        bool matches_radix = FALSE;
         DECLARATION_FOR_LC_NUMERIC_MANIPULATION;
+
         STORE_LC_NUMERIC_FORCE_TO_UNDERLYING();
-        {
-            STRLEN len;
-            const char * const radix = SvPV(PL_numeric_radix_sv, len);
-            if (*sp + len <= send && memEQ(*sp, radix, len)) {
-                *sp += len;
-                RESTORE_LC_NUMERIC();
-                return TRUE;
-            }
-        }
+
+        radix = SvPV(PL_numeric_radix_sv, len);
+        radix = savepvn(radix, len);
+
         RESTORE_LC_NUMERIC();
+
+        if (*sp + len <= send) {
+            matches_radix = memEQ(*sp, radix, len);
+        }
+
+        Safefree(radix);
+
+        if (matches_radix) {
+            *sp += len;
+            return TRUE;
+        }
     }
-    /* always try "." if numeric radix didn't match because
-     * we may have data from different locales mixed */
+
 #endif
 
+    /* always try "." if numeric radix didn't match because
+     * we may have data from different locales mixed */
     if (*sp < send && **sp == '.') {
         ++*sp;
         return TRUE;
     }
+
     return FALSE;
 }
 
diff --git a/perl.h b/perl.h
index 1473721e68..d20fdd0f75 100644
--- a/perl.h
+++ b/perl.h
@@ -5590,6 +5590,7 @@ typedef struct am_table_short AMTS;
  * this would be an attempt to complement the LC_NUMERIC state, and we're not
  * supposed to because it's locked */
 #    define LC_NUMERIC_LOCK(cond_to_panic_if_already_locked)                \
+        CLANG_DIAG_IGNORE(-Wthread-safety)	     	                    \
         STMT_START {                                                        \
             if (PL_lc_numeric_mutex_depth <= 0) {                           \
                 MUTEX_LOCK(&PL_lc_numeric_mutex);                           \
@@ -5617,7 +5618,7 @@ typedef struct am_table_short AMTS;
                 MUTEX_UNLOCK(&PL_lc_numeric_mutex);                         \
                 PL_lc_numeric_mutex_depth = 0;                              \
                 DEBUG_Lv(PerlIO_printf(Perl_debug_log,                      \
-                         "%s: %d: unlocking lc_numeric; depth=0\n",           \
+                         "%s: %d: unlocking lc_numeric; depth=0\n",         \
                          __FILE__, __LINE__));                              \
             }                                                               \
             else {                                                          \
@@ -5626,7 +5627,8 @@ typedef struct am_table_short AMTS;
                         "%s: %d: avoided lc_numeric_unlock; depth=%d\n",    \
                         __FILE__, __LINE__, PL_lc_numeric_mutex_depth));    \
             }                                                               \
-        } STMT_END
+        } STMT_END                                                          \
+        CLANG_DIAG_RESTORE
 
 /* This is used as a generic lock for locale operations.  For example this is
  * used when calling nl_langinfo() so that another thread won't zap the
diff --git a/sv.c b/sv.c
index 2475d46bf5..231215e766 100644
--- a/sv.c
+++ b/sv.c
@@ -2667,6 +2667,7 @@ Perl_sv_2nv_flags(pTHX_ SV *const sv, const I32 flags)
     if (SvTYPE(sv) < SVt_NV) {
 	/* The logic to use SVt_PVNV if necessary is in sv_upgrade.  */
 	sv_upgrade(sv, SVt_NV);
+        CLANG_DIAG_IGNORE_STMT(-Wthread-safety);
 	DEBUG_c({
             DECLARATION_FOR_LC_NUMERIC_MANIPULATION;
             STORE_LC_NUMERIC_SET_STANDARD();
@@ -2675,6 +2676,8 @@ Perl_sv_2nv_flags(pTHX_ SV *const sv, const I32 flags)
 			  PTR2UV(sv), SvNVX(sv));
             RESTORE_LC_NUMERIC();
 	});
+        CLANG_DIAG_RESTORE_STMT;
+
     }
     else if (SvTYPE(sv) < SVt_PVNV)
 	sv_upgrade(sv, SVt_PVNV);
@@ -2809,6 +2812,7 @@ Perl_sv_2nv_flags(pTHX_ SV *const sv, const I32 flags)
 	   and ideally should be fixed.  */
 	return 0.0;
     }
+    CLANG_DIAG_IGNORE_STMT(-Wthread-safety);
     DEBUG_c({
         DECLARATION_FOR_LC_NUMERIC_MANIPULATION;
         STORE_LC_NUMERIC_SET_STANDARD();
@@ -2816,6 +2820,7 @@ Perl_sv_2nv_flags(pTHX_ SV *const sv, const I32 flags)
 		      PTR2UV(sv), SvNVX(sv));
         RESTORE_LC_NUMERIC();
     });
+    CLANG_DIAG_RESTORE_STMT;
     return SvNVX(sv);
 }
 

-- 
Perl5 Master Repository



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About