Skip to content

Commit

Permalink
Fix crash when lex subs are used for AUTOLOAD
Browse files Browse the repository at this point in the history
  • Loading branch information
Father Chrysostomos committed Aug 28, 2014
1 parent 4dda930 commit 1869162
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gv.c
Expand Up @@ -1198,7 +1198,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;

Expand Down
20 changes: 19 additions & 1 deletion t/op/lexsub.t
Expand Up @@ -7,7 +7,7 @@ BEGIN {
*bar::is = *is;
*bar::like = *like;
}
plan 120;
plan 122;

# -------------------- Errors with feature disabled -------------------- #

Expand Down Expand Up @@ -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 -------------------- #

Expand Down Expand Up @@ -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) -------------------- #

Expand Down

0 comments on commit 1869162

Please sign in to comment.