diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-11-02 12:06:01 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-11-02 12:06:01 -0200 |
commit | c5363a1b58573162ef13ba4a345bd48ad3c355d9 (patch) | |
tree | 7c4ee5559a42ce93d770aa0253f0695439a7d2e3 /lvm.c | |
parent | 332a06bbd1a8835c810e52bbf68014d6956b50b8 (diff) | |
download | lua-c5363a1b58573162ef13ba4a345bd48ad3c355d9.tar.gz lua-c5363a1b58573162ef13ba4a345bd48ad3c355d9.tar.bz2 lua-c5363a1b58573162ef13ba4a345bd48ad3c355d9.zip |
in 'luaD_precall', in vararg functions, complete missing parameters
only after moving them to final place (avoids checking the stack
again)
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 18 |
1 files changed, 8 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.257 2015/10/28 14:50:09 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.258 2015/11/02 11:43:17 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -1274,23 +1274,21 @@ void luaV_execute (lua_State *L) { | |||
1274 | vmbreak; | 1274 | vmbreak; |
1275 | } | 1275 | } |
1276 | vmcase(OP_VARARG) { | 1276 | vmcase(OP_VARARG) { |
1277 | int b = GETARG_B(i) - 1; | 1277 | int b = GETARG_B(i) - 1; /* required results */ |
1278 | int j; | 1278 | int j; |
1279 | int n = cast_int(base - ci->func) - cl->p->numparams - 1; | 1279 | int n = cast_int(base - ci->func) - cl->p->numparams - 1; |
1280 | if (n < 0) /* less arguments than parameters? */ | ||
1281 | n = 0; /* no vararg arguments */ | ||
1280 | if (b < 0) { /* B == 0? */ | 1282 | if (b < 0) { /* B == 0? */ |
1281 | b = n; /* get all var. arguments */ | 1283 | b = n; /* get all var. arguments */ |
1282 | Protect(luaD_checkstack(L, n)); | 1284 | Protect(luaD_checkstack(L, n)); |
1283 | ra = RA(i); /* previous call may change the stack */ | 1285 | ra = RA(i); /* previous call may change the stack */ |
1284 | L->top = ra + n; | 1286 | L->top = ra + n; |
1285 | } | 1287 | } |
1286 | for (j = 0; j < b; j++) { | 1288 | for (j = 0; j < b && j < n; j++) |
1287 | if (j < n) { | 1289 | setobjs2s(L, ra + j, base - n + j); |
1288 | setobjs2s(L, ra + j, base - n + j); | 1290 | for (; j < b; j++) /* complete required results with nil */ |
1289 | } | 1291 | setnilvalue(ra + j); |
1290 | else { | ||
1291 | setnilvalue(ra + j); | ||
1292 | } | ||
1293 | } | ||
1294 | vmbreak; | 1292 | vmbreak; |
1295 | } | 1293 | } |
1296 | vmcase(OP_EXTRAARG) { | 1294 | vmcase(OP_EXTRAARG) { |