From 2614be26ab87ca9026618c8aedaad3a5ddddb15d Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Wed, 26 Jan 2022 20:51:34 +0100 Subject: [PATCH] Add an unconditional debug assertion failure macro --- src/debug.rs | 16 ++++++++++++++++ src/lib.rs | 1 + 2 files changed, 17 insertions(+) diff --git a/src/debug.rs b/src/debug.rs index 4dafe873..0931a281 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -45,6 +45,22 @@ macro_rules! nih_debug_assert { ); } +/// 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"); + } + ); + ($format:expr $(, $arg:tt)*) => ( + if cfg!(debug_assertions) { + nih_log!(concat!("Debug assertion failed: ", $format) $(, $arg)*); + } + ); +} + /// A `debug_assert_eq!()` analogue that prints the error with line number information instead of /// panicking. #[macro_export] diff --git a/src/lib.rs b/src/lib.rs index 781aa164..68ffaaeb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#[macro_use] pub mod debug; pub mod params; pub mod plugin;