On Sun, May 31, 2020 at 1:20 PM Renato Maia <maia@inf.puc-rio.br> wrote:
>
> Because I'm getting a spurious segmentation fault while handling the
> error in the finalizer in `lua_close`. The example above can reproduce
> the problem with Lua 5.3.5 most of the time in my environment. But I
> was not able to reproduce it with Lua 5.2.4 nor Lua 5.4.0 alpha.
I can confirm this. Here's a minimal reproducer:
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
int main(void) {
lua_State *L = luaL_newstate();
luaL_openlibs(L);
luaL_loadstring(L, "setmetatable({}, { __gc = function()
debug.getinfo(0, 'n') end }); coroutine.yield()");
lua_resume(L, NULL, 0);
lua_close(L);
return 0;
}
I'm not sure, though, whether this is a bug in Lua, or just that
you're not supposed to use lua_resume on the main thread.
Joseph C. Sible
I'm reasonably certain you're not supposed to. The main thread is something of a special case. It isn't a coroutine and it has responsibilities that coroutines don't. (You can't, for example, close the main thread and expect its coroutines to continue working.)
Honestly I would have been surprised if it DID work, and I wouldn't have relied on it in practice because that sounds more like taking advantage of an implementation detail than an intended behavior.
/s/ Adam