This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix crash when lex subs are used for AUTOLOAD
authorFather Chrysostomos <sprout@cpan.org>
Thu, 28 Aug 2014 13:31:48 +0000 (06:31 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 28 Aug 2014 13:33:25 +0000 (06:33 -0700)
gv.c
t/op/lexsub.t

diff --git a/gv.c b/gv.c
index 500e24b..7e3058d 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -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;
 
index d5fdcb1..54bb985 100644 (file)
@@ -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) -------------------- #