lua

A copy of the Lua development repository
Log | Files | Refs | README

commit 3f253f116e8e292977a1bded964544fb35b3d1e3
parent 389116d8abcc96db3cfe2f3cc25789c089fe12d6
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Thu,  9 May 2019 11:31:53 -0300

Test for dead coroutine moved to 'lua_resume'

The test for dead coroutines done in the 'coro' library was moved
to 'lua_resume', in the kernel, which already does other similar
tests.

Diffstat:
Mlcorolib.c | 4----
Mldo.c | 2++
2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/lcorolib.c b/lcorolib.c @@ -35,10 +35,6 @@ static int auxresume (lua_State *L, lua_State *co, int narg) { lua_pushliteral(L, "too many arguments to resume"); return -1; /* error flag */ } - if (lua_status(co) == LUA_OK && lua_gettop(co) == 0) { - lua_pushliteral(L, "cannot resume dead coroutine"); - return -1; /* error flag */ - } lua_xmove(L, co, narg); status = lua_resume(co, L, narg, &nres); if (status == LUA_OK || status == LUA_YIELD) { diff --git a/ldo.c b/ldo.c @@ -666,6 +666,8 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs, if (L->status == LUA_OK) { /* may be starting a coroutine */ if (L->ci != &L->base_ci) /* not in base level? */ return resume_error(L, "cannot resume non-suspended coroutine", nargs); + else if (L->top - (L->ci->func + 1) == nargs) /* no function? */ + return resume_error(L, "cannot resume dead coroutine", nargs); } else if (L->status != LUA_YIELD) return resume_error(L, "cannot resume dead coroutine", nargs);