From 2b789bd0570983e82533f9ed30c80312ac334694 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 14 Jun 2018 00:32:30 +0200 Subject: 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: `alloc` v.s. `allocator`, `error` v.s. `failure` --- src/liballoc/alloc.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/liballoc/alloc.rs') 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(ptr: Unique) { /// /// 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::().as_ptr(); let end = i.offset(layout.size() as isize); -- cgit 1.4.1-3-g733a5