Remove the now-unit-struct AllocErr parameter of oom()
This commit is contained in:
parent
86753ce1cc
commit
157ff8cd05
12 changed files with 28 additions and 28 deletions
|
@ -136,8 +136,8 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
|
||||||
align as *mut u8
|
align as *mut u8
|
||||||
} else {
|
} else {
|
||||||
let layout = Layout::from_size_align_unchecked(size, align);
|
let layout = Layout::from_size_align_unchecked(size, align);
|
||||||
Global.alloc(layout).unwrap_or_else(|err| {
|
Global.alloc(layout).unwrap_or_else(|_| {
|
||||||
Global.oom(err)
|
Global.oom()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -166,7 +166,7 @@ mod tests {
|
||||||
unsafe {
|
unsafe {
|
||||||
let layout = Layout::from_size_align(1024, 1).unwrap();
|
let layout = Layout::from_size_align(1024, 1).unwrap();
|
||||||
let ptr = Global.alloc_zeroed(layout.clone())
|
let ptr = Global.alloc_zeroed(layout.clone())
|
||||||
.unwrap_or_else(|e| Global.oom(e));
|
.unwrap_or_else(|_| Global.oom());
|
||||||
|
|
||||||
let end = ptr.offset(layout.size() as isize);
|
let end = ptr.offset(layout.size() as isize);
|
||||||
let mut i = ptr;
|
let mut i = ptr;
|
||||||
|
|
|
@ -555,7 +555,7 @@ impl<T: ?Sized> Arc<T> {
|
||||||
let layout = Layout::for_value(&*fake_ptr);
|
let layout = Layout::for_value(&*fake_ptr);
|
||||||
|
|
||||||
let mem = Global.alloc(layout)
|
let mem = Global.alloc(layout)
|
||||||
.unwrap_or_else(|e| Global.oom(e));
|
.unwrap_or_else(|_| Global.oom());
|
||||||
|
|
||||||
// Initialize the real ArcInner
|
// Initialize the real ArcInner
|
||||||
let inner = set_data_ptr(ptr as *mut T, mem) as *mut ArcInner<T>;
|
let inner = set_data_ptr(ptr as *mut T, mem) as *mut ArcInner<T>;
|
||||||
|
|
|
@ -52,8 +52,8 @@ unsafe impl<T> Alloc for T where T: CoreAlloc {
|
||||||
CoreAlloc::dealloc(self, ptr, layout)
|
CoreAlloc::dealloc(self, ptr, layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn oom(&mut self, err: AllocErr) -> ! {
|
fn oom(&mut self, _: AllocErr) -> ! {
|
||||||
CoreAlloc::oom(self, err)
|
CoreAlloc::oom(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usable_size(&self, layout: &Layout) -> (usize, usize) {
|
fn usable_size(&self, layout: &Layout) -> (usize, usize) {
|
||||||
|
|
|
@ -100,7 +100,7 @@ impl<T, A: Alloc> RawVec<T, A> {
|
||||||
};
|
};
|
||||||
match result {
|
match result {
|
||||||
Ok(ptr) => ptr,
|
Ok(ptr) => ptr,
|
||||||
Err(err) => a.oom(err),
|
Err(_) => a.oom(),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -316,7 +316,7 @@ impl<T, A: Alloc> RawVec<T, A> {
|
||||||
new_layout);
|
new_layout);
|
||||||
match ptr_res {
|
match ptr_res {
|
||||||
Ok(ptr) => (new_cap, Unique::new_unchecked(ptr as *mut T)),
|
Ok(ptr) => (new_cap, Unique::new_unchecked(ptr as *mut T)),
|
||||||
Err(e) => self.a.oom(e),
|
Err(_) => self.a.oom(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
@ -325,7 +325,7 @@ impl<T, A: Alloc> RawVec<T, A> {
|
||||||
let new_cap = if elem_size > (!0) / 8 { 1 } else { 4 };
|
let new_cap = if elem_size > (!0) / 8 { 1 } else { 4 };
|
||||||
match self.a.alloc_array::<T>(new_cap) {
|
match self.a.alloc_array::<T>(new_cap) {
|
||||||
Ok(ptr) => (new_cap, ptr.into()),
|
Ok(ptr) => (new_cap, ptr.into()),
|
||||||
Err(e) => self.a.oom(e),
|
Err(_) => self.a.oom(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -444,7 +444,7 @@ impl<T, A: Alloc> RawVec<T, A> {
|
||||||
pub fn reserve_exact(&mut self, used_cap: usize, needed_extra_cap: usize) {
|
pub fn reserve_exact(&mut self, used_cap: usize, needed_extra_cap: usize) {
|
||||||
match self.try_reserve_exact(used_cap, needed_extra_cap) {
|
match self.try_reserve_exact(used_cap, needed_extra_cap) {
|
||||||
Err(CapacityOverflow) => panic!("capacity overflow"),
|
Err(CapacityOverflow) => panic!("capacity overflow"),
|
||||||
Err(AllocErr(e)) => self.a.oom(e),
|
Err(AllocErr(_)) => self.a.oom(),
|
||||||
Ok(()) => { /* yay */ }
|
Ok(()) => { /* yay */ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -554,7 +554,7 @@ impl<T, A: Alloc> RawVec<T, A> {
|
||||||
pub fn reserve(&mut self, used_cap: usize, needed_extra_cap: usize) {
|
pub fn reserve(&mut self, used_cap: usize, needed_extra_cap: usize) {
|
||||||
match self.try_reserve(used_cap, needed_extra_cap) {
|
match self.try_reserve(used_cap, needed_extra_cap) {
|
||||||
Err(CapacityOverflow) => panic!("capacity overflow"),
|
Err(CapacityOverflow) => panic!("capacity overflow"),
|
||||||
Err(AllocErr(e)) => self.a.oom(e),
|
Err(AllocErr(_)) => self.a.oom(),
|
||||||
Ok(()) => { /* yay */ }
|
Ok(()) => { /* yay */ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -669,7 +669,7 @@ impl<T, A: Alloc> RawVec<T, A> {
|
||||||
old_layout,
|
old_layout,
|
||||||
new_layout) {
|
new_layout) {
|
||||||
Ok(p) => self.ptr = Unique::new_unchecked(p as *mut T),
|
Ok(p) => self.ptr = Unique::new_unchecked(p as *mut T),
|
||||||
Err(err) => self.a.oom(err),
|
Err(_) => self.a.oom(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.cap = amount;
|
self.cap = amount;
|
||||||
|
|
|
@ -668,7 +668,7 @@ impl<T: ?Sized> Rc<T> {
|
||||||
let layout = Layout::for_value(&*fake_ptr);
|
let layout = Layout::for_value(&*fake_ptr);
|
||||||
|
|
||||||
let mem = Global.alloc(layout)
|
let mem = Global.alloc(layout)
|
||||||
.unwrap_or_else(|e| Global.oom(e));
|
.unwrap_or_else(|_| Global.oom());
|
||||||
|
|
||||||
// Initialize the real RcBox
|
// Initialize the real RcBox
|
||||||
let inner = set_data_ptr(ptr as *mut T, mem) as *mut RcBox<T>;
|
let inner = set_data_ptr(ptr as *mut T, mem) as *mut RcBox<T>;
|
||||||
|
|
|
@ -73,8 +73,8 @@ unsafe impl Alloc for System {
|
||||||
Alloc::realloc(&mut &*self, ptr, old_layout, new_layout)
|
Alloc::realloc(&mut &*self, ptr, old_layout, new_layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn oom(&mut self, err: AllocErr) -> ! {
|
fn oom(&mut self) -> ! {
|
||||||
Alloc::oom(&mut &*self, err)
|
Alloc::oom(&mut &*self)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -242,7 +242,7 @@ mod platform {
|
||||||
unsafe impl<'a> Alloc for &'a System {
|
unsafe impl<'a> Alloc for &'a System {
|
||||||
alloc_methods_based_on_global_alloc!();
|
alloc_methods_based_on_global_alloc!();
|
||||||
|
|
||||||
fn oom(&mut self, err: AllocErr) -> ! {
|
fn oom(&mut self) -> ! {
|
||||||
use core::fmt::{self, Write};
|
use core::fmt::{self, Write};
|
||||||
|
|
||||||
// Print a message to stderr before aborting to assist with
|
// Print a message to stderr before aborting to assist with
|
||||||
|
@ -250,7 +250,7 @@ mod platform {
|
||||||
// memory since we are in an OOM situation. Any errors are ignored
|
// memory since we are in an OOM situation. Any errors are ignored
|
||||||
// while printing since there's nothing we can do about them and we
|
// while printing since there's nothing we can do about them and we
|
||||||
// are about to exit anyways.
|
// are about to exit anyways.
|
||||||
drop(writeln!(Stderr, "fatal runtime error: {}", err));
|
drop(writeln!(Stderr, "fatal runtime error: {}", AllocErr));
|
||||||
unsafe {
|
unsafe {
|
||||||
::core::intrinsics::abort();
|
::core::intrinsics::abort();
|
||||||
}
|
}
|
||||||
|
@ -459,11 +459,11 @@ mod platform {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn oom(&mut self, err: AllocErr) -> ! {
|
fn oom(&mut self) -> ! {
|
||||||
use core::fmt::{self, Write};
|
use core::fmt::{self, Write};
|
||||||
|
|
||||||
// Same as with unix we ignore all errors here
|
// Same as with unix we ignore all errors here
|
||||||
drop(writeln!(Stderr, "fatal runtime error: {}", err));
|
drop(writeln!(Stderr, "fatal runtime error: {}", AllocErr));
|
||||||
unsafe {
|
unsafe {
|
||||||
::core::intrinsics::abort();
|
::core::intrinsics::abort();
|
||||||
}
|
}
|
||||||
|
|
|
@ -572,7 +572,7 @@ pub unsafe trait Alloc {
|
||||||
/// instead they should return an appropriate error from the
|
/// instead they should return an appropriate error from the
|
||||||
/// invoked method, and let the client decide whether to invoke
|
/// invoked method, and let the client decide whether to invoke
|
||||||
/// this `oom` method in response.
|
/// this `oom` method in response.
|
||||||
fn oom(&mut self, _: AllocErr) -> ! {
|
fn oom(&mut self) -> ! {
|
||||||
unsafe { ::intrinsics::abort() }
|
unsafe { ::intrinsics::abort() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -784,7 +784,7 @@ impl<K, V, S> HashMap<K, V, S>
|
||||||
pub fn reserve(&mut self, additional: usize) {
|
pub fn reserve(&mut self, additional: usize) {
|
||||||
match self.try_reserve(additional) {
|
match self.try_reserve(additional) {
|
||||||
Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"),
|
Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"),
|
||||||
Err(CollectionAllocErr::AllocErr(e)) => Global.oom(e),
|
Err(CollectionAllocErr::AllocErr(_)) => Global.oom(),
|
||||||
Ok(()) => { /* yay */ }
|
Ok(()) => { /* yay */ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -772,7 +772,7 @@ impl<K, V> RawTable<K, V> {
|
||||||
unsafe fn new_uninitialized(capacity: usize) -> RawTable<K, V> {
|
unsafe fn new_uninitialized(capacity: usize) -> RawTable<K, V> {
|
||||||
match Self::try_new_uninitialized(capacity) {
|
match Self::try_new_uninitialized(capacity) {
|
||||||
Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"),
|
Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"),
|
||||||
Err(CollectionAllocErr::AllocErr(e)) => Global.oom(e),
|
Err(CollectionAllocErr::AllocErr(_)) => Global.oom(),
|
||||||
Ok(table) => { table }
|
Ok(table) => { table }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -811,7 +811,7 @@ impl<K, V> RawTable<K, V> {
|
||||||
pub fn new(capacity: usize) -> RawTable<K, V> {
|
pub fn new(capacity: usize) -> RawTable<K, V> {
|
||||||
match Self::try_new(capacity) {
|
match Self::try_new(capacity) {
|
||||||
Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"),
|
Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"),
|
||||||
Err(CollectionAllocErr::AllocErr(e)) => Global.oom(e),
|
Err(CollectionAllocErr::AllocErr(_)) => Global.oom(),
|
||||||
Ok(table) => { table }
|
Ok(table) => { table }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,8 @@ use std::heap::{Heap, Alloc};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = Heap.alloc_one::<i32>().unwrap_or_else(|e| {
|
let ptr = Heap.alloc_one::<i32>().unwrap_or_else(|_| {
|
||||||
Heap.oom(e)
|
Heap.oom()
|
||||||
});
|
});
|
||||||
*ptr.as_ptr() = 4;
|
*ptr.as_ptr() = 4;
|
||||||
assert_eq!(*ptr.as_ptr(), 4);
|
assert_eq!(*ptr.as_ptr(), 4);
|
||||||
|
|
|
@ -50,7 +50,7 @@ unsafe fn test_triangle() -> bool {
|
||||||
println!("allocate({:?})", layout);
|
println!("allocate({:?})", layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
let ret = Heap.alloc(layout.clone()).unwrap_or_else(|e| Heap.oom(e));
|
let ret = Heap.alloc(layout.clone()).unwrap_or_else(|_| Heap.oom());
|
||||||
|
|
||||||
if PRINT {
|
if PRINT {
|
||||||
println!("allocate({:?}) = {:?}", layout, ret);
|
println!("allocate({:?}) = {:?}", layout, ret);
|
||||||
|
@ -73,7 +73,7 @@ unsafe fn test_triangle() -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
let ret = Heap.realloc(ptr, old.clone(), new.clone())
|
let ret = Heap.realloc(ptr, old.clone(), new.clone())
|
||||||
.unwrap_or_else(|e| Heap.oom(e));
|
.unwrap_or_else(|_| Heap.oom());
|
||||||
|
|
||||||
if PRINT {
|
if PRINT {
|
||||||
println!("reallocate({:?}, old={:?}, new={:?}) = {:?}",
|
println!("reallocate({:?}, old={:?}, new={:?}) = {:?}",
|
||||||
|
|
|
@ -32,7 +32,7 @@ struct Ccx {
|
||||||
fn alloc<'a>(_bcx : &'a arena) -> &'a Bcx<'a> {
|
fn alloc<'a>(_bcx : &'a arena) -> &'a Bcx<'a> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = Heap.alloc(Layout::new::<Bcx>())
|
let ptr = Heap.alloc(Layout::new::<Bcx>())
|
||||||
.unwrap_or_else(|e| Heap.oom(e));
|
.unwrap_or_else(|_| Heap.oom());
|
||||||
&*(ptr as *const _)
|
&*(ptr as *const _)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue