summaryrefslogtreecommitdiff
path: root/pp_ctl.c
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-09-16 18:54:57 -0700
committerFather Chrysostomos <sprout@cpan.org>2011-09-16 18:54:57 -0700
commit309aab3af38b00c733d3e986808e79b53ffc4bab (patch)
treee526353108ba6308e868741dd3553ad52b8c4bf0 /pp_ctl.c
parentc22c99bc35171a7072ba6278b8a0fdbbaa86236a (diff)
downloadperl-309aab3af38b00c733d3e986808e79b53ffc4bab.tar.gz
Make goto &CORE::sub use the right lexical scope
Since goto &foo is supposed to replace the current sub call, as though foo had been called instead, logically foo should see the same lexical hints that would have been seen if it had been called to begin with. Regular Perl subs begin with nextstate ops, so they have their own lexical scopes, but CORE:: subs see the caller’s PL_curcop. They lack a nextstate precisely so that they run in the caller’s scope, just as though a built-in function had been called. For Perl subs (as opposed to XSUBs), goto-&sub was not reset- ting PL_curcop to the caller’s value, but leaving as it was, so goto &CORE::sub would cause the CORE sub to run with the lexical hints of the subroutine in replaced, instead of that sub’s caller. This was never a problem until CORE subs came along, as they look like Perl subs to the internals (they have an op tree and are flagged as such), but comprise a sequence of ops that can never result from com- piling Perl source code. The simple one-line fix is to set PL_curcop in pp_goto for Perl subs as well as XSUBs. (For XSUBs it is implied by POPBLOCK.)
Diffstat (limited to 'pp_ctl.c')
-rw-r--r--pp_ctl.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/pp_ctl.c b/pp_ctl.c
index e8907b6751..603d0a5782 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -2908,6 +2908,7 @@ PP(pp_goto)
}
cx->blk_sub.cv = cv;
cx->blk_sub.olddepth = CvDEPTH(cv);
+ PL_curcop = cx->blk_oldcop;
CvDEPTH(cv)++;
if (CvDEPTH(cv) < 2)