diff options
author | kylo252 <[email protected]> | 2021-09-12 08:06:03 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2021-09-12 08:06:03 +0200 |
commit | 7a53fc63e083c0c48d8de361d82736f844c3c14a (patch) | |
tree | 6a88f0e299c48d735d4f02e5c9f35373eb517ec0 | |
parent | 23f535666ee5ce2690f823bb2cb88b843d329763 (diff) |
refactor: add 32bit support for impatient (#1527)
-rw-r--r-- | lua/impatient.lua | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lua/impatient.lua b/lua/impatient.lua index 85d3cb89..4bb83fb6 100644 --- a/lua/impatient.lua +++ b/lua/impatient.lua @@ -26,13 +26,17 @@ _G.__luacache = M local cachepack = {} -- using double for packing/unpacking numbers has no conversion overhead -local c_double = ffi.typeof "double[1]" -local sizeof_c_double = ffi.sizeof "double" +-- 32-bit ARM causes a bus error when casting to double, so use int there +local number_t = jit.arch ~= "arm" and "double" or "int" +ffi.cdef("typedef " .. number_t .. " number_t;") + +local c_number_t = ffi.typeof "number_t[1]" +local c_sizeof_number_t = ffi.sizeof "number_t" local out_buf = {} function out_buf.write_number(buf, num) - buf[#buf + 1] = ffi.string(c_double(num), sizeof_c_double) + buf[#buf + 1] = ffi.string(c_number_t(num), c_sizeof_number_t) end function out_buf.write_string(buf, str) @@ -50,8 +54,8 @@ function in_buf.read_number(buf) if buf.size < buf.pos then error "buffer access violation" end - local res = ffi.cast("double*", buf.ptr + buf.pos)[0] - buf.pos = buf.pos + sizeof_c_double + local res = ffi.cast("number_t*", buf.ptr + buf.pos)[0] + buf.pos = buf.pos + c_sizeof_number_t return res end |