diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-12-28 16:34:07 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-12-28 16:34:07 -0300 |
commit | 6188f3a654c0380db08eb40a5465ce8e71c784f5 (patch) | |
tree | 1a94cd5c0d815a2c23e3ebb967b3019c55c7a128 /ldo.c | |
parent | 7af27ef59da4051914d93d8b63efac663b64765a (diff) | |
download | lua-6188f3a654c0380db08eb40a5465ce8e71c784f5.tar.gz lua-6188f3a654c0380db08eb40a5465ce8e71c784f5.tar.bz2 lua-6188f3a654c0380db08eb40a5465ce8e71c784f5.zip |
Reset thread before panicking
Before panicking, it is simpler to reset the thread instead of closing
its variables and adjust the top manually.
Diffstat (limited to '')
-rw-r--r-- | ldo.c | 6 |
1 files changed, 1 insertions, 5 deletions
@@ -119,17 +119,13 @@ l_noret luaD_throw (lua_State *L, int errcode) { | |||
119 | } | 119 | } |
120 | else { /* thread has no error handler */ | 120 | else { /* thread has no error handler */ |
121 | global_State *g = G(L); | 121 | global_State *g = G(L); |
122 | errcode = luaD_closeprotected(L, 0, errcode); /* close all upvalues */ | 122 | errcode = luaE_resetthread(L, errcode); /* close all upvalues */ |
123 | L->status = cast_byte(errcode); /* mark it as dead */ | ||
124 | if (g->mainthread->errorJmp) { /* main thread has a handler? */ | 123 | if (g->mainthread->errorJmp) { /* main thread has a handler? */ |
125 | setobjs2s(L, g->mainthread->top++, L->top - 1); /* copy error obj. */ | 124 | setobjs2s(L, g->mainthread->top++, L->top - 1); /* copy error obj. */ |
126 | luaD_throw(g->mainthread, errcode); /* re-throw in main thread */ | 125 | luaD_throw(g->mainthread, errcode); /* re-throw in main thread */ |
127 | } | 126 | } |
128 | else { /* no handler at all; abort */ | 127 | else { /* no handler at all; abort */ |
129 | if (g->panic) { /* panic function? */ | 128 | if (g->panic) { /* panic function? */ |
130 | luaD_seterrorobj(L, errcode, L->top); /* assume EXTRA_STACK */ | ||
131 | if (L->ci->top < L->top) | ||
132 | L->ci->top = L->top; /* pushing msg. can break this invariant */ | ||
133 | lua_unlock(L); | 129 | lua_unlock(L); |
134 | g->panic(L); /* call panic function (last chance to jump out) */ | 130 | g->panic(L); /* call panic function (last chance to jump out) */ |
135 | } | 131 | } |