Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/mit/lua/dist/src lua: apply upstream bugfix for "'b...



details:   https://anonhg.NetBSD.org/src/rev/be88500dc9c7
branches:  trunk
changeset: 374299:be88500dc9c7
user:      nikita <nikita%NetBSD.org@localhost>
date:      Mon Apr 17 20:07:32 2023 +0000

description:
lua: apply upstream bugfix for "'break' may not properly close variable in a 'for' loop."

Function 'leaveblock' was generating "break" label before removing
variables from the closing block. If 'createlabel' created a 'close'
instruction (which it did when matching a goto/break that exited
the scope of an upvalue), that instruction would use the wrong level.

diffstat:

 external/mit/lua/dist/src/lparser.c |  18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)

diffs (37 lines):

diff -r 5b423defd36c -r be88500dc9c7 external/mit/lua/dist/src/lparser.c
--- a/external/mit/lua/dist/src/lparser.c       Mon Apr 17 19:54:19 2023 +0000
+++ b/external/mit/lua/dist/src/lparser.c       Mon Apr 17 20:07:32 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lparser.c,v 1.13 2023/04/17 19:17:49 nikita Exp $      */
+/*     $NetBSD: lparser.c,v 1.14 2023/04/17 20:07:32 nikita Exp $      */
 
 /*
 ** Id: lparser.c 
@@ -678,19 +678,19 @@ static void leaveblock (FuncState *fs) {
   LexState *ls = fs->ls;
   int hasclose = 0;
   int stklevel = reglevel(fs, bl->nactvar);  /* level outside the block */
-  if (bl->isloop)  /* fix pending breaks? */
+  removevars(fs, bl->nactvar);  /* remove block locals */
+  lua_assert(bl->nactvar == fs->nactvar);  /* back to level on entry */
+  if (bl->isloop)  /* has to fix pending breaks? */
     hasclose = createlabel(ls, luaS_newliteral(ls->L, "break"), 0, 0);
-  if (!hasclose && bl->previous && bl->upval)
+  if (!hasclose && bl->previous && bl->upval)  /* still need a 'close'? */
     luaK_codeABC(fs, OP_CLOSE, stklevel, 0, 0);
-  fs->bl = bl->previous;
-  removevars(fs, bl->nactvar);
-  lua_assert(bl->nactvar == fs->nactvar);
   fs->freereg = stklevel;  /* free registers */
   ls->dyd->label.n = bl->firstlabel;  /* remove local labels */
-  if (bl->previous)  /* inner block? */
-    movegotosout(fs, bl);  /* update pending gotos to outer block */
+  fs->bl = bl->previous;  /* current block now is previous one */
+  if (bl->previous)  /* was it a nested block? */
+    movegotosout(fs, bl);  /* update pending gotos to enclosing block */
   else {
-    if (bl->firstgoto < ls->dyd->gt.n)  /* pending gotos in outer block? */
+    if (bl->firstgoto < ls->dyd->gt.n)  /* still pending gotos? */
       undefgoto(ls, &ls->dyd->gt.arr[bl->firstgoto]);  /* error */
   }
 }



Home | Main Index | Thread Index | Old Index