Browse Source

Bug: Missing error status in panic function

'luaD_throw' may call 'luaE_resetthread', which returns an error code
but clears 'L->status'; so, 'luaD_throw' should set that status again.
Roberto Ierusalimschy 6 months ago
parent
commit
f5e55be2a0
3 changed files with 8 additions and 0 deletions
  1. 1 0
      ldo.c
  2. 3 0
      ltests.c
  3. 4 0
      testes/api.lua

+ 1 - 0
ldo.c

@@ -120,6 +120,7 @@ l_noret luaD_throw (lua_State *L, int errcode) {
   else {  /* thread has no error handler */
     global_State *g = G(L);
     errcode = luaE_resetthread(L, errcode);  /* close all upvalues */
+    L->status = errcode;
     if (g->mainthread->errorJmp) {  /* main thread has a handler? */
       setobjs2s(L, g->mainthread->top.p++, L->top.p - 1);  /* copy error obj. */
       luaD_throw(g->mainthread, errcode);  /* re-throw in main thread */

+ 3 - 0
ltests.c

@@ -1655,6 +1655,9 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) {
       int level = getnum;
       luaL_traceback(L1, L1, msg, level);
     }
+    else if EQ("threadstatus") {
+      lua_pushstring(L1, statcodes[lua_status(L1)]);
+    }
     else if EQ("return") {
       int n = getnum;
       if (L1 != L) {

+ 4 - 0
testes/api.lua

@@ -399,6 +399,10 @@ do
   -- trivial error
   assert(T.checkpanic("pushstring hi; error") == "hi")
 
+ -- thread status inside panic (bug in 5.4.4)
+  assert(T.checkpanic("pushstring hi; error", "threadstatus; return 2") ==
+         "ERRRUN")
+
   -- using the stack inside panic
   assert(T.checkpanic("pushstring hi; error;",
     [[checkstack 5 XX