diff options
author | Chip Salzenberg <chip@perl.com> | 1997-04-03 10:03:18 +1200 |
---|---|---|
committer | Chip Salzenberg <chip@atlantic.net> | 1997-04-03 10:03:25 +1200 |
commit | 09280a334577a8254c4115b822e1f8cc667611a1 (patch) | |
tree | 5248ec052bcee25ef7a4efc61f20a99d7e7a04e8 | |
parent | 8523fd8370f87f8e7cc44b73b86edff69f32270d (diff) | |
download | perl-09280a334577a8254c4115b822e1f8cc667611a1.tar.gz |
Fix AUTOLOAD, or kill me
-rw-r--r-- | gv.c | 15 | ||||
-rw-r--r-- | pp.c | 4 | ||||
-rwxr-xr-x | t/op/method.t | 11 |
3 files changed, 23 insertions, 7 deletions
@@ -285,8 +285,19 @@ I32 autoload; } else if (autoload) { CV* cv = GvCV(gv); - if (!cv || (!CvROOT(cv) && !CvXSUB(cv))) { - GV* autogv = gv_autoload4(GvSTASH(gv), name, nend - name, TRUE); + if (!CvROOT(cv) && !CvXSUB(cv)) { + GV* stubgv; + GV* autogv; + + if (CvANON(cv)) + stubgv = gv; + else { + stubgv = CvGV(cv); + if (GvCV(stubgv) != cv) /* orphaned import */ + stubgv = gv; + } + autogv = gv_autoload4(GvSTASH(stubgv), + GvNAME(stubgv), GvNAMELEN(stubgv), TRUE); if (autogv) gv = autogv; } @@ -557,7 +557,9 @@ PP(pp_undef) CvANON((CV*)sv) ? "(anonymous)" : GvENAME(CvGV((CV*)sv))); /* FALL THROUGH */ case SVt_PVFM: - cv_undef((CV*)sv); + { GV* gv = (GV*)SvREFCNT_inc(CvGV((CV*)sv)); + cv_undef((CV*)sv); + CvGV((CV*)sv) = gv; } /* let user-undef'd sub keep its identity */ break; case SVt_PVGV: if (SvFAKE(sv)) diff --git a/t/op/method.t b/t/op/method.t index bdbc8a9673..21d7c8f397 100755 --- a/t/op/method.t +++ b/t/op/method.t @@ -64,6 +64,7 @@ test (eval { A->x } || "nope", "nope"); eval <<'EOF'; sub C::e; +BEGIN { *B::e = \&C::e } # Shouldn't prevent AUTOLOAD in original pkg sub Y::f; $counter = 0; @@ -73,14 +74,16 @@ $counter = 0; sub B::AUTOLOAD { my $c = ++$counter; my $method = $B::AUTOLOAD; - *$B::AUTOLOAD = sub { "B: In $method, $c" }; - goto &$B::AUTOLOAD; + my $msg = "B: In $method, $c"; + eval "sub $method { \$msg }"; + goto &$method; } sub C::AUTOLOAD { my $c = ++$counter; my $method = $C::AUTOLOAD; - *$C::AUTOLOAD = sub { "C: In $method, $c" }; - goto &$C::AUTOLOAD; + my $msg = "C: In $method, $c"; + eval "sub $method { \$msg }"; + goto &$method; } EOF |