This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PATCH: make goto work in nested eval ""
authorRobin Houston <robin@cpan.org>
Wed, 14 Mar 2001 04:16:10 +0000 (04:16 +0000)
committerJarkko Hietaniemi <jhi@iki.fi>
Wed, 14 Mar 2001 04:59:54 +0000 (04:59 +0000)
Message-ID: <20010314041610.A16307@puffinry.freeserve.co.uk>

p4raw-id: //depot/perl@9147

pp_ctl.c
t/op/goto.t

index 99e3ff4..93b89b1 100644 (file)
--- 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 */
index 6f9e349..b2e5b2c 100755 (executable)
@@ -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: