Skip to content

Commit e1d8770

Browse files
committed
Fixed bug: wrong stack limit when entering a coroutine
When entering a coroutine, the computation of nCcalls added 'from->nci' to correct for preallocated CallInfos, but 'nci' includes also the Callinfos already used.
1 parent 0f1cd0e commit e1d8770

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

ldo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs,
674674
if (from == NULL)
675675
L->nCcalls = CSTACKTHREAD;
676676
else /* correct 'nCcalls' for this thread */
677-
L->nCcalls = getCcalls(from) + from->nci - L->nci - CSTACKCF;
677+
L->nCcalls = getCcalls(from) - L->nci - CSTACKCF;
678678
if (L->nCcalls <= CSTACKERR)
679679
return resume_error(L, "C stack overflow", nargs);
680680
luai_userstateresume(L, nargs);

testes/cstack.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,22 @@ do print("testing stack-overflow in recursive 'gsub'")
105105
print("\tfinal count: ", count)
106106
end
107107

108+
do -- bug in 5.4.0
109+
print("testing limits in coroutines inside deep calls")
110+
count = 0
111+
local lim = 1000
112+
local function stack (n)
113+
progress()
114+
if n > 0 then return stack(n - 1) + 1
115+
else coroutine.wrap(function ()
116+
stack(lim)
117+
end)()
118+
end
119+
end
120+
121+
print(xpcall(stack, function () return "ok" end, lim))
122+
end
123+
108124

109125
do print("testing changes in C-stack limit")
110126

0 commit comments

Comments
 (0)