From: Abhijit Menon-Sen Date: Sat, 16 Mar 2002 02:38:08 +0000 (+0000) Subject: Subject: [PATCH @15047] Use of inherited AUTOLOAD for non-method X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3ad83ce7d21aa3aa1ac69bde413ed71b6ce30329;p=p5sagit%2Fp5-mst-13.2.git Subject: [PATCH @15047] Use of inherited AUTOLOAD for non-method *::DESTROY() is deprecated From: Ilya Zakharevich Date: Thu, 14 Mar 2002 18:39:22 -0500 Message-Id: <20020314183922.A8448@math.ohio-state.edu> Subject: Re: [PATCH @15047] Use of inherited AUTOLOAD for non-method *::DESTROY() is deprecated From: Dave Mitchell Date: Fri, 15 Mar 2002 19:22:49 +0000 Message-Id: <20020315192249.A22389@fdgroup.com> p4raw-link: @15047 on //depot/perl: 0cce8c827906d6294f47c30840f886b52d8345f8 p4raw-id: //depot/perl@15251 --- diff --git a/gv.c b/gv.c index 3785a2b..6fd5ff7 100644 --- a/gv.c +++ b/gv.c @@ -1412,6 +1412,7 @@ Perl_gv_handler(pTHX_ HV *stash, I32 id) { MAGIC *mg; AMT *amtp; + CV *ret; if (!stash) return Nullcv; @@ -1425,8 +1426,21 @@ Perl_gv_handler(pTHX_ HV *stash, I32 id) if ( amtp->was_ok_am != PL_amagic_generation || amtp->was_ok_sub != PL_sub_generation ) goto do_update; - if (AMT_AMAGIC(amtp)) - return amtp->table[id]; + if (AMT_AMAGIC(amtp)) { + ret = amtp->table[id]; + if (ret && isGV(ret)) { /* Autoloading stab */ + /* Passing it through may have resulted in a warning + "Inherited AUTOLOAD for a non-method deprecated", since + our caller is going through a function call, not a method call. + So return the CV for AUTOLOAD, setting $AUTOLOAD. */ + GV *gv = gv_fetchmethod(stash, (char*)PL_AMG_names[id]); + + if (gv && GvCV(gv)) + return GvCV(gv); + } + return ret; + } + return Nullcv; } diff --git a/t/op/method.t b/t/op/method.t index 0d4e09b..0ce8ce8 100755 --- a/t/op/method.t +++ b/t/op/method.t @@ -9,7 +9,7 @@ BEGIN { @INC = '../lib'; } -print "1..73\n"; +print "1..74\n"; @A::ISA = 'B'; @B::ISA = 'C'; @@ -249,4 +249,20 @@ test ( ] || $@, 'ok' ); +# An autoloaded, inherited DESTROY may be invoked differently than normal +# methods, and has been known to give rise to spurious warnings +# eg <200203121600.QAA11064@gizmo.fdgroup.co.uk> + +{ + use warnings; + my $w = ''; + local $SIG{__WARN__} = sub { $w = $_[0] }; + + sub AutoDest::Base::AUTOLOAD {} + @AutoDest::ISA = qw(AutoDest::Base); + { my $x = bless {}, 'AutoDest'; } + $w =~ s/\n//g; + test($w, ''); +} + print "# $cnt tests completed\n";