diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | compat52.h | 50 | ||||
| -rw-r--r-- | openssl.c | 7 |
3 files changed, 58 insertions, 1 deletions
| @@ -40,7 +40,7 @@ all: openssl.so | |||
| 40 | openssl.so: openssl.o | 40 | openssl.so: openssl.o |
| 41 | $(CC) -o $@ $^ $(SOFLAGS) $(LDFLAGS) | 41 | $(CC) -o $@ $^ $(SOFLAGS) $(LDFLAGS) |
| 42 | 42 | ||
| 43 | openssl.o: openssl.c | 43 | openssl.o: openssl.c compat52.h |
| 44 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< | 44 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< |
| 45 | 45 | ||
| 46 | 46 | ||
diff --git a/compat52.h b/compat52.h new file mode 100644 index 0000000..c674f13 --- /dev/null +++ b/compat52.h | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | |||
| 2 | |||
| 3 | static void luaL_setmetatable(lua_State *L, const char *tname) { | ||
| 4 | luaL_getmetatable(L, tname); | ||
| 5 | lua_setmetatable(L, -2); | ||
| 6 | } /* luaL_setmetatable() */ | ||
| 7 | |||
| 8 | |||
| 9 | static int lua_absindex(lua_State *L, int idx) { | ||
| 10 | return (idx > 0 || idx <= LUA_REGISTRYINDEX)? idx : lua_gettop(L) + idx + 1; | ||
| 11 | } /* lua_absindex() */ | ||
| 12 | |||
| 13 | |||
| 14 | static void *luaL_testudata(lua_State *L, int arg, const char *tname) { | ||
| 15 | void *p = lua_touserdata(L, arg); | ||
| 16 | int eq; | ||
| 17 | |||
| 18 | if (!p || !lua_getmetatable(L, arg)) | ||
| 19 | return 0; | ||
| 20 | |||
| 21 | luaL_getmetatable(L, tname); | ||
| 22 | eq = lua_rawequal(L, -2, -1); | ||
| 23 | lua_pop(L, 2); | ||
| 24 | |||
| 25 | return (eq)? p : 0; | ||
| 26 | } /* luaL_testudate() */ | ||
| 27 | |||
| 28 | |||
| 29 | static void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup) { | ||
| 30 | int i, t = lua_absindex(L, -1 - nup); | ||
| 31 | |||
| 32 | for (; l->name; l++) { | ||
| 33 | for (i = 0; i < nup; i++) | ||
| 34 | lua_pushvalue(L, -nup); | ||
| 35 | lua_pushcclosure(L, l->func, nup); | ||
| 36 | lua_setfield(L, t, l->name); | ||
| 37 | } | ||
| 38 | |||
| 39 | return lua_pop(L, nup); | ||
| 40 | } /* luaL_setfuncs() */ | ||
| 41 | |||
| 42 | |||
| 43 | #define luaL_newlibtable(L, l) \ | ||
| 44 | lua_createtable(L, 0, (sizeof (l) / sizeof *(l)) - 1) | ||
| 45 | |||
| 46 | #define luaL_newlib(L, l) \ | ||
| 47 | (luaL_newlibtable((L), (l)), luaL_setfuncs((L), (l), 0)) | ||
| 48 | |||
| 49 | |||
| 50 | |||
| @@ -52,6 +52,9 @@ | |||
| 52 | #include <lualib.h> | 52 | #include <lualib.h> |
| 53 | #include <lauxlib.h> | 53 | #include <lauxlib.h> |
| 54 | 54 | ||
| 55 | #if LUA_VERSION_NUM < 502 | ||
| 56 | #include "compat52.h" | ||
| 57 | #endif | ||
| 55 | 58 | ||
| 56 | #define BIGNUM_CLASS "OpenSSL Bignum" | 59 | #define BIGNUM_CLASS "OpenSSL Bignum" |
| 57 | #define PUBKEY_CLASS "OpenSSL Pubkey" | 60 | #define PUBKEY_CLASS "OpenSSL Pubkey" |
| @@ -1665,7 +1668,11 @@ static int xc_digest(lua_State *L) { | |||
| 1665 | luaL_Buffer B; | 1668 | luaL_Buffer B; |
| 1666 | unsigned i; | 1669 | unsigned i; |
| 1667 | 1670 | ||
| 1671 | #if LUA_VERSION_NUM < 502 | ||
| 1672 | luaL_buffinit(L, &B); | ||
| 1673 | #else | ||
| 1668 | luaL_buffinitsize(L, &B, 2 * len); | 1674 | luaL_buffinitsize(L, &B, 2 * len); |
| 1675 | #endif | ||
| 1669 | 1676 | ||
| 1670 | for (i = 0; i < len; i++) { | 1677 | for (i = 0; i < len; i++) { |
| 1671 | luaL_addchar(&B, x[0x0f & (md[i] >> 4)]); | 1678 | luaL_addchar(&B, x[0x0f & (md[i] >> 4)]); |
