summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-07-13 13:51:16 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-07-13 13:51:16 -0300
commit454424690dbfc75bcca4598faedd7971ee984acc (patch)
tree686613f2ba05cae8781a28b7dfeb22d63c856836
parent3b2444f7eeacee3f236ea979e546fc61eff33483 (diff)
downloadlua-github-454424690dbfc75bcca4598faedd7971ee984acc.tar.gz
Fixed bug: Computation of stack limit
-rw-r--r--ldo.c2
-rw-r--r--testes/cstack.lua16
2 files changed, 17 insertions, 1 deletions
diff --git a/ldo.c b/ldo.c
index c563b1d9..b39be1bd 100644
--- a/ldo.c
+++ b/ldo.c
@@ -674,7 +674,7 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs,
if (from == NULL)
L->nCcalls = CSTACKTHREAD;
else /* correct 'nCcalls' for this thread */
- L->nCcalls = getCcalls(from) + from->nci - L->nci - CSTACKCF;
+ L->nCcalls = getCcalls(from) - L->nci - CSTACKCF;
if (L->nCcalls <= CSTACKERR)
return resume_error(L, "C stack overflow", nargs);
luai_userstateresume(L, nargs);
diff --git a/testes/cstack.lua b/testes/cstack.lua
index e3e14f74..4e37b988 100644
--- a/testes/cstack.lua
+++ b/testes/cstack.lua
@@ -105,6 +105,22 @@ do print("testing stack-overflow in recursive 'gsub'")
print("\tfinal count: ", count)
end
+do -- bug in 5.4.0
+ print("testing limits in coroutines inside deep calls")
+ count = 0
+ local lim = 1000
+ local function stack (n)
+ progress()
+ if n > 0 then return stack(n - 1) + 1
+ else coroutine.wrap(function ()
+ stack(lim)
+ end)()
+ end
+ end
+
+ print(xpcall(stack, function () return "ok" end, lim))
+end
+
do print("testing changes in C-stack limit")