pub trait c_voidMutExt
{
#[inline(always)]
fn unmap(self, length: usize);
}
macro_rules! debug_assert_self_is_not_null
{
($self: ident) =>
{
debug_assert!(!$self.is_null(), "self (address) can not be null");
}
}
impl c_voidMutExt for *mut c_void
{
#[inline(always)]
fn unmap(self, length: usize)
{
debug_assert_self_is_not_null!(self);
if length == 0
{
return;
}
let result = unsafe { pmem_unmap(self, length) };
if likely(result == 0)
{
return;
}
else if likely(result == -1)
{
match errno().0
{
E::EINVAL => panic!("EINVAL for pmem_unmap() implies a bad address or length"),
illegal @ _ => panic!("Error number '{}' should not occur for pmem_unmap()", illegal),
}
}
else
{
panic!("pmem_unmap() returned value '{}', not 0 or -1", result);
}
}
}