Reset thread before panicking

Before panicking, it is simpler to reset the thread instead of closing
its variables and adjust the top manually.
This commit is contained in:
Roberto Ierusalimschy
2020-12-28 16:34:07 -03:00
parent 7af27ef59d
commit 6188f3a654
3 changed files with 15 additions and 14 deletions

6
ldo.c
View File

@@ -119,17 +119,13 @@ l_noret luaD_throw (lua_State *L, int errcode) {
}
else { /* thread has no error handler */
global_State *g = G(L);
errcode = luaD_closeprotected(L, 0, errcode); /* close all upvalues */
L->status = cast_byte(errcode); /* mark it as dead */
errcode = luaE_resetthread(L, errcode); /* close all upvalues */
if (g->mainthread->errorJmp) { /* main thread has a handler? */
setobjs2s(L, g->mainthread->top++, L->top - 1); /* copy error obj. */
luaD_throw(g->mainthread, errcode); /* re-throw in main thread */
}
else { /* no handler at all; abort */
if (g->panic) { /* panic function? */
luaD_seterrorobj(L, errcode, L->top); /* assume EXTRA_STACK */
if (L->ci->top < L->top)
L->ci->top = L->top; /* pushing msg. can break this invariant */
lua_unlock(L);
g->panic(L); /* call panic function (last chance to jump out) */
}