void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need)
{
MSize n;
- if (L->stacksize > LJ_STACK_MAXEX) /* Overflow while handling overflow? */
- lj_err_throw(L, LUA_ERRERR);
+ if (L->stacksize >= LJ_STACK_MAXEX) {
+ /* 4. Throw 'error in error handling' when we are _over_ the limit. */
+ if (L->stacksize > LJ_STACK_MAXEX)
+ lj_err_throw(L, LUA_ERRERR); /* Does not invoke an error handler. */
+ /* 1. We are _at_ the limit after the last growth. */
+ if (!L->status) { /* 2. Throw 'stack overflow'. */
+ L->status = LUA_ERRRUN; /* Prevent ending here again for pushed msg. */
+ lj_err_msg(L, LJ_ERR_STKOV); /* May invoke an error handler. */
+ }
+ /* 3. Add space (over the limit) for pushed message and error handler. */
+ }
n = L->stacksize + need;
if (n > LJ_STACK_MAX) {
n += 2*LUA_MINSTACK;
n = LJ_STACK_MAX;
}
resizestack(L, n);
- if (L->stacksize >= LJ_STACK_MAXEX)
- lj_err_msg(L, LJ_ERR_STKOV);
}
void LJ_FASTCALL lj_state_growstack1(lua_State *L)