2022-01-26 21:26:30 +11:00
|
|
|
/// Write something to the STDERR stream.
|
|
|
|
///
|
|
|
|
/// XXX: I don't think we need all of the log crate just for some simple logging, but maybe consider
|
|
|
|
/// integrating some other crate with this function if we need to log to some other place than
|
|
|
|
/// STDERR or if it needs to be done in release builds and we should thus try to avoid
|
|
|
|
/// allocations.
|
2022-01-26 21:34:47 +11:00
|
|
|
#[macro_export]
|
2022-01-26 21:26:30 +11:00
|
|
|
macro_rules! nih_log {
|
2022-01-29 00:47:26 +11:00
|
|
|
($format:expr $(, $($args:tt)*)?) => (
|
|
|
|
eprintln!(concat!("[", file!(), ":", line!(), "] ", $format), $($($args)*)?)
|
2022-01-26 21:26:30 +11:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-01-26 21:30:48 +11:00
|
|
|
/// A `debug_assert!()` analogue that prints the error with line number information instead of
|
|
|
|
/// panicking.
|
2022-01-26 21:26:30 +11:00
|
|
|
///
|
|
|
|
/// TODO: Detect if we're running under a debugger, and trigger a break if we are
|
2022-01-26 21:34:47 +11:00
|
|
|
#[macro_export]
|
2022-01-26 21:26:30 +11:00
|
|
|
macro_rules! nih_debug_assert {
|
2022-01-28 23:32:37 +11:00
|
|
|
($cond:expr $(,)?) => (
|
2022-01-26 21:26:30 +11:00
|
|
|
if cfg!(debug_assertions) && !$cond {
|
|
|
|
nih_log!(concat!("Debug assertion failed: ", stringify!($cond)));
|
|
|
|
}
|
|
|
|
);
|
2022-01-29 00:47:26 +11:00
|
|
|
($cond:expr, $format:expr $(, $($args:tt)*)?) => (
|
2022-01-26 21:26:30 +11:00
|
|
|
if cfg!(debug_assertions) && !$cond {
|
2022-01-29 00:47:26 +11:00
|
|
|
nih_log!(concat!("Debug assertion failed: ", stringify!($cond), ", ", $format), $($($args)*)?);
|
2022-01-26 21:26:30 +11:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2022-01-26 21:30:48 +11:00
|
|
|
|
2022-01-27 06:51:34 +11:00
|
|
|
/// An unconditional debug assertion failure, for if the condition has already been checked
|
|
|
|
/// elsewhere.
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! nih_debug_assert_failure {
|
|
|
|
() => (
|
|
|
|
if cfg!(debug_assertions) {
|
|
|
|
nih_log!("Debug assertion failed");
|
|
|
|
}
|
|
|
|
);
|
2022-01-29 00:47:26 +11:00
|
|
|
($format:expr $(, $($args:tt)*)?) => (
|
2022-01-27 06:51:34 +11:00
|
|
|
if cfg!(debug_assertions) {
|
2022-01-29 00:47:26 +11:00
|
|
|
nih_log!(concat!("Debug assertion failed: ", $format), $($($args)*)?);
|
2022-01-27 06:51:34 +11:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-01-26 21:30:48 +11:00
|
|
|
/// A `debug_assert_eq!()` analogue that prints the error with line number information instead of
|
|
|
|
/// panicking.
|
2022-01-26 21:34:47 +11:00
|
|
|
#[macro_export]
|
2022-01-26 21:30:48 +11:00
|
|
|
macro_rules! nih_debug_assert_eq {
|
2022-01-28 23:32:37 +11:00
|
|
|
($left:expr, $right:expr $(,)?) => (
|
2022-01-26 21:30:48 +11:00
|
|
|
if cfg!(debug_assertions) && $left != $right {
|
|
|
|
nih_log!(concat!("Debug assertion failed: ", stringify!($left), " != ", stringify!($right)));
|
|
|
|
}
|
|
|
|
);
|
2022-03-20 22:44:29 +11:00
|
|
|
($left:expr, $right:expr, $format:expr $(, $($args:tt)*)?) => (
|
2022-01-26 21:30:48 +11:00
|
|
|
if cfg!(debug_assertions) && $left != $right {
|
2022-01-29 00:47:26 +11:00
|
|
|
nih_log!(concat!("Debug assertion failed: ", stringify!($left), " != ", stringify!($right), ", ", $format), $($($args)*)?);
|
2022-01-26 21:30:48 +11:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-02-03 08:29:14 +11:00
|
|
|
/// A `debug_assert_ne!()` analogue that prints the error with line number information instead of
|
2022-01-26 21:30:48 +11:00
|
|
|
/// panicking.
|
2022-01-26 21:34:47 +11:00
|
|
|
#[macro_export]
|
2022-02-03 08:29:14 +11:00
|
|
|
macro_rules! nih_debug_assert_ne {
|
2022-01-28 23:32:37 +11:00
|
|
|
($left:expr, $right:expr $(,)?) => (
|
2022-01-26 21:30:48 +11:00
|
|
|
if cfg!(debug_assertions) && $left == $right {
|
|
|
|
nih_log!(concat!("Debug assertion failed: ", stringify!($left), " == ", stringify!($right)));
|
|
|
|
}
|
|
|
|
);
|
2022-03-20 22:44:29 +11:00
|
|
|
($left:expr, $right:expr, $format:expr $(, $($args:tt)*)?) => (
|
2022-01-26 21:30:48 +11:00
|
|
|
if cfg!(debug_assertions) && $left == $right {
|
2022-01-29 00:47:26 +11:00
|
|
|
nih_log!(concat!("Debug assertion failed: ", stringify!($left), " == ", stringify!($right), ", ", $format), $($($args)*)?);
|
2022-01-26 21:30:48 +11:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|