From: Vsevolod Stakhov Date: Thu, 2 Jul 2026 08:37:33 +0000 (+0100) Subject: [Test] static_embed: pack fixture floats via rspamd_util.pack X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F6118%2Fhead;p=thirdparty%2Frspamd.git [Test] static_embed: pack fixture floats via rspamd_util.pack math.frexp was removed in Lua 5.4, so the hand-rolled float32 packer broke the test run on non-LuaJIT builds; rspamd_util.pack provides string.pack semantics on every supported Lua version. --- diff --git a/test/lua/unit/static_embed.lua b/test/lua/unit/static_embed.lua index fbf001a7a4..3a2d837552 100644 --- a/test/lua/unit/static_embed.lua +++ b/test/lua/unit/static_embed.lua @@ -20,25 +20,10 @@ context("Static embed model", function() return path end - -- Pack a float32 little-endian without FFI; all fixture values are - -- exactly representable so the conversion is lossless + -- Pack a float32 little-endian (string.pack semantics, works on any Lua + -- version); all fixture values are exactly representable in float32 local function f32_le(x) - if x == 0 then - return string.char(0, 0, 0, 0) - end - local sign = 0 - if x < 0 then - sign = 1 - x = -x - end - local m, e = math.frexp(x) -- x = m * 2^e, m in [0.5, 1) - local exp = e + 126 -- biased exponent of 1.f * 2^(e-1) - local frac = math.floor((m * 2 - 1) * 2 ^ 23 + 0.5) - return string.char( - frac % 256, - math.floor(frac / 256) % 256, - math.floor(frac / 65536) + (exp % 2) * 128, - sign * 128 + math.floor(exp / 2)) + return rspamd_util.pack('