From 91673a8ec0ae55e188a790bd2dfdc99246adf20e Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 18 Aug 2021 12:05:06 -0300 Subject: 'luaD_tryfuncTM' checks stack space by itself --- lvm.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lvm.c') diff --git a/lvm.c b/lvm.c index df1dec83..29a211c6 100644 --- a/lvm.c +++ b/lvm.c @@ -1657,9 +1657,8 @@ void luaV_execute (lua_State *L, CallInfo *ci) { lua_assert(base == ci->func + 1); } while (!ttisfunction(s2v(ra))) { /* not a function? */ - luaD_tryfuncTM(L, ra); /* try '__call' metamethod */ + ra = luaD_tryfuncTM(L, ra); /* try '__call' metamethod */ b++; /* there is now one extra argument */ - checkstackGCp(L, 1, ra); } if (!ttisLclosure(s2v(ra))) { /* C function? */ luaD_precall(L, ra, LUA_MULTRET); /* call it */ @@ -1670,9 +1669,11 @@ void luaV_execute (lua_State *L, CallInfo *ci) { updatetrap(ci); /* 'luaD_poscall' can change hooks */ goto ret; /* caller returns after the tail call */ } - ci->func -= delta; /* restore 'func' (if vararg) */ - luaD_pretailcall(L, ci, ra, b); /* prepare call frame */ - goto startfunc; /* execute the callee */ + else { /* Lua function */ + ci->func -= delta; /* restore 'func' (if vararg) */ + luaD_pretailcall(L, ci, ra, b); /* prepare call frame */ + goto startfunc; /* execute the callee */ + } } vmcase(OP_RETURN) { int n = GETARG_B(i) - 1; /* number of results */ -- cgit v1.2.3-55-g6feb