From 55b37f1c313121c8cbb341aceea93a386169d6fd Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Wed, 28 Nov 2012 22:42:57 -0800 Subject: [PATCH] pp_goto: Call get-magic before choosing goto type Deciding whether this is goto-label or goto-sub can only correctly happen after get-magic has been invoked, as get-magic can cause the argument to begin or cease to be a subroutine reference. --- pp_ctl.c | 3 ++- t/op/goto.t | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pp_ctl.c b/pp_ctl.c index f889ca8..0256070 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -2768,6 +2768,7 @@ PP(pp_goto) if (PL_op->op_flags & OPf_STACKED) { SV * const sv = POPs; + SvGETMAGIC(sv); /* This egregious kludge implements goto &subroutine */ if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) { @@ -2951,7 +2952,7 @@ PP(pp_goto) } } else { - label = SvPV_const(sv, label_len); + label = SvPV_nomg_const(sv, label_len); label_flags = SvUTF8(sv); } } diff --git a/t/op/goto.t b/t/op/goto.t index 7dafb2a..486277d 100644 --- a/t/op/goto.t +++ b/t/op/goto.t @@ -10,7 +10,7 @@ BEGIN { use warnings; use strict; -plan tests => 88; +plan tests => 89; our $TODO; my $deprecated = 0; @@ -663,3 +663,9 @@ eval { my $x = "\0"; goto $x }; like $@, qr/^Can't find label \0 at /, 'goto $x where $x begins with \0'; eval { goto "\0" }; like $@, qr/^Can't find label \0 at /, 'goto "\0"'; + +sub TIESCALAR { bless [pop] } +sub FETCH { $_[0][0] } +tie my $t, "", sub { "cluck up porridge" }; +is eval { sub { goto $t }->() }//$@, 'cluck up porridge', + 'tied arg returning sub ref'; -- 2.7.4