diff options
| author | bors <bors@rust-lang.org> | 2018-06-19 19:22:12 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-06-19 19:22:12 +0000 |
| commit | d692ab406ebab720f99f950ac3e9aba1e01296af (patch) | |
| tree | dec63b7e24af649d8fc67dc3a838f097a5b0787c /src/liballoc | |
| parent | 6ec1b626ba06b51fc8c23ee1cd7e2788163c2265 (diff) | |
| parent | 2b789bd0570983e82533f9ed30c80312ac334694 (diff) | |
| download | rust-d692ab406ebab720f99f950ac3e9aba1e01296af.tar.gz rust-d692ab406ebab720f99f950ac3e9aba1e01296af.zip | |
Auto merge of #51543 - SimonSapin:oom, r=SimonSapin
Rename OOM to allocation error The acronym is not descriptive unless one has seen it before. * Rename the `oom` function to `handle_alloc_error`. It was **stabilized in 1.28**, so if we do this at all we need to land it this cycle. * Rename `set_oom_hook` to `set_alloc_error_hook` * Rename `take_oom_hook` to `take_alloc_error_hook` Bikeshed: `on` v.s. `for`, `alloc` v.s. `allocator`, `error` v.s. `failure`
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/alloc.rs | 14 | ||||
| -rw-r--r-- | src/liballoc/arc.rs | 4 | ||||
| -rw-r--r-- | src/liballoc/raw_vec.rs | 16 | ||||
| -rw-r--r-- | src/liballoc/rc.rs | 4 |
4 files changed, 21 insertions, 17 deletions
diff --git a/src/liballoc/alloc.rs b/src/liballoc/alloc.rs index 04c8063ffeb..84bd275df34 100644 --- a/src/liballoc/alloc.rs +++ b/src/liballoc/alloc.rs @@ -158,7 +158,7 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 { if !ptr.is_null() { ptr } else { - oom(layout) + handle_alloc_error(layout) } } } @@ -184,13 +184,13 @@ pub(crate) unsafe fn box_free<T: ?Sized>(ptr: Unique<T>) { /// /// The default behavior of this function is to print a message to standard error /// and abort the process. -/// It can be replaced with [`set_oom_hook`] and [`take_oom_hook`]. +/// It can be replaced with [`set_alloc_error_hook`] and [`take_alloc_error_hook`]. /// -/// [`set_oom_hook`]: ../../std/alloc/fn.set_oom_hook.html -/// [`take_oom_hook`]: ../../std/alloc/fn.take_oom_hook.html +/// [`set_alloc_error_hook`]: ../../std/alloc/fn.set_alloc_error_hook.html +/// [`take_alloc_error_hook`]: ../../std/alloc/fn.take_alloc_error_hook.html #[stable(feature = "global_alloc", since = "1.28.0")] #[rustc_allocator_nounwind] -pub fn oom(layout: Layout) -> ! { +pub fn handle_alloc_error(layout: Layout) -> ! { #[allow(improper_ctypes)] extern "Rust" { #[lang = "oom"] @@ -204,14 +204,14 @@ mod tests { extern crate test; use self::test::Bencher; use boxed::Box; - use alloc::{Global, Alloc, Layout, oom}; + use alloc::{Global, Alloc, Layout, handle_alloc_error}; #[test] fn allocate_zeroed() { unsafe { let layout = Layout::from_size_align(1024, 1).unwrap(); let ptr = Global.alloc_zeroed(layout.clone()) - .unwrap_or_else(|_| oom(layout)); + .unwrap_or_else(|_| handle_alloc_error(layout)); let mut i = ptr.cast::<u8>().as_ptr(); let end = i.offset(layout.size() as isize); diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index e3369f0a5b5..0fbd1408f64 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -32,7 +32,7 @@ use core::hash::{Hash, Hasher}; use core::{isize, usize}; use core::convert::From; -use alloc::{Global, Alloc, Layout, box_free, oom}; +use alloc::{Global, Alloc, Layout, box_free, handle_alloc_error}; use boxed::Box; use string::String; use vec::Vec; @@ -554,7 +554,7 @@ impl<T: ?Sized> Arc<T> { let layout = Layout::for_value(&*fake_ptr); let mem = Global.alloc(layout) - .unwrap_or_else(|_| oom(layout)); + .unwrap_or_else(|_| handle_alloc_error(layout)); // Initialize the real ArcInner let inner = set_data_ptr(ptr as *mut T, mem.as_ptr() as *mut u8) as *mut ArcInner<T>; diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs index d1f140e96a3..2369ce648fd 100644 --- a/src/liballoc/raw_vec.rs +++ b/src/liballoc/raw_vec.rs @@ -14,7 +14,7 @@ use core::ops::Drop; use core::ptr::{self, NonNull, Unique}; use core::slice; -use alloc::{Alloc, Layout, Global, oom}; +use alloc::{Alloc, Layout, Global, handle_alloc_error}; use alloc::CollectionAllocErr; use alloc::CollectionAllocErr::*; use boxed::Box; @@ -104,7 +104,7 @@ impl<T, A: Alloc> RawVec<T, A> { }; match result { Ok(ptr) => ptr.cast(), - Err(_) => oom(layout), + Err(_) => handle_alloc_error(layout), } }; @@ -319,7 +319,9 @@ impl<T, A: Alloc> RawVec<T, A> { new_size); match ptr_res { Ok(ptr) => (new_cap, ptr.cast().into()), - Err(_) => oom(Layout::from_size_align_unchecked(new_size, cur.align())), + Err(_) => handle_alloc_error( + Layout::from_size_align_unchecked(new_size, cur.align()) + ), } } None => { @@ -328,7 +330,7 @@ impl<T, A: Alloc> RawVec<T, A> { let new_cap = if elem_size > (!0) / 8 { 1 } else { 4 }; match self.a.alloc_array::<T>(new_cap) { Ok(ptr) => (new_cap, ptr.into()), - Err(_) => oom(Layout::array::<T>(new_cap).unwrap()), + Err(_) => handle_alloc_error(Layout::array::<T>(new_cap).unwrap()), } } }; @@ -611,7 +613,9 @@ impl<T, A: Alloc> RawVec<T, A> { old_layout, new_size) { Ok(p) => self.ptr = p.cast().into(), - Err(_) => oom(Layout::from_size_align_unchecked(new_size, align)), + Err(_) => handle_alloc_error( + Layout::from_size_align_unchecked(new_size, align) + ), } } self.cap = amount; @@ -673,7 +677,7 @@ impl<T, A: Alloc> RawVec<T, A> { }; match (&res, fallibility) { - (Err(AllocErr), Infallible) => oom(new_layout), + (Err(AllocErr), Infallible) => handle_alloc_error(new_layout), _ => {} } diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 84a6ecf7103..32d624e8fbc 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -259,7 +259,7 @@ use core::ops::CoerceUnsized; use core::ptr::{self, NonNull}; use core::convert::From; -use alloc::{Global, Alloc, Layout, box_free, oom}; +use alloc::{Global, Alloc, Layout, box_free, handle_alloc_error}; use string::String; use vec::Vec; @@ -662,7 +662,7 @@ impl<T: ?Sized> Rc<T> { let layout = Layout::for_value(&*fake_ptr); let mem = Global.alloc(layout) - .unwrap_or_else(|_| oom(layout)); + .unwrap_or_else(|_| handle_alloc_error(layout)); // Initialize the real RcBox let inner = set_data_ptr(ptr as *mut T, mem.as_ptr() as *mut u8) as *mut RcBox<T>; |
