improve lua 5.4 support OBS-URL: https://build.opensuse.org/package/show/server:mail/rspamd?expand=0&rev=67
113 lines
4.1 KiB
Diff
113 lines
4.1 KiB
Diff
From cdedeb9f4f3168293a1efe0347da753b6f812a5e Mon Sep 17 00:00:00 2001
|
|
From: "Tomohiro \"Tomo-p\" KATO" <tomop@teamgedoh.net>
|
|
Date: Tue, 16 Feb 2021 00:29:59 +0900
|
|
Subject: [PATCH] fix compatibility with lua-5.4
|
|
|
|
---
|
|
src/libserver/cfg_rcl.c | 3 +++
|
|
src/libstat/stat_config.c | 3 +++
|
|
src/lua/lua_thread_pool.cxx | 5 ++++-
|
|
src/plugins/fuzzy_check.c | 3 +++
|
|
src/plugins/lua/hfilter.lua | 4 ++--
|
|
src/plugins/lua/milter_headers.lua | 2 +-
|
|
6 files changed, 16 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c
|
|
index b19a1dedc2..d91ebf3aee 100644
|
|
--- a/src/libserver/cfg_rcl.c
|
|
+++ b/src/libserver/cfg_rcl.c
|
|
@@ -3571,6 +3571,9 @@ rspamd_rcl_maybe_apply_lua_transform (struct rspamd_config *cfg)
|
|
return;
|
|
}
|
|
else {
|
|
+#if LUA_VERSION_NUM >= 504
|
|
+ lua_settop(L, -2);
|
|
+#endif
|
|
if (lua_type (L, -1) != LUA_TFUNCTION) {
|
|
msg_warn_config ("lua script must return "
|
|
"function and not %s",
|
|
diff --git a/src/libstat/stat_config.c b/src/libstat/stat_config.c
|
|
index 17d0fdcc70..0c9ae2ed08 100644
|
|
--- a/src/libstat/stat_config.c
|
|
+++ b/src/libstat/stat_config.c
|
|
@@ -172,6 +172,9 @@ rspamd_stat_init (struct rspamd_config *cfg, struct ev_loop *ev_base)
|
|
lua_tostring (L, -1));
|
|
}
|
|
else {
|
|
+#if LUA_VERSION_NUM >= 504
|
|
+ lua_settop(L, -2);
|
|
+#endif
|
|
if (lua_type (L, -1) != LUA_TTABLE) {
|
|
msg_err_config ("lua stat must return "
|
|
"table and not %s",
|
|
diff --git a/src/lua/lua_thread_pool.cxx b/src/lua/lua_thread_pool.cxx
|
|
index 62da49482e..dc6c15163a 100644
|
|
--- a/src/lua/lua_thread_pool.cxx
|
|
+++ b/src/lua/lua_thread_pool.cxx
|
|
@@ -261,12 +261,15 @@ lua_thread_pool_restore_callback_full(struct lua_callback_state *cbs,
|
|
|
|
static gint
|
|
lua_do_resume_full(lua_State *L, gint narg, const gchar *loc) {
|
|
+#if LUA_VERSION_NUM >= 504
|
|
+ int nres;
|
|
+#endif
|
|
msg_debug_lua_threads ("%s: lua_do_resume_full", loc);
|
|
#if LUA_VERSION_NUM < 502
|
|
return lua_resume(L, narg);
|
|
#else
|
|
#if LUA_VERSION_NUM >= 504
|
|
- return lua_resume (L, NULL, narg, NULL);
|
|
+ return lua_resume (L, NULL, narg, &nres);
|
|
#else
|
|
return lua_resume (L, NULL, narg);
|
|
#endif
|
|
diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c
|
|
index 722daeacbd..ea8bcf7567 100644
|
|
--- a/src/plugins/fuzzy_check.c
|
|
+++ b/src/plugins/fuzzy_check.c
|
|
@@ -1006,6 +1006,9 @@ fuzzy_check_module_config (struct rspamd_config *cfg, bool validate)
|
|
fuzzy_module_ctx->enabled = FALSE;
|
|
}
|
|
else {
|
|
+#if LUA_VERSION_NUM >= 504
|
|
+ lua_settop(L, -2);
|
|
+#endif
|
|
if (lua_type (L, -1) != LUA_TTABLE) {
|
|
msg_err_config ("lua fuzzy must return "
|
|
"table and not %s",
|
|
diff --git a/src/plugins/lua/hfilter.lua b/src/plugins/lua/hfilter.lua
|
|
index 9179f63b80..3889eaa5bb 100644
|
|
--- a/src/plugins/lua/hfilter.lua
|
|
+++ b/src/plugins/lua/hfilter.lua
|
|
@@ -357,7 +357,7 @@ local function hfilter_callback(task)
|
|
local lines = html_text_part:get_lines_count()
|
|
if lines > 0 and lines < 2 then
|
|
task:insert_result('HFILTER_URL_ONELINE', 1.00,
|
|
- string.format('html:%d:%d', sc, lines))
|
|
+ string.format('html:%d:%d', math.floor(sc), lines))
|
|
end
|
|
end
|
|
end
|
|
@@ -376,7 +376,7 @@ local function hfilter_callback(task)
|
|
local lines = plain_text_part:get_lines_count()
|
|
if lines > 0 and lines < 2 then
|
|
task:insert_result('HFILTER_URL_ONELINE', 1.00,
|
|
- string.format('plain:%d:%d', rel, lines))
|
|
+ string.format('plain:%d:%d', math.floor(rel), lines))
|
|
end
|
|
end
|
|
end
|
|
diff --git a/src/plugins/lua/milter_headers.lua b/src/plugins/lua/milter_headers.lua
|
|
index 0dfaa9e030..1b58cee860 100644
|
|
--- a/src/plugins/lua/milter_headers.lua
|
|
+++ b/src/plugins/lua/milter_headers.lua
|
|
@@ -383,7 +383,7 @@ local function milter_headers(task)
|
|
if local_mod.remove then
|
|
remove[local_mod.header] = local_mod.remove
|
|
end
|
|
- add[local_mod.header] = string.rep(local_mod.char, score)
|
|
+ add[local_mod.header] = string.rep(local_mod.char, math.floor(score))
|
|
end
|
|
|
|
local function spam_header (class, name, value, remove_v)
|