|
|
8050c84 |
diff -up lua-5.4.3/lua-5.4.3-tests/cstack.lua.bug7 lua-5.4.3/lua-5.4.3-tests/cstack.lua
|
|
|
8050c84 |
--- lua-5.4.3/lua-5.4.3-tests/cstack.lua.bug7 2022-01-24 11:29:00.412334975 -0500
|
|
|
8050c84 |
+++ lua-5.4.3/lua-5.4.3-tests/cstack.lua 2022-01-24 11:32:08.101405924 -0500
|
|
|
8050c84 |
@@ -103,6 +103,20 @@ do
|
|
|
8050c84 |
end
|
|
|
8050c84 |
|
|
|
8050c84 |
|
|
|
8050c84 |
+do -- bug in 5.4.2
|
|
|
8050c84 |
+ print("nesting coroutines running after recoverable errors")
|
|
|
8050c84 |
+ local count = 0
|
|
|
8050c84 |
+ local function foo()
|
|
|
8050c84 |
+ count = count + 1
|
|
|
8050c84 |
+ pcall(1) -- create an error
|
|
|
8050c84 |
+ -- running now inside 'precover' ("protected recover")
|
|
|
8050c84 |
+ coroutine.wrap(foo)() -- call another coroutine
|
|
|
8050c84 |
+ end
|
|
|
8050c84 |
+ checkerror("C stack overflow", foo)
|
|
|
8050c84 |
+ print("final count: ", count)
|
|
|
8050c84 |
+end
|
|
|
8050c84 |
+
|
|
|
8050c84 |
+
|
|
|
8050c84 |
if T then
|
|
|
8050c84 |
print("testing stack recovery")
|
|
|
8050c84 |
local N = 0 -- trace number of calls
|
|
|
8050c84 |
diff -up lua-5.4.3/src/ldo.c.bug7 lua-5.4.3/src/ldo.c
|
|
|
8050c84 |
--- lua-5.4.3/src/ldo.c.bug7 2022-01-24 11:27:41.226883145 -0500
|
|
|
8050c84 |
+++ lua-5.4.3/src/ldo.c 2022-01-24 11:28:45.374249175 -0500
|
|
|
8050c84 |
@@ -728,11 +728,10 @@ static void resume (lua_State *L, void *
|
|
|
8050c84 |
StkId firstArg = L->top - n; /* first argument */
|
|
|
8050c84 |
CallInfo *ci = L->ci;
|
|
|
8050c84 |
if (L->status == LUA_OK) /* starting a coroutine? */
|
|
|
8050c84 |
- ccall(L, firstArg - 1, LUA_MULTRET, 1); /* just call its body */
|
|
|
8050c84 |
+ ccall(L, firstArg - 1, LUA_MULTRET, 0); /* just call its body */
|
|
|
8050c84 |
else { /* resuming from previous yield */
|
|
|
8050c84 |
lua_assert(L->status == LUA_YIELD);
|
|
|
8050c84 |
L->status = LUA_OK; /* mark that it is running (again) */
|
|
|
8050c84 |
- luaE_incCstack(L); /* control the C stack */
|
|
|
8050c84 |
if (isLua(ci)) { /* yielded inside a hook? */
|
|
|
8050c84 |
L->top = firstArg; /* discard arguments */
|
|
|
8050c84 |
luaV_execute(L, ci); /* just continue running Lua code */
|
|
|
8050c84 |
@@ -783,6 +782,9 @@ LUA_API int lua_resume (lua_State *L, lu
|
|
|
8050c84 |
else if (L->status != LUA_YIELD) /* ended with errors? */
|
|
|
8050c84 |
return resume_error(L, "cannot resume dead coroutine", nargs);
|
|
|
8050c84 |
L->nCcalls = (from) ? getCcalls(from) : 0;
|
|
|
8050c84 |
+ if (getCcalls(L) >= LUAI_MAXCCALLS)
|
|
|
8050c84 |
+ return resume_error(L, "C stack overflow", nargs);
|
|
|
8050c84 |
+ L->nCcalls++;
|
|
|
8050c84 |
luai_userstateresume(L, nargs);
|
|
|
8050c84 |
api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs);
|
|
|
8050c84 |
status = luaD_rawrunprotected(L, resume, &nargs);
|