diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-11-11 15:13:39 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-11-11 15:13:39 -0200 |
commit | 9a38c08011a2d8a4d291c9267efbdd44e7beb7c4 (patch) | |
tree | a7b8359ba62e66da8055d7a709e864036d8e9410 | |
parent | be87789a6c71b95b9edc69fce16e1ef4eca2d666 (diff) | |
download | lua-9a38c08011a2d8a4d291c9267efbdd44e7beb7c4.tar.gz lua-9a38c08011a2d8a4d291c9267efbdd44e7beb7c4.tar.bz2 lua-9a38c08011a2d8a4d291c9267efbdd44e7beb7c4.zip |
no need to ensure any stack space for panic function + some changes
in 'tryfuncTM' (small simplification)
-rw-r--r-- | ldo.c | 28 |
1 files changed, 12 insertions, 16 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 2.133 2014/11/02 19:33:33 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.134 2014/11/10 17:42:04 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -123,9 +123,9 @@ l_noret luaD_throw (lua_State *L, int errcode) { | |||
123 | if (g->panic) { /* panic function? */ | 123 | if (g->panic) { /* panic function? */ |
124 | seterrorobj(L, errcode, L->top); /* assume EXTRA_STACK */ | 124 | seterrorobj(L, errcode, L->top); /* assume EXTRA_STACK */ |
125 | if (L->ci->top < L->top) | 125 | if (L->ci->top < L->top) |
126 | L->ci->top = L->top + 2; | 126 | L->ci->top = L->top; /* pushing msg. can break this invariant */ |
127 | lua_unlock(L); | 127 | lua_unlock(L); |
128 | g->panic(L); /* call it (last chance to jump out) */ | 128 | g->panic(L); /* call panic function (last chance to jump out) */ |
129 | } | 129 | } |
130 | abort(); | 130 | abort(); |
131 | } | 131 | } |
@@ -289,24 +289,18 @@ static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { | |||
289 | /* | 289 | /* |
290 | ** Check whether __call metafield of 'func' is a function. If so, put | 290 | ** Check whether __call metafield of 'func' is a function. If so, put |
291 | ** it in stack below original 'func' so that 'luaD_precall' can call | 291 | ** it in stack below original 'func' so that 'luaD_precall' can call |
292 | ** it. Raise an error if __call metafield is not a function. (The | 292 | ** it. Raise an error if __call metafield is not a function. |
293 | ** check 'luaD_checkstack' avoids problems of errors in tag methods, | ||
294 | ** because both tag methods and error messages may need EXTRA_STACK.) | ||
295 | */ | 293 | */ |
296 | static StkId tryfuncTM (lua_State *L, StkId func) { | 294 | static void tryfuncTM (lua_State *L, StkId func) { |
297 | const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL); | 295 | const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL); |
298 | StkId p; | 296 | StkId p; |
299 | ptrdiff_t funcr = savestack(L, func); | 297 | if (!ttisfunction(tm)) |
300 | if (!ttisfunction(tm)) { | ||
301 | luaD_checkstack(L, 1); | ||
302 | luaG_typeerror(L, func, "call"); | 298 | luaG_typeerror(L, func, "call"); |
303 | } | ||
304 | /* Open a hole inside the stack at 'func' */ | 299 | /* Open a hole inside the stack at 'func' */ |
305 | for (p = L->top; p > func; p--) setobjs2s(L, p, p-1); | 300 | for (p = L->top; p > func; p--) |
306 | incr_top(L); | 301 | setobjs2s(L, p, p-1); |
307 | func = restorestack(L, funcr); /* previous call may change stack */ | 302 | L->top++; /* slot ensured by caller */ |
308 | setobj2s(L, func, tm); /* tag method is the new function to be called */ | 303 | setobj2s(L, func, tm); /* tag method is the new function to be called */ |
309 | return func; | ||
310 | } | 304 | } |
311 | 305 | ||
312 | 306 | ||
@@ -376,7 +370,9 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { | |||
376 | return 0; | 370 | return 0; |
377 | } | 371 | } |
378 | default: { /* not a function */ | 372 | default: { /* not a function */ |
379 | func = tryfuncTM(L, func); /* retry with 'function' tag method */ | 373 | luaD_checkstack(L, 1); /* ensure space for metamethod */ |
374 | func = restorestack(L, funcr); /* previous call may change stack */ | ||
375 | tryfuncTM(L, func); /* try to get '__call' metamethod */ | ||
380 | return luaD_precall(L, func, nresults); /* now it must be a function */ | 376 | return luaD_precall(L, func, nresults); /* now it must be a function */ |
381 | } | 377 | } |
382 | } | 378 | } |