From bac819b549f92e5593c92ff5cc32ae82f3e8f460 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 20 Apr 2022 19:57:54 +0100 Subject: [PATCH] [Minor] Implement adding deps and remove an old deprecated method --- src/libserver/rspamd_symcache.h | 11 ----------- src/libserver/symcache/symcache_c.cxx | 8 ++++++++ src/libserver/symcache/symcache_internal.hxx | 15 +++++++++++++++ src/lua/lua_config.c | 8 +------- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/libserver/rspamd_symcache.h b/src/libserver/rspamd_symcache.h index 62a4c8714..0ef76c832 100644 --- a/src/libserver/rspamd_symcache.h +++ b/src/libserver/rspamd_symcache.h @@ -222,17 +222,6 @@ void* rspamd_symcache_start_refresh (struct rspamd_symcache *cache, void rspamd_symcache_inc_frequency (struct rspamd_symcache *cache, struct rspamd_symcache_item *item); -/** - * Add dependency relation between two symbols identified by id (source) and - * a symbolic name (destination). Destination could be virtual or real symbol. - * Callback destinations are not yet supported. - * @param id_from source symbol - * @param to destination name - */ -void rspamd_symcache_add_dependency (struct rspamd_symcache *cache, - gint id_from, const gchar *to, - gint virtual_id_from); - /** * Add delayed dependency that is resolved on cache post-load routine * @param cache diff --git a/src/libserver/symcache/symcache_c.cxx b/src/libserver/symcache/symcache_c.cxx index 29aa1d91d..5432c22f4 100644 --- a/src/libserver/symcache/symcache_c.cxx +++ b/src/libserver/symcache/symcache_c.cxx @@ -182,4 +182,12 @@ rspamd_symcache_inc_frequency(struct rspamd_symcache *_cache, struct rspamd_symc { auto *real_item = C_API_SYMCACHE_ITEM(item); real_item->inc_frequency(); +} + +void +rspamd_symcache_add_delayed_dependency (struct rspamd_symcache *cache, + const gchar *from, const gchar *to) +{ + auto *real_cache = C_API_SYMCACHE(cache); + real_cache->add_delayed_dependency(from, to); } \ No newline at end of file diff --git a/src/libserver/symcache/symcache_internal.hxx b/src/libserver/symcache/symcache_internal.hxx index 576a0bfd4..1bfd2f881 100644 --- a/src/libserver/symcache/symcache_internal.hxx +++ b/src/libserver/symcache/symcache_internal.hxx @@ -95,6 +95,8 @@ using order_generation_ptr = std::shared_ptr; struct delayed_cache_dependency { std::string from; std::string to; + + delayed_cache_dependency(std::string_view _from, std::string_view _to) : from(_from), to(_to) {} }; struct delayed_cache_condition { @@ -209,6 +211,19 @@ public: */ auto add_dependency(int id_from, std::string_view to, int virtual_id_from) -> void; + /** + * Add a delayed dependency between symbols that will be resolved on the init stage + * @param from + * @param to + */ + auto add_delayed_dependency(std::string_view from, std::string_view to) -> void { + if (!delayed_deps) { + delayed_deps = std::make_unique>(); + } + + delayed_deps->emplace_back(from, to); + } + /** * Initialises the symbols cache, must be called after all symbols are added * and the config file is loaded diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 607b97174..8c19671f1 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -2323,14 +2323,8 @@ lua_config_register_dependency (lua_State * L) child_id = luaL_checknumber (L, 2); parent = luaL_checkstring (L, 3); - msg_warn_config ("calling for obsolete method to register deps for symbol %d->%s", + return luaL_error(L,"calling for obsolete method to register deps for symbol %d->%s", child_id, parent); - - if (child_id > 0 && parent != NULL) { - - rspamd_symcache_add_dependency (cfg->cache, child_id, parent, - -1); - } } else { child = luaL_checkstring (L,2); -- 2.39.5