diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-01-22 15:40:55 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-01-22 15:58:05 +0000 |
commit | 8d097563def70c38239f7ad663e11e60bd445b6d (patch) | |
tree | d429ee8dadba776f9480b74f08b76c490b5c87ff | |
parent | 427f8879360595ff48b77400b6b02b5a6968c4d1 (diff) | |
download | rspamd-8d097563def70c38239f7ad663e11e60bd445b6d.tar.gz rspamd-8d097563def70c38239f7ad663e11e60bd445b6d.zip |
[Minor] Allow to convert mempool into raw pointer
-rw-r--r-- | src/lua/lua_mempool.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/lua/lua_mempool.c b/src/lua/lua_mempool.c index c376ee701..396f39170 100644 --- a/src/lua/lua_mempool.c +++ b/src/lua/lua_mempool.c @@ -109,6 +109,13 @@ LUA_FUNCTION_DEF (mempool, has_variable); * @return {boolean} `true` if variable exists and has been removed */ LUA_FUNCTION_DEF (mempool, delete_variable); +/** + * @method mempool:topointer() + * + * Returns raw C pointer (lightuserdata) associated with mempool. This might be + * broken with luajit and GC64, use with caution. + */ +LUA_FUNCTION_DEF (mempool, topointer); static const struct luaL_reg mempoollib_m[] = { LUA_INTERFACE_DEF (mempool, add_destructor), @@ -119,6 +126,7 @@ static const struct luaL_reg mempoollib_m[] = { LUA_INTERFACE_DEF (mempool, get_variable), LUA_INTERFACE_DEF (mempool, has_variable), LUA_INTERFACE_DEF (mempool, delete_variable), + LUA_INTERFACE_DEF (mempool, topointer), LUA_INTERFACE_DEF (mempool, delete), {"destroy", lua_mempool_delete}, {"__tostring", rspamd_lua_class_tostring}, @@ -571,6 +579,23 @@ lua_mempool_delete_variable (lua_State *L) } static gint +lua_mempool_topointer (lua_State *L) +{ + LUA_TRACE_POINT; + rspamd_mempool_t *pool = rspamd_lua_check_mempool (L, 1); + + if (pool) { + /* XXX: this might cause issues on arm64 and LuaJIT */ + lua_pushlightuserdata (L, pool); + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 1; +} + +static gint lua_load_mempool (lua_State * L) { lua_newtable (L); |