From 2086e13a4696792d32001f671821571fd27c6ab2 Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Wed, 17 Jun 2015 22:12:48 +0800 Subject: [PATCH] hack lua to support signal --- 3rd/lua/lua.h | 5 +++++ 3rd/lua/lvm.c | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/3rd/lua/lua.h b/3rd/lua/lua.h index 1c2b95ac..065e72a0 100644 --- a/3rd/lua/lua.h +++ b/3rd/lua/lua.h @@ -458,6 +458,11 @@ struct lua_Debug { /* }====================================================================== */ +/* Add by skynet */ + +LUA_API lua_State * skynet_sig_L; +LUA_API void (lua_checksig_)(lua_State *L); +#define lua_checksig(L) if (skynet_sig_L) { lua_checksig_(L); } /****************************************************************************** * Copyright (C) 1994-2015 Lua.org, PUC-Rio. diff --git a/3rd/lua/lvm.c b/3rd/lua/lvm.c index a8cefc52..a45d6cf2 100644 --- a/3rd/lua/lvm.c +++ b/3rd/lua/lvm.c @@ -63,7 +63,17 @@ #endif +/* Add by skynet */ +lua_State * skynet_sig_L = NULL; +LUA_API void +lua_checksig_(lua_State *L) { + if (skynet_sig_L == G(L)->mainthread) { + skynet_sig_L = NULL; + lua_pushnil(L); + lua_error(L); + } +} /* ** Try to convert a value to a float. The float case is already handled @@ -1028,6 +1038,7 @@ void luaV_execute (lua_State *L) { vmbreak; } vmcase(OP_JMP) { + lua_checksig(L); dojump(ci, i, 0); vmbreak; } @@ -1080,6 +1091,7 @@ void luaV_execute (lua_State *L) { vmcase(OP_CALL) { int b = GETARG_B(i); int nresults = GETARG_C(i) - 1; + lua_checksig(L); if (b != 0) L->top = ra+b; /* else previous instruction set top */ if (luaD_precall(L, ra, nresults)) { /* C function? */ if (nresults >= 0) L->top = ci->top; /* adjust results */ @@ -1094,6 +1106,7 @@ void luaV_execute (lua_State *L) { } vmcase(OP_TAILCALL) { int b = GETARG_B(i); + lua_checksig(L); if (b != 0) L->top = ra+b; /* else previous instruction set top */ lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); if (luaD_precall(L, ra, LUA_MULTRET)) /* C function? */ @@ -1203,6 +1216,7 @@ void luaV_execute (lua_State *L) { } vmcase(OP_TFORLOOP) { l_tforloop: + lua_checksig(L); if (!ttisnil(ra + 1)) { /* continue loop? */ setobjs2s(L, ra, ra + 1); /* save control variable */ ci->u.l.savedpc += GETARG_sBx(i); /* jump back */