From: Vsevolod Stakhov Date: Fri, 22 Jan 2021 15:40:55 +0000 (+0000) Subject: [Minor] Allow to convert mempool into raw pointer X-Git-Tag: 3.0~740 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8d097563def70c38239f7ad663e11e60bd445b6d;p=rspamd.git [Minor] Allow to convert mempool into raw pointer --- 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}, @@ -570,6 +578,23 @@ lua_mempool_delete_variable (lua_State *L) return 1; } +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) {