commit 47cf9c8: [Minor] Fix conditions operations
Vsevolod Stakhov
vsevolod at rspamd.com
Sat May 7 12:14:04 UTC 2022
Author: Vsevolod Stakhov
Date: 2022-05-07 13:09:42 +0100
URL: https://github.com/rspamd/rspamd/commit/47cf9c8082000be8b63fbeb4c6d35c7b2bd05af5 (HEAD -> master)
[Minor] Fix conditions operations
---
src/libserver/symcache/symcache_impl.cxx | 9 ++++++++-
src/libserver/symcache/symcache_item.cxx | 7 ++-----
src/libserver/symcache/symcache_item.hxx | 18 ++++++++++++++----
3 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/src/libserver/symcache/symcache_impl.cxx b/src/libserver/symcache/symcache_impl.cxx
index 25918ce1d..fb274e080 100644
--- a/src/libserver/symcache/symcache_impl.cxx
+++ b/src/libserver/symcache/symcache_impl.cxx
@@ -35,10 +35,12 @@ auto symcache::init() -> bool
reload_time = cfg->cache_reload_time;
if (cfg->cache_filename != nullptr) {
+ msg_debug_cache("loading symcache saved data from %s", cfg->cache_filename);
res = load_items();
}
/* Deal with the delayed dependencies */
+ msg_debug_cache("resolving delayed dependencies: %d in list", (int)delayed_deps->size());
for (const auto &delayed_dep: *delayed_deps) {
auto virt_item = get_item_by_name(delayed_dep.from, false);
auto real_item = get_item_by_name(delayed_dep.from, true);
@@ -64,6 +66,7 @@ auto symcache::init() -> bool
/* Deal with the delayed conditions */
+ msg_debug_cache("resolving delayed conditions: %d in list", (int)delayed_conditions->size());
for (const auto &delayed_cond: *delayed_conditions) {
auto it = get_item_by_name_mut(delayed_cond.sym, true);
@@ -80,10 +83,13 @@ auto symcache::init() -> bool
delayed_cond.sym.c_str());
g_abort();
}
+
+ msg_debug_cache("added a condition to the symbol %s", it->symbol.c_str());
}
}
delayed_conditions.reset();
+ msg_debug_cache("process dependencies");
for (auto &it: items_by_id) {
it->process_deps(*this);
}
@@ -110,7 +116,7 @@ auto symcache::init() -> bool
return 1;
};
-
+ msg_debug_cache("sorting stuff");
std::stable_sort(std::begin(connfilters), std::end(connfilters), prefilters_cmp);
std::stable_sort(std::begin(prefilters), std::end(prefilters), prefilters_cmp);
std::stable_sort(std::begin(postfilters), std::end(postfilters), postfilters_cmp);
@@ -120,6 +126,7 @@ auto symcache::init() -> bool
/* Connect metric symbols with symcache symbols */
if (cfg->symbols) {
+ msg_debug_cache("connect metrics");
g_hash_table_foreach(cfg->symbols,
symcache::metric_connect_cb,
(void *) this);
diff --git a/src/libserver/symcache/symcache_item.cxx b/src/libserver/symcache/symcache_item.cxx
index e918d5b2c..70c1921bb 100644
--- a/src/libserver/symcache/symcache_item.cxx
+++ b/src/libserver/symcache/symcache_item.cxx
@@ -472,14 +472,11 @@ auto item_condition::check(std::string_view sym_name, struct rspamd_task *task)
if (cb != -1 && L != nullptr) {
auto ret = false;
- lua_rawgeti(L, LUA_REGISTRYINDEX, cb);
-
lua_pushcfunction (L, &rspamd_lua_traceback);
auto err_idx = lua_gettop(L);
- auto **ptask = (struct rspamd_task **) lua_newuserdata(L, sizeof(struct rspamd_task *));
- rspamd_lua_setclass(L, "rspamd{task}", -1);
- *ptask = task;
+ lua_rawgeti(L, LUA_REGISTRYINDEX, cb);
+ rspamd_lua_task_push(L, task);
if (lua_pcall(L, 1, 1, err_idx) != 0) {
msg_info_task("call to condition for %s failed: %s",
diff --git a/src/libserver/symcache/symcache_item.hxx b/src/libserver/symcache/symcache_item.hxx
index 1d0cd7e35..89c00ded5 100644
--- a/src/libserver/symcache/symcache_item.hxx
+++ b/src/libserver/symcache/symcache_item.hxx
@@ -85,11 +85,21 @@ auto item_type_from_c(enum rspamd_symbol_type type) -> tl::expected<std::pair<sy
struct item_condition {
private:
- lua_State *L;
- int cb;
+ lua_State *L = nullptr;
+ int cb = -1;
public:
- item_condition(lua_State *_L, int _cb) : L(_L), cb(_cb) {}
- virtual ~item_condition();
+ explicit item_condition(lua_State *L_, int cb_) noexcept : L(L_), cb(cb_) {}
+ item_condition(item_condition &&other) noexcept {
+ *this = std::move(other);
+ }
+ /* Make it move only */
+ item_condition(const item_condition &) = delete;
+ item_condition& operator=(item_condition &&other) noexcept {
+ std::swap(other.L, L);
+ std::swap(other.cb, cb);
+ return *this;
+ }
+ ~item_condition();
auto check(std::string_view sym_name, struct rspamd_task *task) const -> bool;
};
More information about the Commits
mailing list