]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
configure: detect lua integer size
authorJason Ish <jason.ish@oisf.net>
Fri, 27 Sep 2019 21:33:45 +0000 (15:33 -0600)
committerVictor Julien <victor@inliniac.net>
Fri, 4 Oct 2019 10:26:51 +0000 (12:26 +0200)
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.

configure.ac
rust/Cargo.toml.in
rust/Makefile.am
rust/src/lua.rs

index 56f01a24a317b87cf43cb46465226d06a2e35379..14a87563ddc322e4f8fdb19903ca52d7b361b2bd 100644 (file)
 
     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 <lua.h> ]],
+            [[
+            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]),
index 75a77bf71ba7602764bc02cb96b5fb3fda1cdc10..02776af38472226e80c46613ef72d41a6db50478 100644 (file)
@@ -11,6 +11,7 @@ debug = true
 
 [features]
 lua = []
+lua_int8 = ["lua"]
 strict = []
 debug = []
 
index 05a9655182d91a1056a9f6cd1735af0b4574a7f7..c7482fcb851c5b8f3662085c45d91d6cfab0eb22 100644 (file)
@@ -20,7 +20,7 @@ RELEASE = --release
 endif
 
 if HAVE_LUA
-RUST_FEATURES +=       lua
+RUST_FEATURES +=       lua $(LUA_INT8)
 endif
 
 if DEBUG
index 75e636ccaef27d1331249acc090753fd5cf9357b..87cb8b3acf9cdf2b30965173d1a36f7395f7e08f 100644 (file)
@@ -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);
         }
     }
 }