From 5440e41314f30c2d7f6b318fc8f59956414ba806 Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Mon, 11 May 2026 22:18:38 +0200 Subject: [PATCH] rust/ffi: move debug validations macros to ffi Ticket: 7666 --- rust/Cargo.toml.in | 2 +- rust/ffi/Cargo.toml.in | 1 + rust/ffi/src/debug.rs | 33 +++++++++++++++++++++++++++++++++ rust/src/debug.rs | 33 --------------------------------- rust/src/jsonbuilder.rs | 2 +- 5 files changed, 36 insertions(+), 35 deletions(-) diff --git a/rust/Cargo.toml.in b/rust/Cargo.toml.in index 92b3daff6a..f1eb9d2efa 100644 --- a/rust/Cargo.toml.in +++ b/rust/Cargo.toml.in @@ -33,7 +33,7 @@ debug = true [features] strict = [] debug = [] -debug-validate = [] +debug-validate = ["suricata-ffi/debug-validate"] ja3 = [] ja4 = [] diff --git a/rust/ffi/Cargo.toml.in b/rust/ffi/Cargo.toml.in index f8f0d6be96..cd8d48a2de 100644 --- a/rust/ffi/Cargo.toml.in +++ b/rust/ffi/Cargo.toml.in @@ -10,3 +10,4 @@ suricata-sys = { path = "../sys" } [features] debug = [] +debug-validate = [] diff --git a/rust/ffi/src/debug.rs b/rust/ffi/src/debug.rs index 7c0ffcff48..dce64dcc32 100644 --- a/rust/ffi/src/debug.rs +++ b/rust/ffi/src/debug.rs @@ -191,3 +191,36 @@ macro_rules! SCFatalErrorOnInit { $crate::debug::fatalerror(&format!($($arg)*)); } } + +#[cfg(not(feature = "debug-validate"))] +#[macro_export] +macro_rules! debug_validate_fail ( + ($msg:expr) => {}; +); + +#[cfg(feature = "debug-validate")] +#[macro_export] +macro_rules! debug_validate_fail ( + ($msg:expr) => { + // Wrap in a conditional to prevent unreachable code warning in caller. + if true { + panic!($msg); + } + }; +); + +#[cfg(not(feature = "debug-validate"))] +#[macro_export] +macro_rules! debug_validate_bug_on ( + ($item:expr) => {}; +); + +#[cfg(feature = "debug-validate")] +#[macro_export] +macro_rules! debug_validate_bug_on ( + ($item:expr) => { + if $item { + panic!("Condition check failed"); + } + }; +); diff --git a/rust/src/debug.rs b/rust/src/debug.rs index d8b22dad53..ecee7f5da8 100644 --- a/rust/src/debug.rs +++ b/rust/src/debug.rs @@ -174,39 +174,6 @@ macro_rules!SCFatalErrorOnInit { } } -#[cfg(not(feature = "debug-validate"))] -#[macro_export] -macro_rules! debug_validate_bug_on ( - ($item:expr) => {}; -); - -#[cfg(feature = "debug-validate")] -#[macro_export] -macro_rules! debug_validate_bug_on ( - ($item:expr) => { - if $item { - panic!("Condition check failed"); - } - }; -); - -#[cfg(not(feature = "debug-validate"))] -#[macro_export] -macro_rules! debug_validate_fail ( - ($msg:expr) => {}; -); - -#[cfg(feature = "debug-validate")] -#[macro_export] -macro_rules! debug_validate_fail ( - ($msg:expr) => { - // Wrap in a conditional to prevent unreachable code warning in caller. - if true { - panic!($msg); - } - }; -); - #[macro_export] macro_rules! unwrap_or_return ( ($e:expr, $r:expr) => { diff --git a/rust/src/jsonbuilder.rs b/rust/src/jsonbuilder.rs index b62ab18e3a..f4638bee62 100644 --- a/rust/src/jsonbuilder.rs +++ b/rust/src/jsonbuilder.rs @@ -1219,11 +1219,11 @@ mod test { } #[test] - #[cfg(not(feature = "debug-validate"))] fn test_array_in_object() -> Result<(), JsonError> { let mut js = JsonBuilder::try_new_object().unwrap(); // Attempt to add an item, should fail. + #[cfg(not(feature = "debug-validate"))] assert_eq!( js.append_string("will fail").err().unwrap(), JsonError::InvalidState