Remove the now-unit-struct AllocErr parameter of oom()
This commit is contained in:
parent
86753ce1cc
commit
157ff8cd05
@ -136,8 +136,8 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
|
||||
align as *mut u8
|
||||
} else {
|
||||
let layout = Layout::from_size_align_unchecked(size, align);
|
||||
Global.alloc(layout).unwrap_or_else(|err| {
|
||||
Global.oom(err)
|
||||
Global.alloc(layout).unwrap_or_else(|_| {
|
||||
Global.oom()
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -166,7 +166,7 @@ fn allocate_zeroed() {
|
||||
unsafe {
|
||||
let layout = Layout::from_size_align(1024, 1).unwrap();
|
||||
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 mut i = ptr;
|
||||
|
@ -555,7 +555,7 @@ unsafe fn allocate_for_ptr(ptr: *const T) -> *mut ArcInner<T> {
|
||||
let layout = Layout::for_value(&*fake_ptr);
|
||||
|
||||
let mem = Global.alloc(layout)
|
||||
.unwrap_or_else(|e| Global.oom(e));
|
||||
.unwrap_or_else(|_| Global.oom());
|
||||
|
||||
// Initialize the real ArcInner
|
||||
let inner = set_data_ptr(ptr as *mut T, mem) as *mut ArcInner<T>;
|
||||
|
@ -52,8 +52,8 @@ unsafe fn dealloc(&mut self, ptr: *mut u8, layout: Layout) {
|
||||
CoreAlloc::dealloc(self, ptr, layout)
|
||||
}
|
||||
|
||||
fn oom(&mut self, err: AllocErr) -> ! {
|
||||
CoreAlloc::oom(self, err)
|
||||
fn oom(&mut self, _: AllocErr) -> ! {
|
||||
CoreAlloc::oom(self)
|
||||
}
|
||||
|
||||
fn usable_size(&self, layout: &Layout) -> (usize, usize) {
|
||||
|
@ -100,7 +100,7 @@ fn allocate_in(cap: usize, zeroed: bool, mut a: A) -> Self {
|
||||
};
|
||||
match result {
|
||||
Ok(ptr) => ptr,
|
||||
Err(err) => a.oom(err),
|
||||
Err(_) => a.oom(),
|
||||
}
|
||||
};
|
||||
|
||||
@ -316,7 +316,7 @@ pub fn double(&mut self) {
|
||||
new_layout);
|
||||
match ptr_res {
|
||||
Ok(ptr) => (new_cap, Unique::new_unchecked(ptr as *mut T)),
|
||||
Err(e) => self.a.oom(e),
|
||||
Err(_) => self.a.oom(),
|
||||
}
|
||||
}
|
||||
None => {
|
||||
@ -325,7 +325,7 @@ pub fn double(&mut self) {
|
||||
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(e) => self.a.oom(e),
|
||||
Err(_) => self.a.oom(),
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -444,7 +444,7 @@ pub fn try_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) {
|
||||
Err(CapacityOverflow) => panic!("capacity overflow"),
|
||||
Err(AllocErr(e)) => self.a.oom(e),
|
||||
Err(AllocErr(_)) => self.a.oom(),
|
||||
Ok(()) => { /* yay */ }
|
||||
}
|
||||
}
|
||||
@ -554,7 +554,7 @@ pub fn try_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) {
|
||||
Err(CapacityOverflow) => panic!("capacity overflow"),
|
||||
Err(AllocErr(e)) => self.a.oom(e),
|
||||
Err(AllocErr(_)) => self.a.oom(),
|
||||
Ok(()) => { /* yay */ }
|
||||
}
|
||||
}
|
||||
@ -669,7 +669,7 @@ pub fn shrink_to_fit(&mut self, amount: usize) {
|
||||
old_layout,
|
||||
new_layout) {
|
||||
Ok(p) => self.ptr = Unique::new_unchecked(p as *mut T),
|
||||
Err(err) => self.a.oom(err),
|
||||
Err(_) => self.a.oom(),
|
||||
}
|
||||
}
|
||||
self.cap = amount;
|
||||
|
@ -668,7 +668,7 @@ unsafe fn allocate_for_ptr(ptr: *const T) -> *mut RcBox<T> {
|
||||
let layout = Layout::for_value(&*fake_ptr);
|
||||
|
||||
let mem = Global.alloc(layout)
|
||||
.unwrap_or_else(|e| Global.oom(e));
|
||||
.unwrap_or_else(|_| Global.oom());
|
||||
|
||||
// Initialize the real RcBox
|
||||
let inner = set_data_ptr(ptr as *mut T, mem) as *mut RcBox<T>;
|
||||
|
@ -73,8 +73,8 @@ unsafe fn realloc(&mut self,
|
||||
Alloc::realloc(&mut &*self, ptr, old_layout, new_layout)
|
||||
}
|
||||
|
||||
fn oom(&mut self, err: AllocErr) -> ! {
|
||||
Alloc::oom(&mut &*self, err)
|
||||
fn oom(&mut self) -> ! {
|
||||
Alloc::oom(&mut &*self)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -242,7 +242,7 @@ unsafe fn realloc(&self, ptr: *mut Void, old_layout: Layout, new_size: usize) ->
|
||||
unsafe impl<'a> Alloc for &'a System {
|
||||
alloc_methods_based_on_global_alloc!();
|
||||
|
||||
fn oom(&mut self, err: AllocErr) -> ! {
|
||||
fn oom(&mut self) -> ! {
|
||||
use core::fmt::{self, Write};
|
||||
|
||||
// Print a message to stderr before aborting to assist with
|
||||
@ -250,7 +250,7 @@ fn oom(&mut self, err: AllocErr) -> ! {
|
||||
// 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
|
||||
// are about to exit anyways.
|
||||
drop(writeln!(Stderr, "fatal runtime error: {}", err));
|
||||
drop(writeln!(Stderr, "fatal runtime error: {}", AllocErr));
|
||||
unsafe {
|
||||
::core::intrinsics::abort();
|
||||
}
|
||||
@ -459,11 +459,11 @@ unsafe fn shrink_in_place(&mut self,
|
||||
}
|
||||
}
|
||||
|
||||
fn oom(&mut self, err: AllocErr) -> ! {
|
||||
fn oom(&mut self) -> ! {
|
||||
use core::fmt::{self, Write};
|
||||
|
||||
// Same as with unix we ignore all errors here
|
||||
drop(writeln!(Stderr, "fatal runtime error: {}", err));
|
||||
drop(writeln!(Stderr, "fatal runtime error: {}", AllocErr));
|
||||
unsafe {
|
||||
::core::intrinsics::abort();
|
||||
}
|
||||
|
@ -572,7 +572,7 @@ pub unsafe trait Alloc {
|
||||
/// instead they should return an appropriate error from the
|
||||
/// invoked method, and let the client decide whether to invoke
|
||||
/// this `oom` method in response.
|
||||
fn oom(&mut self, _: AllocErr) -> ! {
|
||||
fn oom(&mut self) -> ! {
|
||||
unsafe { ::intrinsics::abort() }
|
||||
}
|
||||
|
||||
|
@ -784,7 +784,7 @@ fn raw_capacity(&self) -> usize {
|
||||
pub fn reserve(&mut self, additional: usize) {
|
||||
match self.try_reserve(additional) {
|
||||
Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"),
|
||||
Err(CollectionAllocErr::AllocErr(e)) => Global.oom(e),
|
||||
Err(CollectionAllocErr::AllocErr(_)) => Global.oom(),
|
||||
Ok(()) => { /* yay */ }
|
||||
}
|
||||
}
|
||||
|
@ -772,7 +772,7 @@ unsafe fn try_new_uninitialized(capacity: usize) -> Result<RawTable<K, V>, Colle
|
||||
unsafe fn new_uninitialized(capacity: usize) -> RawTable<K, V> {
|
||||
match Self::try_new_uninitialized(capacity) {
|
||||
Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"),
|
||||
Err(CollectionAllocErr::AllocErr(e)) => Global.oom(e),
|
||||
Err(CollectionAllocErr::AllocErr(_)) => Global.oom(),
|
||||
Ok(table) => { table }
|
||||
}
|
||||
}
|
||||
@ -811,7 +811,7 @@ pub fn try_new(capacity: usize) -> Result<RawTable<K, V>, CollectionAllocErr> {
|
||||
pub fn new(capacity: usize) -> RawTable<K, V> {
|
||||
match Self::try_new(capacity) {
|
||||
Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"),
|
||||
Err(CollectionAllocErr::AllocErr(e)) => Global.oom(e),
|
||||
Err(CollectionAllocErr::AllocErr(_)) => Global.oom(),
|
||||
Ok(table) => { table }
|
||||
}
|
||||
}
|
||||
|
@ -14,8 +14,8 @@
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
let ptr = Heap.alloc_one::<i32>().unwrap_or_else(|e| {
|
||||
Heap.oom(e)
|
||||
let ptr = Heap.alloc_one::<i32>().unwrap_or_else(|_| {
|
||||
Heap.oom()
|
||||
});
|
||||
*ptr.as_ptr() = 4;
|
||||
assert_eq!(*ptr.as_ptr(), 4);
|
||||
|
@ -50,7 +50,7 @@ unsafe fn allocate(layout: Layout) -> *mut u8 {
|
||||
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 {
|
||||
println!("allocate({:?}) = {:?}", layout, ret);
|
||||
@ -73,7 +73,7 @@ unsafe fn reallocate(ptr: *mut u8, old: Layout, new: Layout) -> *mut u8 {
|
||||
}
|
||||
|
||||
let ret = Heap.realloc(ptr, old.clone(), new.clone())
|
||||
.unwrap_or_else(|e| Heap.oom(e));
|
||||
.unwrap_or_else(|_| Heap.oom());
|
||||
|
||||
if PRINT {
|
||||
println!("reallocate({:?}, old={:?}, new={:?}) = {:?}",
|
||||
|
@ -32,7 +32,7 @@ struct Ccx {
|
||||
fn alloc<'a>(_bcx : &'a arena) -> &'a Bcx<'a> {
|
||||
unsafe {
|
||||
let ptr = Heap.alloc(Layout::new::<Bcx>())
|
||||
.unwrap_or_else(|e| Heap.oom(e));
|
||||
.unwrap_or_else(|_| Heap.oom());
|
||||
&*(ptr as *const _)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user