8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- use libc:: { c_char, c_void, size_t, uintptr_t, free, malloc} ;
11
+ use libc:: { c_char, c_void, size_t, uintptr_t, free, malloc, realloc } ;
12
12
use managed:: raw:: { BoxHeaderRepr , BoxRepr } ;
13
13
use unstable:: intrinsics:: TyDesc ;
14
14
use sys:: size_of;
@@ -33,6 +33,7 @@ fn align_to(size: uint, align: uint) -> uint {
33
33
}
34
34
35
35
/// A wrapper around libc::malloc, aborting on out-of-memory
36
+ #[ inline]
36
37
pub unsafe fn malloc_raw ( size : uint ) -> * c_void {
37
38
let p = malloc ( size as size_t ) ;
38
39
if p. is_null ( ) {
@@ -42,6 +43,17 @@ pub unsafe fn malloc_raw(size: uint) -> *c_void {
42
43
p
43
44
}
44
45
46
+ /// A wrapper around libc::realloc, aborting on out-of-memory
47
+ #[ inline]
48
+ pub unsafe fn realloc_raw ( ptr : * mut c_void , size : uint ) -> * mut c_void {
49
+ let p = realloc ( ptr, size as size_t ) ;
50
+ if p. is_null ( ) {
51
+ // we need a non-allocating way to print an error here
52
+ abort ( ) ;
53
+ }
54
+ p
55
+ }
56
+
45
57
// FIXME #4942: Make these signatures agree with exchange_alloc's signatures
46
58
#[ cfg( stage0, not( test) ) ]
47
59
#[ lang="exchange_malloc" ]
0 commit comments