realloc with a new size only, not a full new layout.

Changing the alignment with realloc is not supported.
This commit is contained in:
Simon Sapin 2018-04-04 17:19:16 +02:00
parent b017742136
commit c957e99b30
5 changed files with 73 additions and 101 deletions

View file

@ -91,21 +91,17 @@ unsafe impl Alloc for Global {
unsafe fn realloc(&mut self,
ptr: *mut u8,
layout: Layout,
new_layout: Layout)
new_size: usize)
-> Result<*mut u8, AllocErr>
{
if layout.align() == new_layout.align() {
#[cfg(not(stage0))]
let ptr = __rust_realloc(ptr, layout.size(), layout.align(), new_layout.size());
#[cfg(stage0)]
let ptr = __rust_realloc(ptr, layout.size(), layout.align(),
new_layout.size(), new_layout.align(), &mut 0);
#[cfg(not(stage0))]
let ptr = __rust_realloc(ptr, layout.size(), layout.align(), new_size);
#[cfg(stage0)]
let ptr = __rust_realloc(ptr, layout.size(), layout.align(),
new_size, layout.align(), &mut 0);
if !ptr.is_null() {
Ok(ptr)
} else {
Err(AllocErr)
}
if !ptr.is_null() {
Ok(ptr)
} else {
Err(AllocErr)
}