#[inline]
/// Wraps around a pre-existing value
pub fn wrap<'a, T: Sized>(mut t: T) -> InformationResult<'a, Self> {
let ptr = (&mut t as *mut T) as *mut u8;
let layout = Layout::for_value(&t);
println!("I get this far");
let ptr_new = unsafe{ std::alloc::realloc(ptr, layout, layout.size()) };
println!("... But this doesn't print");
std::alloc::set_alloc_error_hook(|_| {
println!("No error appears here, even though it crashes");
});
Ok(Self {
ptr: ptr_new,
len: size,
cursor: 0,
read_version: AtomicUsize::new(0),
write_version: AtomicUsize::new(0),
corrupt: false,
layout
})
}
The program fails at the realloc subroutine.
error: test failed, to rerun pass '-p hypervec --test primary'
Process finished with exit code -1073740940 (0xC0000374)
The re-alloc function states to use the same layout which was assigned for the pointer. I assume for_layout should do the same?
Is it possible to re-allocate without having to Copy around the bytes of the pointee? I am trying to minimize the number of copies and re-allocations overall