From: Robin Houston Date: Wed, 14 Mar 2001 04:16:10 +0000 (+0000) Subject: PATCH: make goto work in nested eval "" X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a4f3a277dab3a9e285418160103305f0e5819cf9;p=p5sagit%2Fp5-mst-13.2.git PATCH: make goto work in nested eval "" Message-ID: <20010314041610.A16307@puffinry.freeserve.co.uk> p4raw-id: //depot/perl@9147 --- diff --git a/pp_ctl.c b/pp_ctl.c index 99e3ff4..93b89b1 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -2455,6 +2455,7 @@ PP(pp_goto) if (label && *label) { OP *gotoprobe = 0; bool leaving_eval = FALSE; + PERL_CONTEXT *last_eval_cx = 0; /* find label */ @@ -2466,7 +2467,10 @@ PP(pp_goto) case CXt_EVAL: leaving_eval = TRUE; if (CxREALEVAL(cx)) { - gotoprobe = PL_eval_root; /* XXX not good for nested eval */ + gotoprobe = (last_eval_cx ? + last_eval_cx->blk_eval.old_eval_root : + PL_eval_root); + last_eval_cx = cx; break; } /* else fall through */ diff --git a/t/op/goto.t b/t/op/goto.t index 6f9e349..b2e5b2c 100755 --- a/t/op/goto.t +++ b/t/op/goto.t @@ -2,7 +2,7 @@ # "This IS structured code. It's just randomly structured." -print "1..21\n"; +print "1..22\n"; while ($?) { $foo = 1; @@ -129,6 +129,21 @@ eval q{ print ($ok&&!$@ ? "ok 21\n" : "not ok 21\n"); +# Test that goto works in nested eval-string +$ok = 0; +{eval q{ + eval q{ + goto LABEL22; + }; + $ok = 0; + last; + + LABEL22: $ok = 1; +}; +$ok = 0 if $@; +} +print ($ok ? "ok 22\n" : "not ok 22\n"); + exit; bypass: