From 0fa394247f16ba7379229440b00213bb04df57f2 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sun, 6 Mar 2022 15:00:20 +0100 Subject: [PATCH] Add a permit_alloc function Since assert_no_alloc also hides panic messages which can make debugging more difficult: https://github.com/Windfisch/rust-assert-no-alloc/issues/4 --- src/util.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/util.rs b/src/util.rs index f15dc5d7..7dd5318b 100644 --- a/src/util.rs +++ b/src/util.rs @@ -7,6 +7,20 @@ pub use stft::StftHelper; pub const MINUS_INFINITY_DB: f32 = -100.0; +/// Temporarily allow allocations within `func` if NIH-plug was configured with the +/// `assert_process_allocs` feature. +#[cfg(all(debug_assertions, feature = "assert_process_allocs"))] +pub fn permit_alloc T>(func: F) -> T { + assert_no_alloc::permit_alloc(func) +} + +/// Temporarily allow allocations within `func` if NIH-plug was configured with the +/// `assert_process_allocs` feature. +#[cfg(not(all(debug_assertions, feature = "assert_process_allocs")))] +pub fn permit_alloc T>(func: F) -> T { + func +} + /// Convert decibels to a voltage gain ratio, treating anything below -100 dB as minus infinity. pub fn db_to_gain(dbs: f32) -> f32 { if dbs > MINUS_INFINITY_DB {