Actually, there's a lot errors in the code as well. 0 is never a valid stack index, yet you use it as one in lua_resume. Additionally, calling coroutine.yield() when not inside of a coroutine will throw an error. On Fri, Dec 12, 2014 at 3:52 PM, Alex <initrd.gz@xxxxxxxxx> wrote: > > > luaL_loadstring(lua, "coroutine.yield()"); > > This just loads the string and creates a function from the contents; it > doesn't run it. You then try to resume the resulting function, which isn't > a coroutine. > > On Fri, Dec 12, 2014 at 3:44 PM, Sergei Zhirikov < > dmarc-noreply@xxxxxxxxxxxxx> wrote: >> >> Hi, >> >> I've encountered this case of a consistent segmentation fault in LuaJIT >> (tested with 2.0.3 on x86 and x86_64). >> The following simple example allows to reproduce it: >> >> #include <lua.h> >> #include <lualib.h> >> #include <lauxlib.h> >> #include <stdio.h> >> >> int main() >> { >> lua_State *lua = luaL_newstate(); >> luaL_openlibs(lua); >> luaL_loadstring(lua, "coroutine.yield()"); >> int res = lua_resume(lua, 0); >> printf("res=%d, top=%d\n", res, lua_gettop(lua)); >> lua_pushliteral(lua, "test"); >> lua_error(lua); >> return 0; >> } >> >> This code is supposed to panic, but it results in a segmentation fault >> inside lua_error() instead. Admittedly, this not a very common usage >> pattern, but calling lua_error() on a suspended Lua thread can be useful >> sometimes. Also, the "classic" Lua implementation doesn't have a problem >> with this usage. >> >> I'm wondering, can this be fixed with a simple patch? >> >> Thanks & regards, >> Sergei. >> >> >> > > -- > Sincerely, > Alex Parrill > -- Sincerely, Alex Parrill