diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-11-02 16:48:49 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-11-02 16:48:49 -0200 |
commit | e61ee8a036e83667de9c4378e70a278876c81135 (patch) | |
tree | 011ae3672032c0297da48e36b97977f1bb647c9d | |
parent | ff1289a361eb2b077d0df83eaed21647444541ef (diff) | |
download | lua-e61ee8a036e83667de9c4378e70a278876c81135.tar.gz lua-e61ee8a036e83667de9c4378e70a278876c81135.tar.bz2 lua-e61ee8a036e83667de9c4378e70a278876c81135.zip |
in 'luaD_call', use two functions instead of one with fixed boolean
argument + stack error handling in 'luaD_call' moved to a separated
function
-rw-r--r-- | ldo.c | 39 |
1 files changed, 29 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 2.146 2015/11/02 14:06:01 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.147 2015/11/02 16:09:30 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 | */ |
@@ -434,27 +434,46 @@ int luaD_poscall (lua_State *L, StkId firstResult, int nres) { | |||
434 | 434 | ||
435 | 435 | ||
436 | /* | 436 | /* |
437 | ** Check appropriate error for stack overflow ("regular" overflow or | ||
438 | ** overflow while handling stack overflow). If 'nCalls' is larger than | ||
439 | ** LUAI_MAXCCALLS (which means it is handling a "regular" overflow) but | ||
440 | ** smaller than 9/8 of LUAI_MAXCCALLS, does not report an error (to | ||
441 | ** allow overflow handling to work) | ||
442 | */ | ||
443 | static void stackerror (lua_State *L) { | ||
444 | if (L->nCcalls == LUAI_MAXCCALLS) | ||
445 | luaG_runerror(L, "C stack overflow"); | ||
446 | else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3))) | ||
447 | luaD_throw(L, LUA_ERRERR); /* error while handing stack error */ | ||
448 | } | ||
449 | |||
450 | |||
451 | /* | ||
437 | ** Call a function (C or Lua). The function to be called is at *func. | 452 | ** Call a function (C or Lua). The function to be called is at *func. |
438 | ** The arguments are on the stack, right after the function. | 453 | ** The arguments are on the stack, right after the function. |
439 | ** When returns, all the results are on the stack, starting at the original | 454 | ** When returns, all the results are on the stack, starting at the original |
440 | ** function position. | 455 | ** function position. |
441 | */ | 456 | */ |
442 | void luaD_call (lua_State *L, StkId func, int nResults, int allowyield) { | 457 | void luaD_call (lua_State *L, StkId func, int nResults) { |
443 | if (++L->nCcalls >= LUAI_MAXCCALLS) { | 458 | if (++L->nCcalls >= LUAI_MAXCCALLS) |
444 | if (L->nCcalls == LUAI_MAXCCALLS) | 459 | stackerror(L); |
445 | luaG_runerror(L, "C stack overflow"); | ||
446 | else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3))) | ||
447 | luaD_throw(L, LUA_ERRERR); /* error while handing stack error */ | ||
448 | } | ||
449 | if (!allowyield) L->nny++; | ||
450 | if (!luaD_precall(L, func, nResults)) /* is a Lua function? */ | 460 | if (!luaD_precall(L, func, nResults)) /* is a Lua function? */ |
451 | luaV_execute(L); /* call it */ | 461 | luaV_execute(L); /* call it */ |
452 | if (!allowyield) L->nny--; | ||
453 | L->nCcalls--; | 462 | L->nCcalls--; |
454 | } | 463 | } |
455 | 464 | ||
456 | 465 | ||
457 | /* | 466 | /* |
467 | ** Similar to 'luaD_call', but does not allow yields during the call | ||
468 | */ | ||
469 | void luaD_callnoyield (lua_State *L, StkId func, int nResults) { | ||
470 | L->nny++; | ||
471 | luaD_call(L, func, nResults); | ||
472 | L->nny--; | ||
473 | } | ||
474 | |||
475 | |||
476 | /* | ||
458 | ** Completes the execution of an interrupted C function, calling its | 477 | ** Completes the execution of an interrupted C function, calling its |
459 | ** continuation function. | 478 | ** continuation function. |
460 | */ | 479 | */ |