commit 8d09756: [Minor] Allow to convert mempool into raw pointer
Vsevolod Stakhov
vsevolod at highsecure.ru
Fri Jan 22 16:00:32 UTC 2021
Author: Vsevolod Stakhov
Date: 2021-01-22 15:40:55 +0000
URL: https://github.com/rspamd/rspamd/commit/8d097563def70c38239f7ad663e11e60bd445b6d
[Minor] Allow to convert mempool into raw pointer
---
src/lua/lua_mempool.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
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)
{
More information about the Commits
mailing list