1
0
Fork 0

Add more debug assertion macros

This commit is contained in:
Robbert van der Helm 2022-01-26 11:30:48 +01:00
parent 91518b82fd
commit 97cdfd33dd

View file

@ -26,8 +26,8 @@ macro_rules! nih_log {
);
}
/// A `debug_assert!()` analogue that prints the error instead with line number information instead
/// of panicking.
/// A `debug_assert!()` analogue that prints the error with line number information instead of
/// panicking.
///
/// TODO: Detect if we're running under a debugger, and trigger a break if we are
macro_rules! nih_debug_assert {
@ -42,3 +42,33 @@ macro_rules! nih_debug_assert {
}
);
}
/// A `debug_assert_eq!()` analogue that prints the error with line number information instead of
/// panicking.
macro_rules! nih_debug_assert_eq {
($left:expr, $right:expr) => (
if cfg!(debug_assertions) && $left != $right {
nih_log!(concat!("Debug assertion failed: ", stringify!($left), " != ", stringify!($right)));
}
);
(left:expr, $right:expr, $format:expr $(, $arg:tt)*) => (
if cfg!(debug_assertions) && $left != $right {
nih_log!(concat!("Debug assertion failed: ", stringify!($left), " != ", stringify!($right), ", ", $format) $(, $arg)*);
}
);
}
/// A `debug_assert_neq!()` analogue that prints the error with line number information instead of
/// panicking.
macro_rules! nih_debug_assert_neq {
($left:expr, $right:expr) => (
if cfg!(debug_assertions) && $left == $right {
nih_log!(concat!("Debug assertion failed: ", stringify!($left), " == ", stringify!($right)));
}
);
(left:expr, $right:expr, $format:expr $(, $arg:tt)*) => (
if cfg!(debug_assertions) && $left == $right {
nih_log!(concat!("Debug assertion failed: ", stringify!($left), " == ", stringify!($right), ", ", $format) $(, $arg)*);
}
);
}