diff options
| author | XAMPPRocky <4464295+XAMPPRocky@users.noreply.github.com> | 2020-02-26 21:39:30 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-26 21:39:30 +0100 |
| commit | 526280a853f31bbc3120334dfe46e19ea4dbaa25 (patch) | |
| tree | cd35561be4cdcd7591d98bae715726c0e40995b7 /src/liballoc/alloc.rs | |
| parent | e7a344fb745a0a663e21be947b2619df05df6d31 (diff) | |
| parent | abc3073c92df034636a823c5382ece2186d22b9e (diff) | |
| download | rust-526280a853f31bbc3120334dfe46e19ea4dbaa25.tar.gz rust-526280a853f31bbc3120334dfe46e19ea4dbaa25.zip | |
Merge branch 'master' into relnotes-1.42.0
Diffstat (limited to 'src/liballoc/alloc.rs')
| -rw-r--r-- | src/liballoc/alloc.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/liballoc/alloc.rs b/src/liballoc/alloc.rs index 9fb0de63e6f..f41404bf8ca 100644 --- a/src/liballoc/alloc.rs +++ b/src/liballoc/alloc.rs @@ -200,21 +200,27 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 { align as *mut u8 } else { let layout = Layout::from_size_align_unchecked(size, align); - let ptr = alloc(layout); - if !ptr.is_null() { ptr } else { handle_alloc_error(layout) } + match Global.alloc(layout) { + Ok(ptr) => ptr.as_ptr(), + Err(_) => handle_alloc_error(layout), + } } } #[cfg_attr(not(test), lang = "box_free")] #[inline] +// This signature has to be the same as `Box`, otherwise an ICE will happen. +// When an additional parameter to `Box` is added (like `A: AllocRef`), this has to be added here as +// well. +// For example if `Box` is changed to `struct Box<T: ?Sized, A: AllocRef>(Unique<T>, A)`, +// this function has to be changed to `fn box_free<T: ?Sized, A: AllocRef>(Unique<T>, A)` as well. pub(crate) unsafe fn box_free<T: ?Sized>(ptr: Unique<T>) { - let ptr = ptr.as_ptr(); - let size = size_of_val(&*ptr); - let align = min_align_of_val(&*ptr); + let size = size_of_val(ptr.as_ref()); + let align = min_align_of_val(ptr.as_ref()); // We do not allocate for Box<T> when T is ZST, so deallocation is also not necessary. if size != 0 { let layout = Layout::from_size_align_unchecked(size, align); - dealloc(ptr as *mut u8, layout); + Global.dealloc(ptr.cast().into(), layout); } } |
