diff options
author | David Mitchell <davem@iabyn.com> | 2020-03-12 14:14:24 +0000 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2020-03-18 15:23:37 +0000 |
commit | ad89278aa25475fb03971aec66692e18e35d9c07 (patch) | |
tree | 372b56d33bbb6f03b330f5e7f0be3a1a85a92dd9 | |
parent | 2f07b2fb1d76d4d4f344f296ee3432f3f3ce4580 (diff) | |
download | perl-ad89278aa25475fb03971aec66692e18e35d9c07.tar.gz |
fixup to "avoid identical stack traces" - try 2
GH #15109, #17567
[ this commit was originally applied as v5.31.9-121-gfb8188b84d, but was
quickly reverted by v5.31.9-124-g6311900a66. I'm now -re-applying it,
but with a 'SAVEFREEOP(PL_curcop)' added, which was missing from the
original commit. ]
My original fix for this issue, v5.31.6-141-gf2f32cd638
made a shallow copy of &PL_compiling. However, for non-default
warning bits, this made two COPs share the malloced() cop_warnings,
and bad things ensured. In particular this was flagged up in:
GH #17567: "BBC: AYOUNG/OpenVZ-0.01.tar.gz"
The fix in this commit is to do a deep copy of the COP using
newSTATEOP().
-rw-r--r-- | MANIFEST | 1 | ||||
-rw-r--r-- | op.c | 7 | ||||
-rw-r--r-- | t/lib/GH_15109/Foo.pm | 9 | ||||
-rw-r--r-- | t/op/caller.t | 22 |
4 files changed, 30 insertions, 9 deletions
@@ -5648,6 +5648,7 @@ t/lib/feature/switch Tests for enabling/disabling switch feature t/lib/GH_15109/Apack.pm test Module for caller.t t/lib/GH_15109/Bpack.pm test Module for caller.t t/lib/GH_15109/Cpack.pm test Module for caller.t +t/lib/GH_15109/Foo.pm test Module for caller.t t/lib/h2ph.h Test header file for h2ph t/lib/h2ph.pht Generated output from h2ph.h by h2ph, for comparison t/lib/locale/latin1 Part of locale.t in Latin 1 @@ -11712,10 +11712,9 @@ S_process_special_blocks(pTHX_ I32 floor, const char *const fullname, * to PL_compiling, IN_PERL_COMPILETIME/IN_PERL_RUNTIME * will give the wrong answer. */ - Newx(PL_curcop, 1, COP); - StructCopy(&PL_compiling, PL_curcop, COP); - PL_curcop->op_slabbed = 0; - SAVEFREEPV(PL_curcop); + PL_curcop = (COP*)newSTATEOP(PL_compiling.op_flags, NULL, NULL); + CopLINE_set(PL_curcop, CopLINE(&PL_compiling)); + SAVEFREEOP(PL_curcop); } PUSHSTACKi(PERLSI_REQUIRE); diff --git a/t/lib/GH_15109/Foo.pm b/t/lib/GH_15109/Foo.pm new file mode 100644 index 0000000000..1af25470c6 --- /dev/null +++ b/t/lib/GH_15109/Foo.pm @@ -0,0 +1,9 @@ +# for use by caller.t for GH #15109 + +package Foo; + +sub import { + use warnings; # restore default warnings + () = caller(1); # this used to cause valgrind errors +} +1; diff --git a/t/op/caller.t b/t/op/caller.t index 9fc9a1ce39..865b005bf5 100644 --- a/t/op/caller.t +++ b/t/op/caller.t @@ -5,7 +5,7 @@ BEGIN { chdir 't' if -d 't'; require './test.pl'; set_up_inc('../lib'); - plan( tests => 109 ); # some tests are run in a BEGIN block + plan( tests => 111 ); # some tests are run in a BEGIN block } my @c; @@ -349,6 +349,20 @@ do './op/caller.pl' or die $@; like($Cpack::callers[$_], qr{GH_15109/Apack.pm:3}, "GH #15109 level $_") for 3..5; like($Cpack::callers[$_], qr{\(eval \d+\):1}, "GH #15109 level $_") for 6..8; like($Cpack::callers[$_], qr{caller\.t}, "GH #15109 level $_") for 9; + + # GH #15109 followup - the original fix wasn't saving cop_warnings + # correctly and this code used to crash or fail valgrind + + my $w = 0; + local $SIG{__WARN__} = sub { $w++ }; + eval q{ + use warnings; + no warnings 'numeric'; # ensure custom cop_warnings + use Foo; # this used to mess up warnings flags + BEGIN { my $x = "foo" + 1; } # potential "numeric" warning + }; + is ($@, "", "GH #15109 - eval okay"); + is ($w, 0, "GH #15109 - warnings restored"); } { @@ -357,11 +371,9 @@ do './op/caller.pl' or die $@; my ($pkg, $file, $line) = caller; ::is $file, 'virtually/op/caller.t', "BEGIN block sees correct caller filename"; ::is $line, 12345, "BEGIN block sees correct caller line"; - TODO: { - local $::TODO = "BEGIN blocks have wrong caller package [perl #129239]"; - ::is $pkg, 'RT129239', "BEGIN block sees correct caller package"; - } + ::is $pkg, 'RT129239', "BEGIN block sees correct caller package"; #line 12345 "virtually/op/caller.t" } + } |