This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fixup to free_and_set_cop_warnings()
authorDavid Mitchell <davem@iabyn.com>
Fri, 20 Mar 2020 09:06:57 +0000 (09:06 +0000)
committerDavid Mitchell <davem@iabyn.com>
Fri, 20 Mar 2020 09:06:57 +0000 (09:06 +0000)
v5.31.9-156-g94c8b9c1f0 introduced the free_and_set_cop_warnings()
macro. It's first argument expects a COP rather than a COP*. Its usage
in S_restore_cop_warnings(() is to modify PL_cucop, but in order to pass
a COP rather than a COP*, the original commit made a local copy of
PL_curcop and ended up inadvertently updating the copy instead.

This commit changes the maco so it expects a COP*, and updates the bulk
of its callers to use &PL_compiling rather than PL_compiling, and fixes
up S_restore_cop_warnings().

The symptoms were ASAN failures in a few test scripts including
uni/parser.t and ext/XS-APItest/t/handy0*.t.

(The S_restore_cop_warnings() function was only used by
Perl__force_out_malformed_utf8_message(), so didn't cause many issues
outside of test scripts which forced such "malformed "errors).

mg.c
perl.c
regen/warnings.pl
scope.c
utf8.c
warnings.h

diff --git a/mg.c b/mg.c
index b21f4d3..e603b60 100644 (file)
--- a/mg.c
+++ b/mg.c
@@ -2966,7 +2966,7 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg)
        else if (strEQ(mg->mg_ptr+1, "ARNING_BITS")) {
            if ( ! (PL_dowarn & G_WARN_ALL_MASK)) {
                if (!SvPOK(sv)) {
-            free_and_set_cop_warnings(PL_compiling, pWARN_STD);
+            free_and_set_cop_warnings(&PL_compiling, pWARN_STD);
                    break;
                }
                {
@@ -2978,9 +2978,9 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg)
                        not_all |= ptr[i] ^ 0x55;
                    }
                    if (!not_none) {
-                free_and_set_cop_warnings(PL_compiling, pWARN_NONE);
+                free_and_set_cop_warnings(&PL_compiling, pWARN_NONE);
                    } else if (len >= WARNsize && !not_all) {
-                free_and_set_cop_warnings(PL_compiling, pWARN_ALL);
+                free_and_set_cop_warnings(&PL_compiling, pWARN_ALL);
                    PL_dowarn |= G_WARN_ONCE ;
                }
             else {
diff --git a/perl.c b/perl.c
index fdfd1cd..9d1faf4 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -1245,7 +1245,7 @@ perl_destruct(pTHXx)
         }
     }
 
-    free_and_set_cop_warnings(PL_compiling, NULL);
+    free_and_set_cop_warnings(&PL_compiling, NULL);
     cophh_free(CopHINTHASH_get(&PL_compiling));
     CopHINTHASH_set(&PL_compiling, cophh_new_empty());
     CopFILE_free(&PL_compiling);
@@ -3738,12 +3738,12 @@ Perl_moreswitches(pTHX_ const char *s)
        return s;
     case 'W':
        PL_dowarn = G_WARN_ALL_ON|G_WARN_ON;
-    free_and_set_cop_warnings(PL_compiling, pWARN_ALL);
+    free_and_set_cop_warnings(&PL_compiling, pWARN_ALL);
        s++;
        return s;
     case 'X':
        PL_dowarn = G_WARN_ALL_OFF;
-    free_and_set_cop_warnings(PL_compiling, pWARN_NONE);
+    free_and_set_cop_warnings(&PL_compiling, pWARN_NONE);
        s++;
        return s;
     case '*':
index a73ca9e..6000c75 100644 (file)
@@ -393,8 +393,8 @@ EOM
 #define DUP_WARNINGS(p) Perl_dup_warnings(aTHX_ p)
 
 #define free_and_set_cop_warnings(cmp,w) STMT_START { \
-  if (!specialWARN(cmp.cop_warnings)) PerlMemShared_free(cmp.cop_warnings); \
-  cmp.cop_warnings = w; \
+  if (!specialWARN((cmp)->cop_warnings)) PerlMemShared_free((cmp)->cop_warnings); \
+  (cmp)->cop_warnings = w; \
 } STMT_END
 
 /*
diff --git a/scope.c b/scope.c
index ad8f8e7..a948a7b 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -1448,7 +1448,7 @@ Perl_leave_scope(pTHX_ I32 base)
 
        case SAVEt_COMPILE_WARNINGS:
             a0 = ap[0];
-        free_and_set_cop_warnings(PL_compiling, (STRLEN*) a0.any_ptr);
+        free_and_set_cop_warnings(&PL_compiling, (STRLEN*) a0.any_ptr);
            break;
 
        case SAVEt_PARSER:
diff --git a/utf8.c b/utf8.c
index ac07507..2b30cad 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -55,8 +55,7 @@ within non-zero characters.
 static void
 S_restore_cop_warnings(pTHX_ void *p)
 {
-    COP curcop = *PL_curcop;
-    free_and_set_cop_warnings(curcop, (STRLEN*) p);
+    free_and_set_cop_warnings(PL_curcop, (STRLEN*) p);
 }
 
 
index 37ab205..f02edea 100644 (file)
 #define DUP_WARNINGS(p) Perl_dup_warnings(aTHX_ p)
 
 #define free_and_set_cop_warnings(cmp,w) STMT_START { \
-  if (!specialWARN(cmp.cop_warnings)) PerlMemShared_free(cmp.cop_warnings); \
-  cmp.cop_warnings = w; \
+  if (!specialWARN((cmp)->cop_warnings)) PerlMemShared_free((cmp)->cop_warnings); \
+  (cmp)->cop_warnings = w; \
 } STMT_END
 
 /*