aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-07-13 13:39:02 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-07-13 13:39:02 -0300
commite1d8770f12542d34a3e32b825c95b93f8a341ee1 (patch)
tree15296aaedd195efd19192052af2192fcd7c12f54
parent0f1cd0eba99ea6d383e75b9ae488d00ad541c210 (diff)
downloadlua-e1d8770f12542d34a3e32b825c95b93f8a341ee1.tar.gz
lua-e1d8770f12542d34a3e32b825c95b93f8a341ee1.tar.bz2
lua-e1d8770f12542d34a3e32b825c95b93f8a341ee1.zip
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.
-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 e3db1f74..4c976a14 100644
--- a/ldo.c
+++ b/ldo.c
@@ -674,7 +674,7 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs,
674 if (from == NULL) 674 if (from == NULL)
675 L->nCcalls = CSTACKTHREAD; 675 L->nCcalls = CSTACKTHREAD;
676 else /* correct 'nCcalls' for this thread */ 676 else /* correct 'nCcalls' for this thread */
677 L->nCcalls = getCcalls(from) + from->nci - L->nci - CSTACKCF; 677 L->nCcalls = getCcalls(from) - L->nci - CSTACKCF;
678 if (L->nCcalls <= CSTACKERR) 678 if (L->nCcalls <= CSTACKERR)
679 return resume_error(L, "C stack overflow", nargs); 679 return resume_error(L, "C stack overflow", nargs);
680 luai_userstateresume(L, nargs); 680 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'")
105 print("\tfinal count: ", count) 105 print("\tfinal count: ", count)
106end 106end
107 107
108do -- 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))
122end
123
108 124
109do print("testing changes in C-stack limit") 125do print("testing changes in C-stack limit")
110 126