Browse Source

wrong message error in some cases involving closures

Roberto Ierusalimschy 19 years ago
parent
commit
ca7e5b5cb6
2 changed files with 49 additions and 4 deletions
  1. 43 0
      bugs
  2. 6 4
      ldebug.c

+ 43 - 0
bugs

@@ -1052,3 +1052,46 @@ patch = [[
 ]],
 
 }
+
+
+Bug{
+what = [[wrong message error in some cases involving closures]],
+
+report = [[Shmuel Zeigerman, on 07/2006]],
+
+since = "Lua 5.1",
+
+example = [[
+local Var
+local function main()
+  NoSuchName (function() Var=0 end)
+end
+main()
+--> lua5.1: temp:3: attempt to call upvalue 'Var' (a nil value)
+]],
+
+patch = [[
+*ldebug.c:
+@@ -435,14 +435,16 @@
+         break;
+       }
+       case OP_CLOSURE: {
+-        int nup;
++        int nup, j;
+         check(b < pt->sizep);
+         nup = pt->p[b]->nups;
+         check(pc + nup < pt->sizecode);
+-        for (; nup>0; nup--) {
+-          OpCode op1 = GET_OPCODE(pt->code[pc+nup]);
++        for (j = 1; j <= nup; j++) {
++          OpCode op1 = GET_OPCODE(pt->code[pc + j]);
+           check(op1 == OP_GETUPVAL || op1 == OP_MOVE);
+         }
++        if (reg != NO_REG)  /* tracing? */
++          pc += nup;  /* do not 'execute' these pseudo-instructions */
+         break;
+       }
+       case OP_VARARG: {
+]],
+
+}

+ 6 - 4
ldebug.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldebug.c,v 2.29 2005/12/22 16:19:56 roberto Exp roberto $
+** $Id: ldebug.c,v 2.30 2006/07/11 15:53:29 roberto Exp roberto $
 ** Debug Interface
 ** See Copyright Notice in lua.h
 */
@@ -435,14 +435,16 @@ static Instruction symbexec (const Proto *pt, int lastpc, int reg) {
         break;
       }
       case OP_CLOSURE: {
-        int nup;
+        int nup, j;
         check(b < pt->sizep);
         nup = pt->p[b]->nups;
         check(pc + nup < pt->sizecode);
-        for (; nup>0; nup--) {
-          OpCode op1 = GET_OPCODE(pt->code[pc+nup]);
+        for (j = 1; j <= nup; j++) {
+          OpCode op1 = GET_OPCODE(pt->code[pc + j]);
           check(op1 == OP_GETUPVAL || op1 == OP_MOVE);
         }
+        if (reg != NO_REG)  /* tracing? */
+          pc += nup;  /* do not 'execute' these pseudo-instructions */
         break;
       }
       case OP_VARARG: {