# HG changeset patch # User jbe # Date 1431029775 -7200 # Node ID 43387f11b09689efb8b3efc72e5909e17ff6ba3f # Parent 6dfe5b424b1839429b160c32f9c03c9f3ce019cb Do not pass moonbridge_io.block when invoking callback passed to _call I/O methods but only include it for _yield I/O methods diff -r 6dfe5b424b18 -r 43387f11b096 Makefile --- a/Makefile Thu May 07 21:32:58 2015 +0200 +++ b/Makefile Thu May 07 22:16:15 2015 +0200 @@ -68,5 +68,5 @@ ld -shared -o moonbridge_websocket.so -lmd moonbridge_websocket.o clean:: - rm -f moonbridge moonbridge_io.o moonbridge_websocket.so + rm -f moonbridge moonbridge_io.o moonbridge_io.so moonbridge_websocket.o moonbridge_websocket.so diff -r 6dfe5b424b18 -r 43387f11b096 moonbridge_io.c --- a/moonbridge_io.c Thu May 07 21:32:58 2015 +0200 +++ b/moonbridge_io.c Thu May 07 22:16:15 2015 +0200 @@ -73,8 +73,10 @@ int nonblocking; } moonbr_io_listener_t; -static int moonbr_io_yield(lua_State *L) { - return lua_yield(L, 0); +static int moonbr_io_yield_block(lua_State *L) { + lua_pushlightuserdata(L, &moonbr_io_block_udata); + lua_insert(L, 1); + return lua_yield(L, lua_gettop(L)); } #if LUA_VERSION_NUM >= 503 @@ -91,7 +93,7 @@ lua_pushcfunction(L, callfunc); \ lua_insert(L, 1); \ args = lua_gettop(L); \ - lua_pushcfunction(L, moonbr_io_yield); \ + lua_pushcfunction(L, moonbr_io_yield_block); \ lua_insert(L, 3); \ lua_callk(L, args, LUA_MULTRET, 0, moonbr_io_cont_returnall); \ return lua_gettop(L); \ @@ -334,10 +336,9 @@ lua_replace(L, 3); } lua_pushvalue(L, 2); - lua_pushlightuserdata(L, &moonbr_io_block_udata); lua_pushvalue(L, 1); lua_pushliteral(L, "r"); - lua_callk(L, 3, 0, ctx, moonbr_io_read_cont); + lua_callk(L, 2, 0, ctx, moonbr_io_read_cont); } if (ctx == 1) { lua_pushvalue(L, 5); @@ -399,10 +400,9 @@ lua_replace(L, 3); } lua_pushvalue(L, 2); - lua_pushlightuserdata(L, &moonbr_io_block_udata); lua_pushvalue(L, 1); lua_pushliteral(L, "r"); - lua_callk(L, 3, 0, ctx, moonbr_io_drain_cont); + lua_callk(L, 2, 0, ctx, moonbr_io_drain_cont); } lua_pushinteger(L, totallen); lua_pushvalue(L, -2); @@ -580,10 +580,9 @@ } lua_pop(L, 2); lua_pushvalue(L, 2); - lua_pushlightuserdata(L, &moonbr_io_block_udata); lua_pushvalue(L, 1); lua_pushliteral(L, "w"); - lua_callk(L, 3, 0, 0, moonbr_io_write_cont); + lua_callk(L, 2, 0, 0, moonbr_io_write_cont); } }