From fdaaf522474df9dd9eb23e875acd939cd0d2ea90 Mon Sep 17 00:00:00 2001 From: william Date: Sat, 25 Jul 2015 14:37:04 -0700 Subject: refactor ex_newstate fix, which left nil on the stack --- src/openssl.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/openssl.c b/src/openssl.c index 8977234..9dbcda7 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -1181,18 +1181,23 @@ static int ex__gc(lua_State *L) { return 0; } /* ex__gc() */ -static void ex_newstate(lua_State *L) { - struct ex_state *state; - struct lua_State *thr; +static _Bool ex_hasstate(lua_State *L) { + _Bool has; lua_pushlightuserdata(L, (void *)&ex__gc); lua_gettable(L, LUA_REGISTRYINDEX); + has = !lua_isnil(L, -1); + lua_pop(L, 1); - if (!lua_isnil(L, -1)) { - lua_pop(L, 1); + return has; +} /* ex_hasstate() */ +static void ex_newstate(lua_State *L) { + struct ex_state *state; + struct lua_State *thr; + + if (ex_hasstate(L)) return; - } state = prepudata(L, sizeof *state, NULL, &ex__gc); LIST_INIT(&state->data); -- cgit v1.2.3-59-g8ed1b