This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove unwarranted assertion in Perl_newATTRSUB_x()
authorAaron Crane <arc@cpan.org>
Sun, 3 Jan 2016 14:29:43 +0000 (14:29 +0000)
committerAaron Crane <arc@cpan.org>
Sun, 3 Jan 2016 15:29:24 +0000 (15:29 +0000)
RT #126845: if a stub subroutine definition with a prototype has been seen,
then any subsequent stub (or definition) of the same subroutine with an
attribute was causing an assertion failure because of a null pointer.

This assertion was added in 2eaf799e74b14dc77b90d5484a3fd4ceac12b46a, which
itself would already have triggered this assertion failure, even though all
subsequent uses of the pointer in question were guarded with non-null
conditions. So merely deleting the assertion is the right thing.

op.c
t/op/sub.t

diff --git a/op.c b/op.c
index 0de303c..1b78a4c 100644 (file)
--- a/op.c
+++ b/op.c
@@ -8407,7 +8407,6 @@ Perl_newATTRSUB_x(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs,
         const_sv = NULL;
 
     if (SvPOK(gv) || (SvROK(gv) && SvTYPE(SvRV(gv)) != SVt_PVCV)) {
-       assert (block);
        cv_ckproto_len_flags((const CV *)gv,
                             o ? (const GV *)cSVOPo->op_sv : NULL, ps,
                             ps_len, ps_utf8|CV_CKPROTO_CURSTASH);
index d9b7b3c..0e9b603 100644 (file)
@@ -6,7 +6,7 @@ BEGIN {
     set_up_inc('../lib');
 }
 
-plan(tests => 55);
+plan(tests => 57);
 
 sub empty_sub {}
 
@@ -246,6 +246,13 @@ predeclared(); # set $x to 42
 $main::x = $main::x = "You should not see this.";
 inside_predeclared(); # run test
 
+# RT #126845: this used to fail an assertion in Perl_newATTRSUB_x()
+eval 'sub rt126845_1 (); sub rt126845_1 () :lvalue';
+pass("RT #126845: stub with prototype, then with attribute");
+
+eval 'sub rt126845_2 (); sub rt126845_2 () :lvalue {}';
+pass("RT #126845: stub with prototype, then definition with attribute");
+
 # RT #124156 death during unwinding causes crash
 # the tie allows us to trigger another die while cleaning up the stack
 # from an earlier die.