diff options
author | Father Chrysostomos <sprout@cpan.org> | 2014-08-28 06:31:48 -0700 |
---|---|---|
committer | Steve Hay <steve.m.hay@googlemail.com> | 2014-12-27 12:18:56 +0000 |
commit | 806e35e902f3c0f48b542708cb7110b57d15d718 (patch) | |
tree | 025d877de2f6ad8682f7436eb061a49430a9899e | |
parent | ea136445d3d39ab4051ce197548b87b46585ed8b (diff) | |
download | perl-806e35e902f3c0f48b542708cb7110b57d15d718.tar.gz |
Fix crash when lex subs are used for AUTOLOAD
(cherry picked from commit 18691622911f2e18df42a5a98ea4c42386f4e558)
-rw-r--r-- | gv.c | 2 | ||||
-rw-r--r-- | t/op/lexsub.t | 20 |
2 files changed, 20 insertions, 2 deletions
@@ -1202,7 +1202,7 @@ Perl_gv_autoload_pvn(pTHX_ HV *stash, const char *name, STRLEN len, U32 flags) * use that, but for lack of anything better we will use the sub's * original package to look up $AUTOLOAD. */ - varstash = GvSTASH(CvGV(cv)); + varstash = CvNAMED(cv) ? CvSTASH(cv) : GvSTASH(CvGV(cv)); vargv = *(GV**)hv_fetch(varstash, S_autoload, S_autolen, TRUE); ENTER; diff --git a/t/op/lexsub.t b/t/op/lexsub.t index d5fdcb1374..54bb985f7d 100644 --- a/t/op/lexsub.t +++ b/t/op/lexsub.t @@ -7,7 +7,7 @@ BEGIN { *bar::is = *is; *bar::like = *like; } -plan 120; +plan 122; # -------------------- Errors with feature disabled -------------------- # @@ -313,6 +313,15 @@ like runperl( ), qr/syntax error/, 'referencing a state sub after a syntax error does not crash'; +{ + state $stuff; + package A { + state sub foo{ $stuff .= our $AUTOLOAD } + *A::AUTOLOAD = \&foo; + } + A::bar(); + is $stuff, 'A::bar', 'state sub assigned to *AUTOLOAD can autoload'; +} # -------------------- my -------------------- # @@ -606,6 +615,15 @@ like runperl( ), qr/syntax error/, 'referencing a my sub after a syntax error does not crash'; +{ + state $stuff; + package A { + my sub foo{ $stuff .= our $AUTOLOAD } + *A::AUTOLOAD = \&foo; + } + A::bar(); + is $stuff, 'A::bar', 'my sub assigned to *AUTOLOAD can autoload'; +} # -------------------- Interactions (and misc tests) -------------------- # |