summaryrefslogtreecommitdiff
path: root/t/op/lexsub.t
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2013-06-02 13:25:24 -0700
committerFather Chrysostomos <sprout@cpan.org>2013-06-02 13:25:24 -0700
commit3a74e0e282cd5c2593f9477923d3bcb1f32ece37 (patch)
tree23a45139900f09299e4c3e1315b07a02a218f5fb /t/op/lexsub.t
parent9a5e6f3cd84e6eaf40dad034fb9d25cb3361accc (diff)
downloadperl-3a74e0e282cd5c2593f9477923d3bcb1f32ece37.tar.gz
Fix crashes after syntax errors in lexical subs
Peter Martini fixed this in commit 89e006ae4e39db for our subs. (Thank you, BTW, if you are reading this.) The warning is expected; the assertion failure is not: $ ./miniperl -Ilib -Mfeature=:all -e 'state sub a { is ref } a()' The lexical_subs feature is experimental at -e line 1. Assertion failed: (hek), function Perl_ck_subr, file op.c, line 10558. Abort trap: 6 $ ./miniperl -Ilib -Mfeature=:all -e 'my sub a { is ref } a()' The lexical_subs feature is experimental at -e line 1. Assertion failed: (SvTYPE(_svmagic) >= SVt_PVMG), function S_mg_findext_flags, file mg.c, line 398. Abort trap: 6 $ The prototype CV for a my sub is stored in magic attached to the pad name. The. The code to fetch the prototype CV for a my sub calls mg_find on the pad name. If a syntax error occurs when the sub is be ing compiled, the magic will never be attached, so the pad name (pad names are currently SVs) will not have been upgraded to SVt_PVMG, causing an assertion failure in mg_find, which only accepts SVs thus upgraded. When a pad entry is created, it is automatically filled with an empty SV of the appropriate type. For a subroutine, this is a nameless CV stub. CVs can be named in two ways, via GVs for package subs, or via heks for lexical subs. This stub has neither and is truly nameless. Since a lexical sub is never installed if it contains a syntax error, this stub is visible during subsequent compilation in the same scope. ck_subr wasn’t prepared to handle a stub with absolutely no name attached to it, since it is designed for handling sub calls where the sub is known at compile time, so there must be a GV available to it, unless the sub is lexical, and all lexical subs have heks. This commit fixes the assumptions in both places. Exactly what hap- pens and what is returned is not so important, as this only hap- pens after a syntax error, when the op tree is going to be thrown away anyway.
Diffstat (limited to 't/op/lexsub.t')
-rw-r--r--t/op/lexsub.t4
1 files changed, 0 insertions, 4 deletions
diff --git a/t/op/lexsub.t b/t/op/lexsub.t
index 0e101e865f..d70f2ccf2b 100644
--- a/t/op/lexsub.t
+++ b/t/op/lexsub.t
@@ -321,7 +321,6 @@ sub make_anon_with_state_sub{
}
r(1);
}
-$::TODO = ' ';
like runperl(
switches => [ '-Mfeature=:all' ],
prog => 'state sub a { foo ref } a()',
@@ -329,7 +328,6 @@ like runperl(
),
qr/syntax error/,
'referencing a state sub after a syntax error does not crash';
-undef $::TODO;
# -------------------- my -------------------- #
@@ -622,7 +620,6 @@ not_lexical11();
eval q{ my sub george () { 2 } };
is $w, undef, 'no double free from constant my subs';
}
-$::TODO = ' ';
like runperl(
switches => [ '-Mfeature=:all' ],
prog => 'my sub a { foo ref } a()',
@@ -630,7 +627,6 @@ like runperl(
),
qr/syntax error/,
'referencing a my sub after a syntax error does not crash';
-undef $::TODO;
# -------------------- Interactions (and misc tests) -------------------- #