Use a macro for the null pointer checks
This commit is contained in:
parent
b9d38f5c39
commit
47f84081dd
|
@ -52,6 +52,16 @@ lazy_static! {
|
||||||
static ref BYPASS_PARAM_HASH: u32 = hash_param_id(BYPASS_PARAM_ID);
|
static ref BYPASS_PARAM_HASH: u32 = hash_param_id(BYPASS_PARAM_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Early exit out of a VST3 function when one of the passed pointers is null
|
||||||
|
macro_rules! check_null_ptr {
|
||||||
|
($ptr:expr $(, $ptrs:expr)* $(, )?) => {
|
||||||
|
if $ptr.is_null() $(|| $ptrs.is_null())* {
|
||||||
|
nih_debug_assert_failure!("Null pointer passed to function");
|
||||||
|
return kInvalidArgument;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#[VST3(implements(IComponent, IEditController, IAudioProcessor))]
|
#[VST3(implements(IComponent, IEditController, IAudioProcessor))]
|
||||||
pub struct Wrapper<P: Plugin> {
|
pub struct Wrapper<P: Plugin> {
|
||||||
/// The wrapped plugin instance.
|
/// The wrapped plugin instance.
|
||||||
|
@ -168,10 +178,7 @@ impl<P: Plugin> IComponent for Wrapper<P> {
|
||||||
index: i32,
|
index: i32,
|
||||||
info: *mut vst3_sys::vst::BusInfo,
|
info: *mut vst3_sys::vst::BusInfo,
|
||||||
) -> tresult {
|
) -> tresult {
|
||||||
if info.is_null() {
|
check_null_ptr!(info);
|
||||||
nih_debug_assert_failure!("Null pointer passed to function");
|
|
||||||
return kInvalidArgument;
|
|
||||||
}
|
|
||||||
|
|
||||||
match type_ {
|
match type_ {
|
||||||
t if t == vst3_sys::vst::MediaTypes::kAudio as i32 => {
|
t if t == vst3_sys::vst::MediaTypes::kAudio as i32 => {
|
||||||
|
@ -210,10 +217,7 @@ impl<P: Plugin> IComponent for Wrapper<P> {
|
||||||
in_info: *mut vst3_sys::vst::RoutingInfo,
|
in_info: *mut vst3_sys::vst::RoutingInfo,
|
||||||
out_info: *mut vst3_sys::vst::RoutingInfo,
|
out_info: *mut vst3_sys::vst::RoutingInfo,
|
||||||
) -> tresult {
|
) -> tresult {
|
||||||
if in_info.is_null() || out_info.is_null() {
|
check_null_ptr!(in_info, out_info);
|
||||||
nih_debug_assert_failure!("Null pointer passed to function");
|
|
||||||
return kInvalidArgument;
|
|
||||||
}
|
|
||||||
|
|
||||||
*out_info = mem::zeroed();
|
*out_info = mem::zeroed();
|
||||||
|
|
||||||
|
@ -291,10 +295,7 @@ impl<P: Plugin> IEditController for Wrapper<P> {
|
||||||
param_index: i32,
|
param_index: i32,
|
||||||
info: *mut vst3_sys::vst::ParameterInfo,
|
info: *mut vst3_sys::vst::ParameterInfo,
|
||||||
) -> tresult {
|
) -> tresult {
|
||||||
if info.is_null() {
|
check_null_ptr!(info);
|
||||||
nih_debug_assert_failure!("Null pointer passed to function");
|
|
||||||
return kInvalidArgument;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parameter index `self.param_ids.len()` is our own bypass parameter
|
// Parameter index `self.param_ids.len()` is our own bypass parameter
|
||||||
if param_index < 0 || param_index > self.param_hashes.len() as i32 {
|
if param_index < 0 || param_index > self.param_hashes.len() as i32 {
|
||||||
|
@ -339,10 +340,7 @@ impl<P: Plugin> IEditController for Wrapper<P> {
|
||||||
value_normalized: f64,
|
value_normalized: f64,
|
||||||
string: *mut TChar,
|
string: *mut TChar,
|
||||||
) -> tresult {
|
) -> tresult {
|
||||||
if string.is_null() {
|
check_null_ptr!(string);
|
||||||
nih_debug_assert_failure!("Null pointer passed to function");
|
|
||||||
return kInvalidArgument;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Somehow there's no length there, so we'll assume our own maximum
|
// Somehow there's no length there, so we'll assume our own maximum
|
||||||
let dest = &mut *(string as *mut [TChar; 128]);
|
let dest = &mut *(string as *mut [TChar; 128]);
|
||||||
|
@ -373,10 +371,7 @@ impl<P: Plugin> IEditController for Wrapper<P> {
|
||||||
string: *const TChar,
|
string: *const TChar,
|
||||||
value_normalized: *mut f64,
|
value_normalized: *mut f64,
|
||||||
) -> tresult {
|
) -> tresult {
|
||||||
if string.is_null() || value_normalized.is_null() {
|
check_null_ptr!(string, value_normalized);
|
||||||
nih_debug_assert_failure!("Null pointer passed to function");
|
|
||||||
return kInvalidArgument;
|
|
||||||
}
|
|
||||||
|
|
||||||
let string = match U16CStr::from_ptr_str(string as *const u16).to_string() {
|
let string = match U16CStr::from_ptr_str(string as *const u16).to_string() {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
|
@ -472,10 +467,7 @@ impl<P: Plugin> IAudioProcessor for Wrapper<P> {
|
||||||
outputs: *mut vst3_sys::vst::SpeakerArrangement,
|
outputs: *mut vst3_sys::vst::SpeakerArrangement,
|
||||||
num_outs: i32,
|
num_outs: i32,
|
||||||
) -> tresult {
|
) -> tresult {
|
||||||
if inputs.is_null() || outputs.is_null() {
|
check_null_ptr!(inputs, outputs);
|
||||||
nih_debug_assert_failure!("Null pointer passed to function");
|
|
||||||
return kInvalidArgument;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We currently only do single audio bus IO configurations
|
// We currently only do single audio bus IO configurations
|
||||||
if num_ins != 1 || num_outs != 1 {
|
if num_ins != 1 || num_outs != 1 {
|
||||||
|
@ -503,10 +495,7 @@ impl<P: Plugin> IAudioProcessor for Wrapper<P> {
|
||||||
index: i32,
|
index: i32,
|
||||||
arr: *mut vst3_sys::vst::SpeakerArrangement,
|
arr: *mut vst3_sys::vst::SpeakerArrangement,
|
||||||
) -> tresult {
|
) -> tresult {
|
||||||
if arr.is_null() {
|
check_null_ptr!(arr);
|
||||||
nih_debug_assert_failure!("Null pointer passed to function");
|
|
||||||
return kInvalidArgument;
|
|
||||||
}
|
|
||||||
|
|
||||||
let config = self.current_bus_config.borrow();
|
let config = self.current_bus_config.borrow();
|
||||||
match (dir, index) {
|
match (dir, index) {
|
||||||
|
@ -551,10 +540,7 @@ impl<P: Plugin> IAudioProcessor for Wrapper<P> {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn setup_processing(&self, setup: *const vst3_sys::vst::ProcessSetup) -> tresult {
|
unsafe fn setup_processing(&self, setup: *const vst3_sys::vst::ProcessSetup) -> tresult {
|
||||||
if setup.is_null() {
|
check_null_ptr!(setup);
|
||||||
nih_debug_assert_failure!("Null pointer passed to function");
|
|
||||||
return kInvalidArgument;
|
|
||||||
}
|
|
||||||
|
|
||||||
// There's no special handling for offline processing at the moment
|
// There's no special handling for offline processing at the moment
|
||||||
let setup = &*setup;
|
let setup = &*setup;
|
||||||
|
@ -589,10 +575,7 @@ impl<P: Plugin> IAudioProcessor for Wrapper<P> {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn process(&self, data: *mut vst3_sys::vst::ProcessData) -> tresult {
|
unsafe fn process(&self, data: *mut vst3_sys::vst::ProcessData) -> tresult {
|
||||||
if data.is_null() {
|
check_null_ptr!(data);
|
||||||
nih_debug_assert_failure!("Null pointer passed to function");
|
|
||||||
return kInvalidArgument;
|
|
||||||
}
|
|
||||||
|
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
@ -669,10 +652,7 @@ impl<P: Vst3Plugin> IPluginFactory for Factory<P> {
|
||||||
_iid: *const vst3_sys::IID,
|
_iid: *const vst3_sys::IID,
|
||||||
obj: *mut *mut vst3_sys::c_void,
|
obj: *mut *mut vst3_sys::c_void,
|
||||||
) -> tresult {
|
) -> tresult {
|
||||||
if cid.is_null() || obj.is_null() {
|
check_null_ptr!(cid, obj);
|
||||||
nih_debug_assert_failure!("Null pointer passed to function");
|
|
||||||
return kInvalidArgument;
|
|
||||||
}
|
|
||||||
|
|
||||||
if *cid != self.cid {
|
if *cid != self.cid {
|
||||||
return kNoInterface;
|
return kNoInterface;
|
||||||
|
|
Loading…
Reference in a new issue