Auto merge of #75687 - TimDiekmann:realloc-align, r=Amanieu
Allow reallocation to different alignment in `AllocRef` The allocator-wg [has decided](https://github.com/rust-lang/wg-allocators/issues/5#issuecomment-672591112) to support reallocating to a different alignment in `AllocRef`. For more details please see the linked issue. r? @Amanieu closes https://github.com/rust-lang/wg-allocators/issues/5
This commit is contained in:
commit
ffd59bf9c6
5 changed files with 185 additions and 162 deletions
|
|
@ -48,7 +48,7 @@ unsafe fn test_triangle() -> bool {
|
|||
println!("allocate({:?}) = {:?}", layout, ptr);
|
||||
}
|
||||
|
||||
ptr.as_non_null_ptr().as_ptr()
|
||||
ptr.as_mut_ptr()
|
||||
}
|
||||
|
||||
unsafe fn deallocate(ptr: *mut u8, layout: Layout) {
|
||||
|
|
@ -65,23 +65,17 @@ unsafe fn test_triangle() -> bool {
|
|||
}
|
||||
|
||||
let memory = if new.size() > old.size() {
|
||||
Global.grow(
|
||||
NonNull::new_unchecked(ptr),
|
||||
old,
|
||||
new.size(),
|
||||
)
|
||||
Global.grow(NonNull::new_unchecked(ptr), old, new)
|
||||
} else {
|
||||
Global.shrink(NonNull::new_unchecked(ptr), old, new.size())
|
||||
Global.shrink(NonNull::new_unchecked(ptr), old, new)
|
||||
};
|
||||
|
||||
let ptr = 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, ptr);
|
||||
}
|
||||
ptr.as_non_null_ptr().as_ptr()
|
||||
ptr.as_mut_ptr()
|
||||
}
|
||||
|
||||
fn idx_to_size(i: usize) -> usize {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue