Implement init and init_offset on AllocInit and mark it unsafe

This commit is contained in:
Tim Diekmann 2020-03-29 01:47:05 +01:00
parent bf6a46db31
commit 3ade8ae660
3 changed files with 39 additions and 30 deletions

View file

@ -214,12 +214,12 @@ unsafe impl AllocRef for Global {
self.alloc(new_layout, init)
}
ReallocPlacement::MayMove => {
// `realloc` probably checks for `new_size > old_size` or something similar.
// `realloc` probably checks for `new_size > size` or something similar.
intrinsics::assume(new_size > size);
let ptr = realloc(ptr.as_ptr(), layout, new_size);
let mut memory =
let memory =
MemoryBlock { ptr: NonNull::new(ptr).ok_or(AllocErr)?, size: new_size };
memory.init_offset(init, size);
init.init_offset(memory, size);
Ok(memory)
}
}
@ -250,7 +250,7 @@ unsafe impl AllocRef for Global {
Ok(MemoryBlock { ptr: layout.dangling(), size: 0 })
}
ReallocPlacement::MayMove => {
// `realloc` probably checks for `new_size < old_size` or something similar.
// `realloc` probably checks for `new_size < size` or something similar.
intrinsics::assume(new_size < size);
let ptr = realloc(ptr.as_ptr(), layout, new_size);
Ok(MemoryBlock { ptr: NonNull::new(ptr).ok_or(AllocErr)?, size: new_size })