From c220e1a11e00efe060ea99925553cb1e03e3363a Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Sat, 7 Jul 2012 23:39:07 -0700 Subject: [PATCH] Correct err msg when calling stub w/no autoload fb MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit If an AUTOLOAD subroutine loads a sub by assigning to the glob, there may be code elsewhere that has a reference to a stub, that is now assigned over. To cope with this situation, calls to undefined sub- routines will fall back to whatever sub is in the subroutine’s owner typeglob. This has been the case since Perl 5.000. But the error message that occurs if the typeglob happens to have no sub in it is wrong: $ perl -e ' my $foosub = \&foo; undef *foo; &$foosub; ' Not a CODE reference at -e line 4. as opposed to this: $ perl -e ' my $foosub = \&foo; &$foosub; ' Undefined subroutine &main::foo called at -e line 3. They should both produce the same error message, because $foosub is a code reference, albeit without a body. --- MANIFEST | 1 + pp_hot.c | 4 ++-- t/lib/croak/pp_hot | 13 +++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 t/lib/croak/pp_hot diff --git a/MANIFEST b/MANIFEST index 7a5d0c0..1396660 100644 --- a/MANIFEST +++ b/MANIFEST @@ -5034,6 +5034,7 @@ t/lib/compmod.pl Helper for 1_compile.t t/lib/croak/mg Test croak calls from mg.c t/lib/croak/op Test croak calls from op.c t/lib/croak/pp_ctl Test croak calls from pp_ctl.c +t/lib/croak/pp_hot Test croak calls from pp_hot.c t/lib/croak.t Test calls to Perl_croak() in the C source. t/lib/croak/toke Test croak calls from toke.c t/lib/cygwin.t Builtin cygwin function tests diff --git a/pp_hot.c b/pp_hot.c index 77b707c..38c49a0 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -2648,15 +2648,15 @@ try_autoload: { cv = GvCV(autogv); } - /* sorry */ else { + sorry: sub_name = sv_newmortal(); gv_efullname3(sub_name, gv, NULL); DIE(aTHX_ "Undefined subroutine &%"SVf" called", SVfARG(sub_name)); } } if (!cv) - DIE(aTHX_ "Not a CODE reference"); + goto sorry; goto retry; } diff --git a/t/lib/croak/pp_hot b/t/lib/croak/pp_hot new file mode 100644 index 0000000..1e12fbb --- /dev/null +++ b/t/lib/croak/pp_hot @@ -0,0 +1,13 @@ +__END__ +# NAME calling undef sub belonging to undef GV + my $foosub = \&foo; + undef *foo; + &$foosub; +EXPECT +Undefined subroutine &main::foo called at - line 3. +######## +# NAME calling undef sub resident in its GV + my $foosub = \&foo; + &$foosub; +EXPECT +Undefined subroutine &main::foo called at - line 2. -- 2.7.4