lua

A copy of the Lua development repository
Log | Files | Refs | README

commit 9a38c08011a2d8a4d291c9267efbdd44e7beb7c4
parent be87789a6c71b95b9edc69fce16e1ef4eca2d666
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Tue, 11 Nov 2014 15:13:14 -0200

no need to ensure any stack space for panic function + some changes
in 'tryfuncTM' (small simplification)

Diffstat:
Mldo.c | 28++++++++++++----------------
1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/ldo.c b/ldo.c @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 2.133 2014/11/02 19:33:33 roberto Exp roberto $ +** $Id: ldo.c,v 2.134 2014/11/10 17:42:04 roberto Exp roberto $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -123,9 +123,9 @@ l_noret luaD_throw (lua_State *L, int errcode) { if (g->panic) { /* panic function? */ seterrorobj(L, errcode, L->top); /* assume EXTRA_STACK */ if (L->ci->top < L->top) - L->ci->top = L->top + 2; + L->ci->top = L->top; /* pushing msg. can break this invariant */ lua_unlock(L); - g->panic(L); /* call it (last chance to jump out) */ + g->panic(L); /* call panic function (last chance to jump out) */ } abort(); } @@ -289,24 +289,18 @@ static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { /* ** Check whether __call metafield of 'func' is a function. If so, put ** it in stack below original 'func' so that 'luaD_precall' can call -** it. Raise an error if __call metafield is not a function. (The -** check 'luaD_checkstack' avoids problems of errors in tag methods, -** because both tag methods and error messages may need EXTRA_STACK.) +** it. Raise an error if __call metafield is not a function. */ -static StkId tryfuncTM (lua_State *L, StkId func) { +static void tryfuncTM (lua_State *L, StkId func) { const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL); StkId p; - ptrdiff_t funcr = savestack(L, func); - if (!ttisfunction(tm)) { - luaD_checkstack(L, 1); + if (!ttisfunction(tm)) luaG_typeerror(L, func, "call"); - } /* Open a hole inside the stack at 'func' */ - for (p = L->top; p > func; p--) setobjs2s(L, p, p-1); - incr_top(L); - func = restorestack(L, funcr); /* previous call may change stack */ + for (p = L->top; p > func; p--) + setobjs2s(L, p, p-1); + L->top++; /* slot ensured by caller */ setobj2s(L, func, tm); /* tag method is the new function to be called */ - return func; } @@ -376,7 +370,9 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { return 0; } default: { /* not a function */ - func = tryfuncTM(L, func); /* retry with 'function' tag method */ + luaD_checkstack(L, 1); /* ensure space for metamethod */ + func = restorestack(L, funcr); /* previous call may change stack */ + tryfuncTM(L, func); /* try to get '__call' metamethod */ return luaD_precall(L, func, nresults); /* now it must be a function */ } }