aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatarLibravatar william <william@25tandclement.com> 2015-07-25 14:37:04 -0700
committerLibravatarLibravatar william <william@25tandclement.com> 2015-07-25 14:37:04 -0700
commitfdaaf522474df9dd9eb23e875acd939cd0d2ea90 (patch)
tree5746aba088ab30cb4be6fbdc0b0bd9893e897770
parentf73eccfc8e589e6cc670c488b78715ee40b6985d (diff)
downloadluaossl-fdaaf522474df9dd9eb23e875acd939cd0d2ea90.tar.gz
luaossl-fdaaf522474df9dd9eb23e875acd939cd0d2ea90.tar.bz2
luaossl-fdaaf522474df9dd9eb23e875acd939cd0d2ea90.zip
refactor ex_newstate fix, which left nil on the stack
-rw-r--r--src/openssl.c17
1 files changed, 11 insertions, 6 deletions
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);