alloc: Refactor OOM into a common routine
This commit is contained in:
parent
4cd932f94e
commit
051abae802
@ -130,7 +130,6 @@ unsafe fn closure_exchange_malloc(drop_glue: fn(*mut u8), size: uint,
|
||||
|
||||
#[cfg(jemalloc)]
|
||||
mod imp {
|
||||
use core::intrinsics::abort;
|
||||
use core::option::{None, Option};
|
||||
use core::ptr::{RawPtr, mut_null, null};
|
||||
use core::num::Bitwise;
|
||||
@ -163,7 +162,7 @@ mod imp {
|
||||
pub unsafe fn allocate(size: uint, align: uint) -> *mut u8 {
|
||||
let ptr = je_mallocx(size as size_t, mallocx_align(align)) as *mut u8;
|
||||
if ptr.is_null() {
|
||||
abort()
|
||||
::oom()
|
||||
}
|
||||
ptr
|
||||
}
|
||||
@ -174,7 +173,7 @@ mod imp {
|
||||
let ptr = je_rallocx(ptr as *mut c_void, size as size_t,
|
||||
mallocx_align(align)) as *mut u8;
|
||||
if ptr.is_null() {
|
||||
abort()
|
||||
::oom()
|
||||
}
|
||||
ptr
|
||||
}
|
||||
|
@ -94,6 +94,14 @@ pub mod owned;
|
||||
pub mod arc;
|
||||
pub mod rc;
|
||||
|
||||
/// Common OOM routine used by liballoc
|
||||
fn oom() -> ! {
|
||||
// FIXME(#14674): This really needs to do something other than just abort
|
||||
// here, but any printing done must be *guaranteed* to not
|
||||
// allocate.
|
||||
unsafe { core::intrinsics::abort() }
|
||||
}
|
||||
|
||||
// FIXME(#14344): When linking liballoc with libstd, this library will be linked
|
||||
// as an rlib (it only exists as an rlib). It turns out that an
|
||||
// optimized standard library doesn't actually use *any* symbols
|
||||
|
@ -13,7 +13,6 @@
|
||||
|
||||
use libc::{c_void, size_t, free, malloc, realloc};
|
||||
use core::ptr::{RawPtr, mut_null};
|
||||
use core::intrinsics::abort;
|
||||
|
||||
/// A wrapper around libc::malloc, aborting on out-of-memory
|
||||
#[inline]
|
||||
@ -25,8 +24,7 @@ pub unsafe fn malloc_raw(size: uint) -> *mut u8 {
|
||||
} else {
|
||||
let p = malloc(size as size_t);
|
||||
if p.is_null() {
|
||||
// we need a non-allocating way to print an error here
|
||||
abort();
|
||||
::oom();
|
||||
}
|
||||
p as *mut u8
|
||||
}
|
||||
@ -43,8 +41,7 @@ pub unsafe fn realloc_raw(ptr: *mut u8, size: uint) -> *mut u8 {
|
||||
} else {
|
||||
let p = realloc(ptr as *mut c_void, size as size_t);
|
||||
if p.is_null() {
|
||||
// we need a non-allocating way to print an error here
|
||||
abort();
|
||||
::oom();
|
||||
}
|
||||
p as *mut u8
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user