From 7bdf2557bbf7267542604567a0db809657b54d97 Mon Sep 17 00:00:00 2001 From: William Ahern Date: Wed, 10 Oct 2012 16:46:28 -0700 Subject: -n fix compile for LuaJIT --- Makefile | 2 +- compat52.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ openssl.c | 7 +++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 compat52.h diff --git a/Makefile b/Makefile index c6f7e4d..609f09c 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ all: openssl.so openssl.so: openssl.o $(CC) -o $@ $^ $(SOFLAGS) $(LDFLAGS) -openssl.o: openssl.c +openssl.o: openssl.c compat52.h $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< diff --git a/compat52.h b/compat52.h new file mode 100644 index 0000000..c674f13 --- /dev/null +++ b/compat52.h @@ -0,0 +1,50 @@ + + +static void luaL_setmetatable(lua_State *L, const char *tname) { + luaL_getmetatable(L, tname); + lua_setmetatable(L, -2); +} /* luaL_setmetatable() */ + + +static int lua_absindex(lua_State *L, int idx) { + return (idx > 0 || idx <= LUA_REGISTRYINDEX)? idx : lua_gettop(L) + idx + 1; +} /* lua_absindex() */ + + +static void *luaL_testudata(lua_State *L, int arg, const char *tname) { + void *p = lua_touserdata(L, arg); + int eq; + + if (!p || !lua_getmetatable(L, arg)) + return 0; + + luaL_getmetatable(L, tname); + eq = lua_rawequal(L, -2, -1); + lua_pop(L, 2); + + return (eq)? p : 0; +} /* luaL_testudate() */ + + +static void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup) { + int i, t = lua_absindex(L, -1 - nup); + + for (; l->name; l++) { + for (i = 0; i < nup; i++) + lua_pushvalue(L, -nup); + lua_pushcclosure(L, l->func, nup); + lua_setfield(L, t, l->name); + } + + return lua_pop(L, nup); +} /* luaL_setfuncs() */ + + +#define luaL_newlibtable(L, l) \ + lua_createtable(L, 0, (sizeof (l) / sizeof *(l)) - 1) + +#define luaL_newlib(L, l) \ + (luaL_newlibtable((L), (l)), luaL_setfuncs((L), (l), 0)) + + + diff --git a/openssl.c b/openssl.c index c0196bd..4ab0688 100644 --- a/openssl.c +++ b/openssl.c @@ -52,6 +52,9 @@ #include #include +#if LUA_VERSION_NUM < 502 +#include "compat52.h" +#endif #define BIGNUM_CLASS "OpenSSL Bignum" #define PUBKEY_CLASS "OpenSSL Pubkey" @@ -1665,7 +1668,11 @@ static int xc_digest(lua_State *L) { luaL_Buffer B; unsigned i; +#if LUA_VERSION_NUM < 502 + luaL_buffinit(L, &B); +#else luaL_buffinitsize(L, &B, 2 * len); +#endif for (i = 0; i < len; i++) { luaL_addchar(&B, x[0x0f & (md[i] >> 4)]); -- cgit v1.2.3-59-g8ed1b