about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/libstd/libc.rs2
-rw-r--r--src/libstd/rt/global_heap.rs14
2 files changed, 14 insertions, 2 deletions
diff --git a/src/libstd/libc.rs b/src/libstd/libc.rs
index 41b78afded1..f4ea29b5c05 100644
--- a/src/libstd/libc.rs
+++ b/src/libstd/libc.rs
@@ -1945,7 +1945,7 @@ pub mod funcs {
                 #[fast_ffi]
                 unsafe fn malloc(size: size_t) -> *c_void;
                 #[fast_ffi]
-                unsafe fn realloc(p: *c_void, size: size_t) -> *c_void;
+                unsafe fn realloc(p: *mut c_void, size: size_t) -> *mut c_void;
                 #[fast_ffi]
                 unsafe fn free(p: *c_void);
                 unsafe fn abort() -> !;
diff --git a/src/libstd/rt/global_heap.rs b/src/libstd/rt/global_heap.rs
index f669dc753d6..a7fbed2dd70 100644
--- a/src/libstd/rt/global_heap.rs
+++ b/src/libstd/rt/global_heap.rs
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use libc::{c_char, c_void, size_t, uintptr_t, free, malloc};
+use libc::{c_char, c_void, size_t, uintptr_t, free, malloc, realloc};
 use managed::raw::{BoxHeaderRepr, BoxRepr};
 use unstable::intrinsics::TyDesc;
 use sys::size_of;
@@ -33,6 +33,7 @@ fn align_to(size: uint, align: uint) -> uint {
 }
 
 /// A wrapper around libc::malloc, aborting on out-of-memory
+#[inline]
 pub unsafe fn malloc_raw(size: uint) -> *c_void {
     let p = malloc(size as size_t);
     if p.is_null() {
@@ -42,6 +43,17 @@ pub unsafe fn malloc_raw(size: uint) -> *c_void {
     p
 }
 
+/// A wrapper around libc::realloc, aborting on out-of-memory
+#[inline]
+pub unsafe fn realloc_raw(ptr: *mut c_void, size: uint) -> *mut c_void {
+    let p = realloc(ptr, size as size_t);
+    if p.is_null() {
+        // we need a non-allocating way to print an error here
+        abort();
+    }
+    p
+}
+
 // FIXME #4942: Make these signatures agree with exchange_alloc's signatures
 #[cfg(stage0, not(test))]
 #[lang="exchange_malloc"]