lua-users home
lua-l archive

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


> > Here is another (much simpler) test case, in pure Lua
> > (that shows BTW that luaL_argerror is not the one to blame).
> 
> The problem is with the symbolic executor (symbexec, in ldebug.c). When
> creating a closure, Lua (re)uses the opcode OP_GETUPVAL as a way to
> tell that the new function has, as upvalue, an upvalue from the enclosing
> function (Var, in your example); [...]
> But 'symbexec' handles the OP_GETUPVAL as a real instruction,
> and therefore reports that the value at register 0 (the one being called),
> came from that upvalue.

I hope the next patch solves the bug:

ldebug.c: function symbexec:

       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;
       }

-- Roberto