mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
Remove Alloc::oom
This commit is contained in:
parent
e513c1bd31
commit
9e8f683476
1
src/Cargo.lock
generated
1
src/Cargo.lock
generated
@ -19,7 +19,6 @@ dependencies = [
|
||||
name = "alloc_jemalloc"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"alloc_system 0.0.0",
|
||||
"build_helper 0.1.0",
|
||||
"cc 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"compiler_builtins 0.0.0",
|
||||
|
@ -131,11 +131,6 @@ unsafe impl Alloc for Global {
|
||||
unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<NonNull<Opaque>, AllocErr> {
|
||||
NonNull::new(GlobalAlloc::alloc_zeroed(self, layout)).ok_or(AllocErr)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn oom(&mut self) -> ! {
|
||||
oom()
|
||||
}
|
||||
}
|
||||
|
||||
/// The allocator for unique pointers.
|
||||
|
@ -59,7 +59,7 @@ unsafe impl<T> Alloc for T where T: CoreAlloc {
|
||||
}
|
||||
|
||||
fn oom(&mut self, _: AllocErr) -> ! {
|
||||
CoreAlloc::oom(self)
|
||||
unsafe { ::core::intrinsics::abort() }
|
||||
}
|
||||
|
||||
fn usable_size(&self, layout: &Layout) -> (usize, usize) {
|
||||
|
@ -14,7 +14,7 @@ use core::ops::Drop;
|
||||
use core::ptr::{self, NonNull, Unique};
|
||||
use core::slice;
|
||||
|
||||
use alloc::{Alloc, Layout, Global};
|
||||
use alloc::{Alloc, Layout, Global, oom};
|
||||
use alloc::CollectionAllocErr;
|
||||
use alloc::CollectionAllocErr::*;
|
||||
use boxed::Box;
|
||||
@ -101,7 +101,7 @@ impl<T, A: Alloc> RawVec<T, A> {
|
||||
};
|
||||
match result {
|
||||
Ok(ptr) => ptr,
|
||||
Err(_) => a.oom(),
|
||||
Err(_) => oom(),
|
||||
}
|
||||
};
|
||||
|
||||
@ -316,7 +316,7 @@ impl<T, A: Alloc> RawVec<T, A> {
|
||||
new_size);
|
||||
match ptr_res {
|
||||
Ok(ptr) => (new_cap, ptr.cast().into()),
|
||||
Err(_) => self.a.oom(),
|
||||
Err(_) => oom(),
|
||||
}
|
||||
}
|
||||
None => {
|
||||
@ -325,7 +325,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(_) => self.a.oom(),
|
||||
Err(_) => oom(),
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -442,7 +442,7 @@ impl<T, A: Alloc> RawVec<T, A> {
|
||||
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) => capacity_overflow(),
|
||||
Err(AllocErr) => self.a.oom(),
|
||||
Err(AllocErr) => oom(),
|
||||
Ok(()) => { /* yay */ }
|
||||
}
|
||||
}
|
||||
@ -552,7 +552,7 @@ impl<T, A: Alloc> RawVec<T, A> {
|
||||
pub fn reserve(&mut self, used_cap: usize, needed_extra_cap: usize) {
|
||||
match self.try_reserve(used_cap, needed_extra_cap) {
|
||||
Err(CapacityOverflow) => capacity_overflow(),
|
||||
Err(AllocErr) => self.a.oom(),
|
||||
Err(AllocErr) => oom(),
|
||||
Ok(()) => { /* yay */ }
|
||||
}
|
||||
}
|
||||
@ -667,7 +667,7 @@ impl<T, A: Alloc> RawVec<T, A> {
|
||||
old_layout,
|
||||
new_size) {
|
||||
Ok(p) => self.ptr = p.cast().into(),
|
||||
Err(_) => self.a.oom(),
|
||||
Err(_) => oom(),
|
||||
}
|
||||
}
|
||||
self.cap = amount;
|
||||
|
@ -12,7 +12,6 @@ test = false
|
||||
doc = false
|
||||
|
||||
[dependencies]
|
||||
alloc_system = { path = "../liballoc_system" }
|
||||
core = { path = "../libcore" }
|
||||
libc = { path = "../rustc/libc_shim" }
|
||||
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
|
||||
|
@ -14,7 +14,7 @@
|
||||
reason = "this library is unlikely to be stabilized in its current \
|
||||
form or name",
|
||||
issue = "27783")]
|
||||
#![feature(alloc_system)]
|
||||
#![feature(core_intrinsics)]
|
||||
#![feature(libc)]
|
||||
#![feature(linkage)]
|
||||
#![feature(staged_api)]
|
||||
@ -23,7 +23,6 @@
|
||||
#![cfg_attr(not(dummy_jemalloc), feature(allocator_api))]
|
||||
#![rustc_alloc_kind = "exe"]
|
||||
|
||||
extern crate alloc_system;
|
||||
extern crate libc;
|
||||
|
||||
#[cfg(not(dummy_jemalloc))]
|
||||
@ -102,7 +101,7 @@ mod contents {
|
||||
#[no_mangle]
|
||||
#[rustc_std_internal_symbol]
|
||||
pub unsafe extern fn __rde_oom() -> ! {
|
||||
::alloc_system::oom()
|
||||
::core::intrinsics::abort();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -71,11 +71,6 @@ unsafe impl Alloc for System {
|
||||
new_size: usize) -> Result<NonNull<Opaque>, AllocErr> {
|
||||
NonNull::new(GlobalAlloc::realloc(self, ptr.as_ptr(), layout, new_size)).ok_or(AllocErr)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn oom(&mut self) -> ! {
|
||||
::oom()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
@ -103,11 +98,6 @@ unsafe impl<'a> Alloc for &'a System {
|
||||
new_size: usize) -> Result<NonNull<Opaque>, AllocErr> {
|
||||
NonNull::new(GlobalAlloc::realloc(*self, ptr.as_ptr(), layout, new_size)).ok_or(AllocErr)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn oom(&mut self) -> ! {
|
||||
::oom()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(windows, unix, target_os = "cloudabi", target_os = "redox"))]
|
||||
@ -366,63 +356,3 @@ mod platform {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn oom() -> ! {
|
||||
write_to_stderr("fatal runtime error: memory allocation failed");
|
||||
unsafe {
|
||||
::core::intrinsics::abort();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(unix, target_os = "redox"))]
|
||||
#[inline]
|
||||
fn write_to_stderr(s: &str) {
|
||||
extern crate libc;
|
||||
|
||||
unsafe {
|
||||
libc::write(libc::STDERR_FILENO,
|
||||
s.as_ptr() as *const libc::c_void,
|
||||
s.len());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
#[inline]
|
||||
fn write_to_stderr(s: &str) {
|
||||
use core::ptr;
|
||||
|
||||
type LPVOID = *mut u8;
|
||||
type HANDLE = LPVOID;
|
||||
type DWORD = u32;
|
||||
type BOOL = i32;
|
||||
type LPDWORD = *mut DWORD;
|
||||
type LPOVERLAPPED = *mut u8;
|
||||
|
||||
const STD_ERROR_HANDLE: DWORD = -12i32 as DWORD;
|
||||
|
||||
extern "system" {
|
||||
fn WriteFile(hFile: HANDLE,
|
||||
lpBuffer: LPVOID,
|
||||
nNumberOfBytesToWrite: DWORD,
|
||||
lpNumberOfBytesWritten: LPDWORD,
|
||||
lpOverlapped: LPOVERLAPPED)
|
||||
-> BOOL;
|
||||
fn GetStdHandle(which: DWORD) -> HANDLE;
|
||||
}
|
||||
|
||||
unsafe {
|
||||
// WriteFile silently fails if it is passed an invalid
|
||||
// handle, so there is no need to check the result of
|
||||
// GetStdHandle.
|
||||
WriteFile(GetStdHandle(STD_ERROR_HANDLE),
|
||||
s.as_ptr() as LPVOID,
|
||||
s.len() as DWORD,
|
||||
ptr::null_mut(),
|
||||
ptr::null_mut());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(any(windows, unix, target_os = "redox")))]
|
||||
#[inline]
|
||||
fn write_to_stderr(_: &str) {}
|
||||
|
@ -603,32 +603,6 @@ pub unsafe trait Alloc {
|
||||
/// to allocate that block of memory.
|
||||
unsafe fn dealloc(&mut self, ptr: NonNull<Opaque>, layout: Layout);
|
||||
|
||||
/// Allocator-specific method for signaling an out-of-memory
|
||||
/// condition.
|
||||
///
|
||||
/// `oom` aborts the thread or process, optionally performing
|
||||
/// cleanup or logging diagnostic information before panicking or
|
||||
/// aborting.
|
||||
///
|
||||
/// `oom` is meant to be used by clients unable to cope with an
|
||||
/// unsatisfied allocation request, and wish to abandon
|
||||
/// computation rather than attempt to recover locally.
|
||||
///
|
||||
/// Implementations of the `oom` method are discouraged from
|
||||
/// infinitely regressing in nested calls to `oom`. In
|
||||
/// practice this means implementors should eschew allocating,
|
||||
/// especially from `self` (directly or indirectly).
|
||||
///
|
||||
/// Implementations of the allocation and reallocation methods
|
||||
/// (e.g. `alloc`, `alloc_one`, `realloc`) are discouraged from
|
||||
/// panicking (or aborting) in the event of memory exhaustion;
|
||||
/// 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) -> ! {
|
||||
unsafe { ::intrinsics::abort() }
|
||||
}
|
||||
|
||||
// == ALLOCATOR-SPECIFIC QUANTITIES AND LIMITS ==
|
||||
// usable_size
|
||||
|
||||
|
@ -16,6 +16,5 @@ static A: usize = 0;
|
||||
//~| the trait bound `usize:
|
||||
//~| the trait bound `usize:
|
||||
//~| the trait bound `usize:
|
||||
//~| the trait bound `usize:
|
||||
|
||||
fn main() {}
|
||||
|
Loading…
Reference in New Issue
Block a user