diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-03-17 16:34:20 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-03-17 16:34:20 +0000 |
commit | 6d65818ca24f83e6b606cd291b3fe17e288f2b07 (patch) | |
tree | 5bee5f18c371aeb8eca76c040755bb8645406108 /src/lua | |
parent | 45c172ad0af49d2c73ddc3fcd2111718c6a8b19d (diff) | |
download | rspamd-6d65818ca24f83e6b606cd291b3fe17e288f2b07.tar.gz rspamd-6d65818ca24f83e6b606cd291b3fe17e288f2b07.zip |
Allow to check mempool on any position in the stack.
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/lua_common.h | 2 | ||||
-rw-r--r-- | src/lua/lua_mempool.c | 22 | ||||
-rw-r--r-- | src/lua/lua_session.c | 2 |
3 files changed, 11 insertions, 15 deletions
diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index ce817d1e1..1f3ea5922 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -230,7 +230,7 @@ void rspamd_lua_dumpstack (lua_State *L); /* Set lua path according to the configuration */ void rspamd_lua_set_path (lua_State *L, struct rspamd_config *cfg); -struct memory_pool_s * rspamd_lua_check_mempool (lua_State * L); +struct memory_pool_s * rspamd_lua_check_mempool (lua_State * L, gint pos); #endif /* WITH_LUA */ diff --git a/src/lua/lua_mempool.c b/src/lua/lua_mempool.c index 049f8080e..e6d80ab1f 100644 --- a/src/lua/lua_mempool.c +++ b/src/lua/lua_mempool.c @@ -24,10 +24,6 @@ #include "lua_common.h" #include "mem_pool.h" -/* Public prototypes */ -struct memory_pool_s * rspamd_lua_check_mempool (lua_State * L); -void luaopen_mempool (lua_State * L); - /* Lua bindings */ LUA_FUNCTION_DEF (mempool, create); LUA_FUNCTION_DEF (mempool, memory_pool_add_destructor); @@ -64,10 +60,10 @@ struct lua_mempool_udata { }; struct memory_pool_s * -rspamd_lua_check_mempool (lua_State * L) +rspamd_lua_check_mempool (lua_State * L, gint pos) { - void *ud = luaL_checkudata (L, 1, "rspamd{mempool}"); - luaL_argcheck (L, ud != NULL, 1, "'mempool' expected"); + void *ud = luaL_checkudata (L, pos, "rspamd{mempool}"); + luaL_argcheck (L, ud != NULL, pos, "'mempool' expected"); return ud ? *((struct memory_pool_s **)ud) : NULL; } @@ -105,7 +101,7 @@ lua_mempool_destructor_func (gpointer p) static int lua_mempool_memory_pool_add_destructor (lua_State *L) { - struct memory_pool_s *mempool = rspamd_lua_check_mempool (L); + struct memory_pool_s *mempool = rspamd_lua_check_mempool (L, 1); struct lua_mempool_udata *ud; if (mempool) { @@ -135,7 +131,7 @@ lua_mempool_memory_pool_add_destructor (lua_State *L) static int lua_mempool_memory_pool_delete (lua_State *L) { - struct memory_pool_s *mempool = rspamd_lua_check_mempool (L); + struct memory_pool_s *mempool = rspamd_lua_check_mempool (L, 1); if (mempool) { rspamd_mempool_delete (mempool); @@ -151,7 +147,7 @@ lua_mempool_memory_pool_delete (lua_State *L) static int lua_mempool_memory_pool_stat (lua_State *L) { - struct memory_pool_s *mempool = rspamd_lua_check_mempool (L); + struct memory_pool_s *mempool = rspamd_lua_check_mempool (L, 1); if (mempool) { @@ -166,7 +162,7 @@ lua_mempool_memory_pool_stat (lua_State *L) static int lua_mempool_memory_pool_suggest_size (lua_State *L) { - struct memory_pool_s *mempool = rspamd_lua_check_mempool (L); + struct memory_pool_s *mempool = rspamd_lua_check_mempool (L, 1); if (mempool) { lua_pushinteger (L, rspamd_mempool_suggest_size ()); @@ -182,7 +178,7 @@ lua_mempool_memory_pool_suggest_size (lua_State *L) static int lua_mempool_memory_pool_set_variable (lua_State *L) { - struct memory_pool_s *mempool = rspamd_lua_check_mempool (L); + struct memory_pool_s *mempool = rspamd_lua_check_mempool (L, 1); const gchar *var = luaL_checkstring (L, 2), *value = luaL_checkstring (L, 3); @@ -201,7 +197,7 @@ lua_mempool_memory_pool_set_variable (lua_State *L) static int lua_mempool_memory_pool_get_variable (lua_State *L) { - struct memory_pool_s *mempool = rspamd_lua_check_mempool (L); + struct memory_pool_s *mempool = rspamd_lua_check_mempool (L, 1); const gchar *var = luaL_checkstring (L, 2); gchar *value; diff --git a/src/lua/lua_session.c b/src/lua/lua_session.c index 3fa636a5b..bbbd6695e 100644 --- a/src/lua/lua_session.c +++ b/src/lua/lua_session.c @@ -156,7 +156,7 @@ lua_session_create (lua_State *L) return 1; } - mempool = rspamd_lua_check_mempool (L); + mempool = rspamd_lua_check_mempool (L, 1); if (mempool == NULL) { msg_err ("invalid mempool argument to rspamd_session.create"); lua_pushnil (L); |