lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> I might be mistaken, but I believe I found a bug in Lua 5.2.2 with
> `coroutine.resume` (even after applying all patches). When calling it
> with the current coroutine (i.e. passing `coroutine.running()`) it
> seems to break the running coroutine. I'm aware that the call itself
> makes no practical sense, but it even returns an appropriate error
> message ("cannot resume non-suspended coroutine") so I don't think
> breaking the state is what it should do. Here's the code to reproduce
> the issue:
> 
> ```
> -- Minimal test-case (I think)
> print(coroutine.resume(coroutine.create(function()
>   coroutine.resume(coroutine.running())
>   coroutine.yield()
> end)))
> -- expected: true
> -- actually: false   attempt to yield across a C-call boundary
> ```
> 
> Note that even after the call to `coroutine.resume` the coroutine is
> not dead, however: `coroutine.status(coroutine.running())` still
> reports "running".

Bug confirmed. I guess the problem is this line when finishing
'lua_resume' (file ldo.c):

  L->nny = 1;  /* do not allow yields */

(It assumed to coroutine was not running before the call to resume,
so it restores its original status; but in your example the original
status was not "do not allow yields".) But I have to check it.

-- Roberto