1
Fork 0

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`
This commit is contained in:
Simon Sapin 2018-06-14 00:32:30 +02:00
parent b36917b331
commit 2b789bd057
10 changed files with 72 additions and 64 deletions

View file

@ -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),
_ => {}
}