mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Add luaD_checkCstack and update luaD_call/luau_callTM
This commit is contained in:
parent
70ff6b4347
commit
18fd25453c
3 changed files with 12 additions and 7 deletions
|
@ -213,6 +213,14 @@ CallInfo* luaD_growCI(lua_State* L)
|
||||||
return ++L->ci;
|
return ++L->ci;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void luaD_checkCstack(lua_State *L)
|
||||||
|
{
|
||||||
|
if (L->nCcalls == LUAI_MAXCCALLS)
|
||||||
|
luaG_runerror(L, "C stack overflow");
|
||||||
|
else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS >> 3)))
|
||||||
|
luaD_throw(L, LUA_ERRERR); /* error while handling stack error */
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Call a function (C or Lua). The function to be called is at *func.
|
** Call a function (C or Lua). The function to be called is at *func.
|
||||||
** The arguments are on the stack, right after the function.
|
** The arguments are on the stack, right after the function.
|
||||||
|
@ -222,12 +230,8 @@ CallInfo* luaD_growCI(lua_State* L)
|
||||||
void luaD_call(lua_State* L, StkId func, int nResults)
|
void luaD_call(lua_State* L, StkId func, int nResults)
|
||||||
{
|
{
|
||||||
if (++L->nCcalls >= LUAI_MAXCCALLS)
|
if (++L->nCcalls >= LUAI_MAXCCALLS)
|
||||||
{
|
luaD_checkCstack(L);
|
||||||
if (L->nCcalls == LUAI_MAXCCALLS)
|
|
||||||
luaG_runerror(L, "C stack overflow");
|
|
||||||
else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS >> 3)))
|
|
||||||
luaD_throw(L, LUA_ERRERR); /* error while handing stack error */
|
|
||||||
}
|
|
||||||
if (luau_precall(L, func, nResults) == PCRLUA)
|
if (luau_precall(L, func, nResults) == PCRLUA)
|
||||||
{ /* is a Lua function? */
|
{ /* is a Lua function? */
|
||||||
L->ci->flags |= LUA_CALLINFO_RETURN; /* luau_execute will stop after returning from the stack frame */
|
L->ci->flags |= LUA_CALLINFO_RETURN; /* luau_execute will stop after returning from the stack frame */
|
||||||
|
|
|
@ -49,6 +49,7 @@ LUAI_FUNC int luaD_pcall(lua_State* L, Pfunc func, void* u, ptrdiff_t oldtop, pt
|
||||||
LUAI_FUNC void luaD_reallocCI(lua_State* L, int newsize);
|
LUAI_FUNC void luaD_reallocCI(lua_State* L, int newsize);
|
||||||
LUAI_FUNC void luaD_reallocstack(lua_State* L, int newsize);
|
LUAI_FUNC void luaD_reallocstack(lua_State* L, int newsize);
|
||||||
LUAI_FUNC void luaD_growstack(lua_State* L, int n);
|
LUAI_FUNC void luaD_growstack(lua_State* L, int n);
|
||||||
|
LUAI_FUNC void luaD_checkCstack(lua_State* L);
|
||||||
|
|
||||||
LUAI_FUNC l_noret luaD_throw(lua_State* L, int errcode);
|
LUAI_FUNC l_noret luaD_throw(lua_State* L, int errcode);
|
||||||
LUAI_FUNC int luaD_rawrunprotected(lua_State* L, Pfunc f, void* ud);
|
LUAI_FUNC int luaD_rawrunprotected(lua_State* L, Pfunc f, void* ud);
|
||||||
|
|
|
@ -181,7 +181,7 @@ LUAU_NOINLINE static void luau_callTM(lua_State* L, int nparams, int res)
|
||||||
++L->nCcalls;
|
++L->nCcalls;
|
||||||
|
|
||||||
if (L->nCcalls >= LUAI_MAXCCALLS)
|
if (L->nCcalls >= LUAI_MAXCCALLS)
|
||||||
luaG_runerror(L, "C stack overflow");
|
luaD_checkCstack(L);
|
||||||
|
|
||||||
luaD_checkstack(L, LUA_MINSTACK);
|
luaD_checkstack(L, LUA_MINSTACK);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue