summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-06-13 23:35:54 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-06-16 18:15:48 -0700
commit051abae802318d8401c9b5e6baa9ffc863f7f8eb (patch)
treee07e148b118dee75de8f65b8ba3254a64ff516b4 /src/liballoc
parent4cd932f94e76046500e180bc941e36a2a17cade8 (diff)
downloadrust-051abae802318d8401c9b5e6baa9ffc863f7f8eb.tar.gz
rust-051abae802318d8401c9b5e6baa9ffc863f7f8eb.zip
alloc: Refactor OOM into a common routine
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/heap.rs5
-rw-r--r--src/liballoc/lib.rs8
-rw-r--r--src/liballoc/libc_heap.rs7
3 files changed, 12 insertions, 8 deletions
diff --git a/src/liballoc/heap.rs b/src/liballoc/heap.rs
index 0e7445e737c..79a616b9555 100644
--- a/src/liballoc/heap.rs
+++ b/src/liballoc/heap.rs
@@ -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
     }
diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs
index 0d8d25bff20..a947378f768 100644
--- a/src/liballoc/lib.rs
+++ b/src/liballoc/lib.rs
@@ -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
diff --git a/src/liballoc/libc_heap.rs b/src/liballoc/libc_heap.rs
index 5b189bc672e..25938ba0d54 100644
--- a/src/liballoc/libc_heap.rs
+++ b/src/liballoc/libc_heap.rs
@@ -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
     }