develooper Front page | perl.perl5.porters | Postings from March 2001

Re: [ID 20010309.004] my-variables lose values while goto'ing within a for(;;)-loop

Thread Next
From:
Robin Houston
Date:
March 9, 2001 23:50
Subject:
Re: [ID 20010309.004] my-variables lose values while goto'ing within a for(;;)-loop
Message ID:
20010310021431.A8800@puffinry.freeserve.co.uk
Wow! This is a venerable bug, dating at least back to 5.00404.

When a for(;;) is compiled, there's no nextstate immediately
before the enterloop, and so when pp_goto does this:

            case CXt_LOOP:
                gotoprobe = cx->blk_oldcop->op_sibling;
                break;

gotoprobe ends up pointing into a dead end.

That means that the label doesn't get found until the
next context up is searched; and so the loop context is
left and re-entered when the goto is executed.

I'm not sure whether it is the best fix, but the patch below
seems to solve the problem (and still passes all tests).

[The alternative approach, I suppose, would be to say that
pp_goto is making unreasonable assumptions]

You'll have to make run_byacc of course: perly_c.diff will
still apply but with fuzz of one line in the final hunk.

 .robin.

--- perly.y.orig        Fri Mar  9 23:24:30 2001
+++ perly.y     Sat Mar 10 00:19:03 2001
@@ -249,9 +249,10 @@
                        /* basically fake up an initialize-while lineseq */
                        { OP *forop = append_elem(OP_LINESEQ,
                                        scalar($5),
-                                       newWHILEOP(0, 1, (LOOP*)Nullop,
-                                                  $2, scalar($7),
-                                                  $11, scalar($9)));
+                                       newSTATEOP(0, Nullch,
+                                           newWHILEOP(0, 1, (LOOP*)Nullop,
+                                               $2, scalar($7),
+                                               $11, scalar($9))));
                          PL_copline = $2;
                          $$ = block_end($4, newSTATEOP(0, $1, forop)); }
        |       label block cont  /* a block is a loop that happens once */


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About