Skip to content

Commit

Permalink
Promote debug assertion failures to warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
robbert-vdh committed Dec 30, 2023
1 parent 4511d9f commit 9a9b7cd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ state is to list breaking changes.
libraries that link against a different version of `raw_window_handle` than
the one used by NIH-plug itself by simply wrapping around
`ParentWindowHandle`.
- `nih_debug_assert*!()` failures are now promoted to a warning instead of a
debug message. This makes the non-fatal debug assertion failures easier to
spot.

## [2023-12-30]

Expand Down
16 changes: 8 additions & 8 deletions src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ macro_rules! nih_debug_assert {
if cfg!(test) {
debug_assert!($cond);
} else if cfg!(debug_assertions) && !$cond {
$crate::util::permit_alloc(|| $crate::log::debug!(concat!("Debug assertion failed: ", stringify!($cond))));
$crate::util::permit_alloc(|| $crate::log::warn!(concat!("Debug assertion failed: ", stringify!($cond))));
}
);
($cond:expr, $format:expr $(, $($args:tt)*)?) => (
#[allow(clippy::neg_cmp_op_on_partial_ord)]
if cfg!(test) {
debug_assert!($cond, $format, $($($args)*)?);
} else if cfg!(debug_assertions) && !$cond {
$crate::util::permit_alloc(|| $crate::log::debug!(concat!("Debug assertion failed: ", stringify!($cond), ", ", $format), $($($args)*)?));
$crate::util::permit_alloc(|| $crate::log::warn!(concat!("Debug assertion failed: ", stringify!($cond), ", ", $format), $($($args)*)?));
}
);
}
Expand All @@ -117,14 +117,14 @@ macro_rules! nih_debug_assert_failure {
if cfg!(test) {
debug_assert!(false, "Debug assertion failed");
} else if cfg!(debug_assertions) {
$crate::util::permit_alloc(|| $crate::log::debug!("Debug assertion failed"));
$crate::util::permit_alloc(|| $crate::log::warn!("Debug assertion failed"));
}
);
($format:expr $(, $($args:tt)*)?) => (
if cfg!(test) {
debug_assert!(false, concat!("Debug assertion failed: ", $format), $($($args)*)?);
} else if cfg!(debug_assertions) {
$crate::util::permit_alloc(|| $crate::log::debug!(concat!("Debug assertion failed: ", $format), $($($args)*)?));
$crate::util::permit_alloc(|| $crate::log::warn!(concat!("Debug assertion failed: ", $format), $($($args)*)?));
}
);
}
Expand All @@ -140,15 +140,15 @@ macro_rules! nih_debug_assert_eq {
if cfg!(test) {
debug_assert_eq!($left, $right);
} else if cfg!(debug_assertions) && $left != $right {
$crate::util::permit_alloc(|| $crate::log::debug!(concat!("Debug assertion failed: ", stringify!($left), " != ", stringify!($right))));
$crate::util::permit_alloc(|| $crate::log::warn!(concat!("Debug assertion failed: ", stringify!($left), " != ", stringify!($right))));
}
);
($left:expr, $right:expr, $format:expr $(, $($args:tt)*)?) => (
#[allow(clippy::neg_cmp_op_on_partial_ord)]
if cfg!(test) {
debug_assert_eq!($left, $right, $format, $($($args)*)?);
} else if cfg!(debug_assertions) && $left != $right {
$crate::util::permit_alloc(|| $crate::log::debug!(concat!("Debug assertion failed: ", stringify!($left), " != ", stringify!($right), ", ", $format), $($($args)*)?));
$crate::util::permit_alloc(|| $crate::log::warn!(concat!("Debug assertion failed: ", stringify!($left), " != ", stringify!($right), ", ", $format), $($($args)*)?));
}
);
}
Expand All @@ -164,15 +164,15 @@ macro_rules! nih_debug_assert_ne {
if cfg!(test) {
debug_assert_ne!($left, $right);
} else if cfg!(debug_assertions) && $left == $right {
$crate::util::permit_alloc(|| $crate::log::debug!(concat!("Debug assertion failed: ", stringify!($left), " == ", stringify!($right))));
$crate::util::permit_alloc(|| $crate::log::warn!(concat!("Debug assertion failed: ", stringify!($left), " == ", stringify!($right))));
}
);
($left:expr, $right:expr, $format:expr $(, $($args:tt)*)?) => (
#[allow(clippy::neg_cmp_op_on_partial_ord)]
if cfg!(test) {
debug_assert_ne!($left, $right, $format, $($($args)*)?);
} else if cfg!(debug_assertions) && $left == $right {
$crate::util::permit_alloc(|| $crate::log::debug!(concat!("Debug assertion failed: ", stringify!($left), " == ", stringify!($right), ", ", $format), $($($args)*)?));
$crate::util::permit_alloc(|| $crate::log::warn!(concat!("Debug assertion failed: ", stringify!($left), " == ", stringify!($right), ", ", $format), $($($args)*)?));
}
);
}
Expand Down

0 comments on commit 9a9b7cd

Please sign in to comment.