// well enough to reproduce (and illustrate) the bug from #16687.
#![feature(allocator_api)]
+#![feature(slice_ptr_get)]
-use std::alloc::{handle_alloc_error, AllocInit, AllocRef, Global, Layout, ReallocPlacement};
+use std::alloc::{handle_alloc_error, AllocRef, Global, Layout};
use std::ptr::{self, NonNull};
fn main() {
println!("allocate({:?})", layout);
}
- let memory = Global
- .alloc(layout, AllocInit::Uninitialized)
- .unwrap_or_else(|_| handle_alloc_error(layout));
+ let ptr = Global.alloc(layout).unwrap_or_else(|_| handle_alloc_error(layout));
if PRINT {
- println!("allocate({:?}) = {:?}", layout, memory.ptr);
+ println!("allocate({:?}) = {:?}", layout, ptr);
}
- memory.ptr.cast().as_ptr()
+ ptr.as_mut_ptr()
}
unsafe fn deallocate(ptr: *mut u8, layout: Layout) {
}
let memory = if new.size() > old.size() {
- Global.grow(
- NonNull::new_unchecked(ptr),
- old,
- new.size(),
- ReallocPlacement::MayMove,
- AllocInit::Uninitialized,
- )
+ Global.grow(NonNull::new_unchecked(ptr), old, new)
} else {
- Global.shrink(NonNull::new_unchecked(ptr), old, new.size(), ReallocPlacement::MayMove)
+ Global.shrink(NonNull::new_unchecked(ptr), old, new)
};
- let memory = memory.unwrap_or_else(|_| {
- handle_alloc_error(Layout::from_size_align_unchecked(new.size(), old.align()))
- });
+ let ptr = memory.unwrap_or_else(|_| handle_alloc_error(new));
if PRINT {
- println!("reallocate({:?}, old={:?}, new={:?}) = {:?}", ptr, old, new, memory.ptr);
+ println!("reallocate({:?}, old={:?}, new={:?}) = {:?}", ptr, old, new, ptr);
}
- memory.ptr.cast().as_ptr()
+ ptr.as_mut_ptr()
}
fn idx_to_size(i: usize) -> usize {