rust/ffi: move debug validations macros to ffi

Ticket: 7666
pull/15432/head
Philippe Antoine 4 months ago committed by Victor Julien
parent 6dff07b631
commit 5440e41314

@ -33,7 +33,7 @@ debug = true
[features]
strict = []
debug = []
debug-validate = []
debug-validate = ["suricata-ffi/debug-validate"]
ja3 = []
ja4 = []

@ -10,3 +10,4 @@ suricata-sys = { path = "../sys" }
[features]
debug = []
debug-validate = []

@ -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");
}
};
);

@ -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) => {

@ -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

Loading…
Cancel
Save