diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-03-05 13:39:47 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-03-05 13:39:47 +0000 |
commit | 8238dc0a23a0c654dc25e6debe738ae3321a46ce (patch) | |
tree | 786d8a9a0e1e8928bb5be8c262e9f7baf32f655f /src/lua | |
parent | 1fc2eaa7b39eb81deafe925bb56fc8d7cd3de078 (diff) | |
download | rspamd-8238dc0a23a0c654dc25e6debe738ae3321a46ce.tar.gz rspamd-8238dc0a23a0c654dc25e6debe738ae3321a46ce.zip |
[Project] Start optimization of userdata hashing
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/lua/lua_common.h | 4 | ||||
-rw-r--r-- | src/lua/lua_config.c | 8 | ||||
-rw-r--r-- | src/lua/lua_logger.c | 4 | ||||
-rw-r--r-- | src/lua/lua_task.c | 16 |
5 files changed, 19 insertions, 16 deletions
diff --git a/src/lua/CMakeLists.txt b/src/lua/CMakeLists.txt index a504f99f8..46de053ba 100644 --- a/src/lua/CMakeLists.txt +++ b/src/lua/CMakeLists.txt @@ -34,6 +34,7 @@ SET(LUASRC ${CMAKE_CURRENT_SOURCE_DIR}/lua_common.c ${CMAKE_CURRENT_SOURCE_DIR}/lua_spf.c ${CMAKE_CURRENT_SOURCE_DIR}/lua_tensor.c ${CMAKE_CURRENT_SOURCE_DIR}/lua_parsers.c - ${CMAKE_CURRENT_SOURCE_DIR}/lua_compress.c) + ${CMAKE_CURRENT_SOURCE_DIR}/lua_compress.c + ${CMAKE_CURRENT_SOURCE_DIR}/lua_classnames.c) SET(RSPAMD_LUA ${LUASRC} PARENT_SCOPE)
\ No newline at end of file diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index cc2b94390..b46c0bfc9 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -1,5 +1,5 @@ /* - * Copyright 2023 Vsevolod Stakhov + * Copyright 2024 Vsevolod Stakhov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ #include "config.h" + /* Lua headers do not have __cplusplus guards... */ #ifdef __cplusplus extern "C" { @@ -40,6 +41,7 @@ extern "C" { #include "rspamd.h" #include "ucl.h" #include "lua_ucl.h" +#include "lua_classnames.h" #ifdef __cplusplus extern "C" { diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index a044827a7..5e3eacd29 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -1,5 +1,5 @@ /* - * Copyright 2023 Vsevolod Stakhov + * Copyright 2024 Vsevolod Stakhov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1242,7 +1242,7 @@ lua_metric_symbol_callback(struct rspamd_task *task, } ptask = lua_newuserdata(L, sizeof(struct rspamd_task *)); - rspamd_lua_setclass(L, "rspamd{task}", -1); + rspamd_lua_setclass(L, rspamd_task_classname, -1); *ptask = task; if ((ret = lua_pcall(L, 1, LUA_MULTRET, err_idx)) != 0) { @@ -1382,7 +1382,7 @@ lua_metric_symbol_callback_coro(struct rspamd_task *task, } ptask = lua_newuserdata(thread, sizeof(struct rspamd_task *)); - rspamd_lua_setclass(thread, "rspamd{task}", -1); + rspamd_lua_setclass(thread, rspamd_task_classname, -1); *ptask = task; thread_entry->finish_callback = lua_metric_symbol_callback_return; @@ -4773,7 +4773,7 @@ void lua_call_finish_script(struct rspamd_config_cfg_lua_script *sc, lua_rawgeti(L, LUA_REGISTRYINDEX, sc->cbref); ptask = lua_newuserdata(L, sizeof(struct rspamd_task *)); - rspamd_lua_setclass(L, "rspamd{task}", -1); + rspamd_lua_setclass(L, rspamd_task_classname, -1); *ptask = task; lua_thread_call(thread, 1); diff --git a/src/lua/lua_logger.c b/src/lua/lua_logger.c index f4f8f3dbf..b9969b86b 100644 --- a/src/lua/lua_logger.c +++ b/src/lua/lua_logger.c @@ -1,5 +1,5 @@ /* - * Copyright 2023 Vsevolod Stakhov + * Copyright 2024 Vsevolod Stakhov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -653,7 +653,7 @@ lua_logger_get_id(lua_State *L, gint pos, GError **err) clsname = lua_tostring(L, -1); - if (strcmp(clsname, "rspamd{task}") == 0) { + if (strcmp(clsname, rspamd_task_classname) == 0) { struct rspamd_task *task = lua_check_task(L, pos); if (task) { diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index dd2ca108b..79cf9c55e 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -1,5 +1,5 @@ /* - * Copyright 2023 Vsevolod Stakhov + * Copyright 2024 Vsevolod Stakhov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1382,7 +1382,7 @@ static const struct luaL_reg archivelib_m[] = { struct rspamd_task * lua_check_task(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{task}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_task_classname); luaL_argcheck(L, ud != NULL, pos, "'task' expected"); return ud ? *((struct rspamd_task **) ud) : NULL; } @@ -1390,7 +1390,7 @@ lua_check_task(lua_State *L, gint pos) struct rspamd_task * lua_check_task_maybe(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata_maybe(L, pos, "rspamd{task}"); + void *ud = rspamd_lua_check_udata_maybe(L, pos, rspamd_task_classname); return ud ? *((struct rspamd_task **) ud) : NULL; } @@ -1781,7 +1781,7 @@ lua_task_load_from_file(lua_State *L) if (res) { ptask = lua_newuserdata(L, sizeof(*ptask)); *ptask = task; - rspamd_lua_setclass(L, "rspamd{task}", -1); + rspamd_lua_setclass(L, rspamd_task_classname, -1); } else { if (err) { @@ -1832,7 +1832,7 @@ lua_task_load_from_string(lua_State *L) ptask = lua_newuserdata(L, sizeof(*ptask)); *ptask = task; - rspamd_lua_setclass(L, "rspamd{task}", -1); + rspamd_lua_setclass(L, rspamd_task_classname, -1); return 2; } @@ -1868,7 +1868,7 @@ lua_task_create(lua_State *L) ptask = lua_newuserdata(L, sizeof(*ptask)); *ptask = task; - rspamd_lua_setclass(L, "rspamd{task}", -1); + rspamd_lua_setclass(L, rspamd_task_classname, -1); return 1; } @@ -7271,7 +7271,7 @@ luaopen_archive(lua_State *L) void luaopen_task(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{task}", tasklib_m); + rspamd_lua_new_class(L, rspamd_task_classname, tasklib_m); lua_pop(L, 1); rspamd_lua_add_preload(L, "rspamd_task", lua_load_task); @@ -7290,6 +7290,6 @@ void rspamd_lua_task_push(lua_State *L, struct rspamd_task *task) struct rspamd_task **ptask; ptask = lua_newuserdata(L, sizeof(gpointer)); - rspamd_lua_setclass(L, "rspamd{task}", -1); + rspamd_lua_setclass(L, rspamd_task_classname, -1); *ptask = task; } |