diff options
| author | Simon Sapin <simon.sapin@exyr.org> | 2018-04-04 17:19:16 +0200 |
|---|---|---|
| committer | Simon Sapin <simon.sapin@exyr.org> | 2018-04-12 22:53:13 +0200 |
| commit | c957e99b305ecee113442a7ce0edd6b565200ca9 (patch) | |
| tree | 02c7f8f7f8f35577d74dfb057625a2a4dae717a7 /src/liballoc/alloc.rs | |
| parent | b017742136a5d02b6ba0f2080e97d18a8bfeba4b (diff) | |
| download | rust-c957e99b305ecee113442a7ce0edd6b565200ca9.tar.gz rust-c957e99b305ecee113442a7ce0edd6b565200ca9.zip | |
realloc with a new size only, not a full new layout.
Changing the alignment with realloc is not supported.
Diffstat (limited to 'src/liballoc/alloc.rs')
| -rw-r--r-- | src/liballoc/alloc.rs | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/liballoc/alloc.rs b/src/liballoc/alloc.rs index a7b5864016c..a6fc8d5004c 100644 --- a/src/liballoc/alloc.rs +++ b/src/liballoc/alloc.rs @@ -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); - - if !ptr.is_null() { - Ok(ptr) - } else { - Err(AllocErr) - } + #[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) } |
