Skip to content

Commit 9e8f683

Browse files
committed
Remove Alloc::oom
1 parent e513c1b commit 9e8f683

File tree

9 files changed

+10
-115
lines changed

9 files changed

+10
-115
lines changed

src/Cargo.lock

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/liballoc/alloc.rs

-5
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,6 @@ unsafe impl Alloc for Global {
131131
unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<NonNull<Opaque>, AllocErr> {
132132
NonNull::new(GlobalAlloc::alloc_zeroed(self, layout)).ok_or(AllocErr)
133133
}
134-
135-
#[inline]
136-
fn oom(&mut self) -> ! {
137-
oom()
138-
}
139134
}
140135

141136
/// The allocator for unique pointers.

src/liballoc/heap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ unsafe impl<T> Alloc for T where T: CoreAlloc {
5959
}
6060

6161
fn oom(&mut self, _: AllocErr) -> ! {
62-
CoreAlloc::oom(self)
62+
unsafe { ::core::intrinsics::abort() }
6363
}
6464

6565
fn usable_size(&self, layout: &Layout) -> (usize, usize) {

src/liballoc/raw_vec.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use core::ops::Drop;
1414
use core::ptr::{self, NonNull, Unique};
1515
use core::slice;
1616

17-
use alloc::{Alloc, Layout, Global};
17+
use alloc::{Alloc, Layout, Global, oom};
1818
use alloc::CollectionAllocErr;
1919
use alloc::CollectionAllocErr::*;
2020
use boxed::Box;
@@ -101,7 +101,7 @@ impl<T, A: Alloc> RawVec<T, A> {
101101
};
102102
match result {
103103
Ok(ptr) => ptr,
104-
Err(_) => a.oom(),
104+
Err(_) => oom(),
105105
}
106106
};
107107

@@ -316,7 +316,7 @@ impl<T, A: Alloc> RawVec<T, A> {
316316
new_size);
317317
match ptr_res {
318318
Ok(ptr) => (new_cap, ptr.cast().into()),
319-
Err(_) => self.a.oom(),
319+
Err(_) => oom(),
320320
}
321321
}
322322
None => {
@@ -325,7 +325,7 @@ impl<T, A: Alloc> RawVec<T, A> {
325325
let new_cap = if elem_size > (!0) / 8 { 1 } else { 4 };
326326
match self.a.alloc_array::<T>(new_cap) {
327327
Ok(ptr) => (new_cap, ptr.into()),
328-
Err(_) => self.a.oom(),
328+
Err(_) => oom(),
329329
}
330330
}
331331
};
@@ -442,7 +442,7 @@ impl<T, A: Alloc> RawVec<T, A> {
442442
pub fn reserve_exact(&mut self, used_cap: usize, needed_extra_cap: usize) {
443443
match self.try_reserve_exact(used_cap, needed_extra_cap) {
444444
Err(CapacityOverflow) => capacity_overflow(),
445-
Err(AllocErr) => self.a.oom(),
445+
Err(AllocErr) => oom(),
446446
Ok(()) => { /* yay */ }
447447
}
448448
}
@@ -552,7 +552,7 @@ impl<T, A: Alloc> RawVec<T, A> {
552552
pub fn reserve(&mut self, used_cap: usize, needed_extra_cap: usize) {
553553
match self.try_reserve(used_cap, needed_extra_cap) {
554554
Err(CapacityOverflow) => capacity_overflow(),
555-
Err(AllocErr) => self.a.oom(),
555+
Err(AllocErr) => oom(),
556556
Ok(()) => { /* yay */ }
557557
}
558558
}
@@ -667,7 +667,7 @@ impl<T, A: Alloc> RawVec<T, A> {
667667
old_layout,
668668
new_size) {
669669
Ok(p) => self.ptr = p.cast().into(),
670-
Err(_) => self.a.oom(),
670+
Err(_) => oom(),
671671
}
672672
}
673673
self.cap = amount;

src/liballoc_jemalloc/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ test = false
1212
doc = false
1313

1414
[dependencies]
15-
alloc_system = { path = "../liballoc_system" }
1615
core = { path = "../libcore" }
1716
libc = { path = "../rustc/libc_shim" }
1817
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }

src/liballoc_jemalloc/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
reason = "this library is unlikely to be stabilized in its current \
1515
form or name",
1616
issue = "27783")]
17-
#![feature(alloc_system)]
17+
#![feature(core_intrinsics)]
1818
#![feature(libc)]
1919
#![feature(linkage)]
2020
#![feature(staged_api)]
@@ -23,7 +23,6 @@
2323
#![cfg_attr(not(dummy_jemalloc), feature(allocator_api))]
2424
#![rustc_alloc_kind = "exe"]
2525

26-
extern crate alloc_system;
2726
extern crate libc;
2827

2928
#[cfg(not(dummy_jemalloc))]
@@ -102,7 +101,7 @@ mod contents {
102101
#[no_mangle]
103102
#[rustc_std_internal_symbol]
104103
pub unsafe extern fn __rde_oom() -> ! {
105-
::alloc_system::oom()
104+
::core::intrinsics::abort();
106105
}
107106

108107
#[no_mangle]

src/liballoc_system/lib.rs

-70
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ unsafe impl Alloc for System {
7171
new_size: usize) -> Result<NonNull<Opaque>, AllocErr> {
7272
NonNull::new(GlobalAlloc::realloc(self, ptr.as_ptr(), layout, new_size)).ok_or(AllocErr)
7373
}
74-
75-
#[inline]
76-
fn oom(&mut self) -> ! {
77-
::oom()
78-
}
7974
}
8075

8176
#[cfg(stage0)]
@@ -103,11 +98,6 @@ unsafe impl<'a> Alloc for &'a System {
10398
new_size: usize) -> Result<NonNull<Opaque>, AllocErr> {
10499
NonNull::new(GlobalAlloc::realloc(*self, ptr.as_ptr(), layout, new_size)).ok_or(AllocErr)
105100
}
106-
107-
#[inline]
108-
fn oom(&mut self) -> ! {
109-
::oom()
110-
}
111101
}
112102

113103
#[cfg(any(windows, unix, target_os = "cloudabi", target_os = "redox"))]
@@ -366,63 +356,3 @@ mod platform {
366356
}
367357
}
368358
}
369-
370-
#[inline]
371-
pub fn oom() -> ! {
372-
write_to_stderr("fatal runtime error: memory allocation failed");
373-
unsafe {
374-
::core::intrinsics::abort();
375-
}
376-
}
377-
378-
#[cfg(any(unix, target_os = "redox"))]
379-
#[inline]
380-
fn write_to_stderr(s: &str) {
381-
extern crate libc;
382-
383-
unsafe {
384-
libc::write(libc::STDERR_FILENO,
385-
s.as_ptr() as *const libc::c_void,
386-
s.len());
387-
}
388-
}
389-
390-
#[cfg(windows)]
391-
#[inline]
392-
fn write_to_stderr(s: &str) {
393-
use core::ptr;
394-
395-
type LPVOID = *mut u8;
396-
type HANDLE = LPVOID;
397-
type DWORD = u32;
398-
type BOOL = i32;
399-
type LPDWORD = *mut DWORD;
400-
type LPOVERLAPPED = *mut u8;
401-
402-
const STD_ERROR_HANDLE: DWORD = -12i32 as DWORD;
403-
404-
extern "system" {
405-
fn WriteFile(hFile: HANDLE,
406-
lpBuffer: LPVOID,
407-
nNumberOfBytesToWrite: DWORD,
408-
lpNumberOfBytesWritten: LPDWORD,
409-
lpOverlapped: LPOVERLAPPED)
410-
-> BOOL;
411-
fn GetStdHandle(which: DWORD) -> HANDLE;
412-
}
413-
414-
unsafe {
415-
// WriteFile silently fails if it is passed an invalid
416-
// handle, so there is no need to check the result of
417-
// GetStdHandle.
418-
WriteFile(GetStdHandle(STD_ERROR_HANDLE),
419-
s.as_ptr() as LPVOID,
420-
s.len() as DWORD,
421-
ptr::null_mut(),
422-
ptr::null_mut());
423-
}
424-
}
425-
426-
#[cfg(not(any(windows, unix, target_os = "redox")))]
427-
#[inline]
428-
fn write_to_stderr(_: &str) {}

src/libcore/alloc.rs

-26
Original file line numberDiff line numberDiff line change
@@ -603,32 +603,6 @@ pub unsafe trait Alloc {
603603
/// to allocate that block of memory.
604604
unsafe fn dealloc(&mut self, ptr: NonNull<Opaque>, layout: Layout);
605605

606-
/// Allocator-specific method for signaling an out-of-memory
607-
/// condition.
608-
///
609-
/// `oom` aborts the thread or process, optionally performing
610-
/// cleanup or logging diagnostic information before panicking or
611-
/// aborting.
612-
///
613-
/// `oom` is meant to be used by clients unable to cope with an
614-
/// unsatisfied allocation request, and wish to abandon
615-
/// computation rather than attempt to recover locally.
616-
///
617-
/// Implementations of the `oom` method are discouraged from
618-
/// infinitely regressing in nested calls to `oom`. In
619-
/// practice this means implementors should eschew allocating,
620-
/// especially from `self` (directly or indirectly).
621-
///
622-
/// Implementations of the allocation and reallocation methods
623-
/// (e.g. `alloc`, `alloc_one`, `realloc`) are discouraged from
624-
/// panicking (or aborting) in the event of memory exhaustion;
625-
/// instead they should return an appropriate error from the
626-
/// invoked method, and let the client decide whether to invoke
627-
/// this `oom` method in response.
628-
fn oom(&mut self) -> ! {
629-
unsafe { ::intrinsics::abort() }
630-
}
631-
632606
// == ALLOCATOR-SPECIFIC QUANTITIES AND LIMITS ==
633607
// usable_size
634608

src/test/compile-fail/allocator/not-an-allocator.rs

-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ static A: usize = 0;
1616
//~| the trait bound `usize:
1717
//~| the trait bound `usize:
1818
//~| the trait bound `usize:
19-
//~| the trait bound `usize:
2019

2120
fn main() {}

0 commit comments

Comments
 (0)