aboutsummaryrefslogtreecommitdiff
path: root/ltm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-01-28 11:39:52 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-01-28 11:39:52 -0200
commit89110986d7a9e81960261ae682780d5fd06dc4ac (patch)
tree5fe3d0039b2152223b58adc33a4b6c916fc853d8 /ltm.c
parent53979dfe0dbd7eba767ff37b1148d1e4dc9f8294 (diff)
downloadlua-89110986d7a9e81960261ae682780d5fd06dc4ac.tar.gz
lua-89110986d7a9e81960261ae682780d5fd06dc4ac.tar.bz2
lua-89110986d7a9e81960261ae682780d5fd06dc4ac.zip
bug in tailcall of vararg functions
(when adjusting missing parameters)
Diffstat (limited to 'ltm.c')
-rw-r--r--ltm.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/ltm.c b/ltm.c
index 8108abb2..64622f20 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 2.56 2017/12/28 15:42:57 roberto Exp roberto $ 2** $Id: ltm.c,v 2.57 2018/01/28 12:08:04 roberto Exp roberto $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -216,21 +216,20 @@ int luaT_callorderiTM (lua_State *L, const TValue *p1, int v2,
216} 216}
217 217
218 218
219void luaT_adjustvarargs (lua_State *L, Proto *p, int actual) { 219void luaT_adjustvarargs (lua_State *L, int nfixparams, int actual) {
220 int i; 220 int i;
221 Table *vtab; 221 Table *vtab;
222 TValue nname; 222 TValue nname;
223 int nfixparams = p->numparams; /* number of fixed parameters */ 223 int nextra = actual - nfixparams; /* number of extra arguments */
224 actual -= nfixparams; /* number of extra arguments */
225 vtab = luaH_new(L); /* create vararg table */ 224 vtab = luaH_new(L); /* create vararg table */
226 sethvalue2s(L, L->top, vtab); /* anchor it for resizing */ 225 sethvalue2s(L, L->top, vtab); /* anchor it for resizing */
227 L->top++; /* space ensured by caller */ 226 L->top++; /* space ensured by caller */
228 luaH_resize(L, vtab, actual, 1); 227 luaH_resize(L, vtab, nextra, 1);
229 for (i = 0; i < actual; i++) /* put extra arguments into vararg table */ 228 for (i = 0; i < nextra; i++) /* put extra arguments into vararg table */
230 setobj2n(L, &vtab->array[i], s2v(L->top - actual + i - 1)); 229 setobj2n(L, &vtab->array[i], s2v(L->top - nextra + i - 1));
231 setsvalue(L, &nname, G(L)->nfield); /* get field 'n' */ 230 setsvalue(L, &nname, G(L)->nfield); /* get field 'n' */
232 setivalue(luaH_set(L, vtab, &nname), actual); /* store counter there */ 231 setivalue(luaH_set(L, vtab, &nname), nextra); /* store counter there */
233 L->top -= actual; /* remove extra elements from the stack */ 232 L->top -= nextra; /* remove extra elements from the stack */
234 sethvalue2s(L, L->top - 1, vtab); /* move table to new top */ 233 sethvalue2s(L, L->top - 1, vtab); /* move table to new top */
235 luaC_checkGC(L); 234 luaC_checkGC(L);
236} 235}