[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: The C API and yielded threads: What is allowed?
- From: Uli Schlachter <psychon@...>
- Date: Fri, 17 Nov 2017 17:39:14 +0100
Hi everyone,
my problem is basically: Which functions am I allowed to call on a
lua_State with lua_status(L) == LUA_YIELD? Also, where in the manual is
this documented (and/or: could someone write up the needed docs for this)?
It seems that I am not allowed to do Lua calls on such a state as there
is an api_check() that asserts against it in lua_callp and lua_pcallk.
However, currently Lua does not mind running meta-methods on such a
thread, except when that metamethod causes a call to one of the
functions above. I got assertion failures from basically all Lua
versions in complicated conditions around this, some of them involving
debug.sethook() / LuaCov.
I wanted to propose adding an api_check() to luaT_callTM() and
luaT_callbinTM() so that these problems are caught earlier. However,
Google lead me to [0] which basically mentions the same problem, but
mentions that __gc metamethods mean that "basically nothing" is allowed
on a yielded thread.
So, what is the state of this? Is the assertion from [1] correct that
only lua_resume, lua_xmove, lua_pushthread and lua_checkstack are okay?
(I would add lua_version to the list, and I bet there are other
functions which ought to be okay:)
However, I don't think that even just lua_checkstack is okay since if
HARDMEMTESTS is defined this can cause a complete GC run (and this runs
finalizers, right?). If so, then I can not even push the arguments for
continuation to the yielded thread if there are too many?!?
Thanks for any pointers and clarifications, for example to docs that I
missed. :-)
Also, please add lua_apicheck()s that make it easier to test if some
piece of code got this wrong.
Cheers,
Uli
[0]: http://lua-users.org/lists/lua-l/2016-08/msg00150.html
[1]: http://lua-users.org/lists/lua-l/2016-08/msg00186.html
P.S.: https://github.com/pavouk/lgi/pull/181
--
"For saving the Earth.. and eating cheesecake!"