1
0
Fork 0
nih-plug/src/wrapper/clap/util.rs
Robbert van der Helm f581294d7b Update rustdoc formatting for links
Apparently it showed this text verbatim, and not in monospace.
2022-03-03 23:05:12 +01:00

46 lines
1.2 KiB
Rust

use std::ops::Deref;
/// Early exit out of a function with the specified return value when one of the passed pointers is
/// null.
macro_rules! check_null_ptr {
($ret:expr, $ptr:expr $(, $ptrs:expr)* $(, )?) => {
check_null_ptr_msg!("Null pointer passed to function", $ret, $ptr $(, $ptrs)*)
};
}
/// The same as [`check_null_ptr!`], but with a custom message.
macro_rules! check_null_ptr_msg {
($msg:expr, $ret:expr, $ptr:expr $(, $ptrs:expr)* $(, )?) => {
if $ptr.is_null() $(|| $ptrs.is_null())* {
nih_debug_assert_failure!($msg);
return $ret;
}
};
}
/// Send+Sync wrapper around CLAP host extension pointers.
pub struct ClapPtr<T> {
inner: *const T,
}
impl<T> Deref for ClapPtr<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
unsafe { &*self.inner }
}
}
unsafe impl<T> Send for ClapPtr<T> {}
unsafe impl<T> Sync for ClapPtr<T> {}
impl<T> ClapPtr<T> {
/// Create a wrapper around a CLAP object pointer.
///
/// # Safety
///
/// The pointer must point to a valid object with a lifetime that exceeds this object.
pub unsafe fn new(ptr: *const T) -> Self {
Self { inner: ptr }
}
}