From: Jason Ish Date: Fri, 27 Sep 2019 21:33:45 +0000 (-0600) Subject: configure: detect lua integer size X-Git-Tag: suricata-5.0.0~99 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f9c9548b74235647c57068c3962acce210a02b03;p=thirdparty%2Fsuricata.git configure: detect lua integer size Lua 5.1 and 5.3 use a different integer size. Run a test program to set the integer size used in the Rust FFI layer to Rust. --- diff --git a/configure.ac b/configure.ac index 56f01a24a3..14a87563dd 100644 --- a/configure.ac +++ b/configure.ac @@ -2117,6 +2117,25 @@ AM_CONDITIONAL([HAVE_LUA], [test "x$enable_lua" != "xno"]) + # If Lua is enabled, test the integer size. + if test "x$enable_lua" = "xyes"; then + AC_MSG_CHECKING([size of lua integer]) + AC_RUN_IFELSE([AC_LANG_PROGRAM([[ #include ]], + [[ + if (sizeof(lua_Integer) == 8) { + exit(1); + } + exit(0); + ]])], + [ + AC_MSG_RESULT([4]) + ], + [ + AC_MSG_RESULT([8]) + AC_SUBST([LUA_INT8], ["lua_int8"]) + ]) + fi + # libmaxminddb AC_ARG_ENABLE(geoip, AS_HELP_STRING([--enable-geoip],[Enable GeoIP2 support]), diff --git a/rust/Cargo.toml.in b/rust/Cargo.toml.in index 75a77bf71b..02776af384 100644 --- a/rust/Cargo.toml.in +++ b/rust/Cargo.toml.in @@ -11,6 +11,7 @@ debug = true [features] lua = [] +lua_int8 = ["lua"] strict = [] debug = [] diff --git a/rust/Makefile.am b/rust/Makefile.am index 05a9655182..c7482fcb85 100644 --- a/rust/Makefile.am +++ b/rust/Makefile.am @@ -20,7 +20,7 @@ RELEASE = --release endif if HAVE_LUA -RUST_FEATURES += lua +RUST_FEATURES += lua $(LUA_INT8) endif if DEBUG diff --git a/rust/src/lua.rs b/rust/src/lua.rs index 75e636ccae..87cb8b3acf 100644 --- a/rust/src/lua.rs +++ b/rust/src/lua.rs @@ -19,6 +19,12 @@ use std::os::raw::c_char; use std::os::raw::c_int; use std::os::raw::c_long; +#[cfg(feature = "lua_int8")] +type LuaInteger = i64; + +#[cfg(not(feature = "lua_int8"))] +type LuaInteger = i32; + /// The Rust place holder for lua_State. pub enum CLuaState {} @@ -26,7 +32,7 @@ extern { fn lua_createtable(lua: *mut CLuaState, narr: c_int, nrec: c_int); fn lua_settable(lua: *mut CLuaState, idx: c_long); fn lua_pushlstring(lua: *mut CLuaState, s: *const c_char, len: usize); - fn lua_pushinteger(lua: *mut CLuaState, n: c_long); + fn lua_pushinteger(lua: *mut CLuaState, n: LuaInteger); } pub struct LuaState { @@ -55,7 +61,7 @@ impl LuaState { pub fn pushinteger(&self, val: i64) { unsafe { - lua_pushinteger(self.lua, val as c_long); + lua_pushinteger(self.lua, val as LuaInteger); } } }