in 'luaD_precall', in vararg functions, complete missing parameters

only after moving them to final place (avoids checking the stack
again)
This commit is contained in:
Roberto Ierusalimschy
2015-11-02 12:06:01 -02:00
parent 332a06bbd1
commit c5363a1b58
2 changed files with 21 additions and 25 deletions

18
lvm.c
View File

@@ -1,5 +1,5 @@
/*
** $Id: lvm.c,v 2.257 2015/10/28 14:50:09 roberto Exp roberto $
** $Id: lvm.c,v 2.258 2015/11/02 11:43:17 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -1274,23 +1274,21 @@ void luaV_execute (lua_State *L) {
vmbreak;
}
vmcase(OP_VARARG) {
int b = GETARG_B(i) - 1;
int b = GETARG_B(i) - 1; /* required results */
int j;
int n = cast_int(base - ci->func) - cl->p->numparams - 1;
if (n < 0) /* less arguments than parameters? */
n = 0; /* no vararg arguments */
if (b < 0) { /* B == 0? */
b = n; /* get all var. arguments */
Protect(luaD_checkstack(L, n));
ra = RA(i); /* previous call may change the stack */
L->top = ra + n;
}
for (j = 0; j < b; j++) {
if (j < n) {
setobjs2s(L, ra + j, base - n + j);
}
else {
setnilvalue(ra + j);
}
}
for (j = 0; j < b && j < n; j++)
setobjs2s(L, ra + j, base - n + j);
for (; j < b; j++) /* complete required results with nil */
setnilvalue(ra + j);
vmbreak;
}
vmcase(OP_EXTRAARG) {