diff options
| author | Daniel Micay <danielmicay@gmail.com> | 2014-10-24 17:34:57 -0400 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2014-10-25 14:12:19 -0400 |
| commit | 2bc4d3ec23cc88155173729e60df54c8aa4949a6 (patch) | |
| tree | 46b2d71ffeba2ffa639b8f67c9480617d04aea9f /src/liballoc/heap.rs | |
| parent | 6f253bd49e80c809b7c22fd257bcef06a8ca7c30 (diff) | |
| download | rust-2bc4d3ec23cc88155173729e60df54c8aa4949a6.tar.gz rust-2bc4d3ec23cc88155173729e60df54c8aa4949a6.zip | |
get rid of libc_heap::{malloc_raw, realloc_raw}
The C standard library functions should be used directly. The quirky NULL / zero-size allocation workaround is no longer necessary and was adding an extra branch to the allocator code path in a build without jemalloc. This is a small step towards liballoc being compatible with handling OOM errors instead of aborting (#18292). [breaking-change]
Diffstat (limited to 'src/liballoc/heap.rs')
| -rw-r--r-- | src/liballoc/heap.rs | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/liballoc/heap.rs b/src/liballoc/heap.rs index 0e5aca18ec7..20569d336a8 100644 --- a/src/liballoc/heap.rs +++ b/src/liballoc/heap.rs @@ -213,8 +213,8 @@ mod imp { mod imp { use core::cmp; use core::ptr; + use core::ptr::RawPtr; use libc; - use libc_heap; use super::MIN_ALIGN; extern { @@ -226,7 +226,11 @@ mod imp { #[inline] pub unsafe fn allocate(size: uint, align: uint) -> *mut u8 { if align <= MIN_ALIGN { - libc_heap::malloc_raw(size) + let ptr = libc::malloc(size as libc::size_t); + if ptr.is_null() { + ::oom(); + } + ptr as *mut u8 } else { let mut out = 0 as *mut libc::c_void; let ret = posix_memalign(&mut out, @@ -242,7 +246,11 @@ mod imp { #[inline] pub unsafe fn reallocate(ptr: *mut u8, old_size: uint, size: uint, align: uint) -> *mut u8 { if align <= MIN_ALIGN { - libc_heap::realloc_raw(ptr, size) + let ptr = libc::realloc(ptr as *mut libc::c_void, size as libc::size_t); + if ptr.is_null() { + ::oom(); + } + ptr as *mut u8 } else { let new_ptr = allocate(size, align); ptr::copy_memory(new_ptr, ptr as *const u8, cmp::min(size, old_size)); @@ -274,7 +282,6 @@ mod imp { mod imp { use libc::{c_void, size_t}; use libc; - use libc_heap; use core::ptr::RawPtr; use super::MIN_ALIGN; @@ -288,7 +295,11 @@ mod imp { #[inline] pub unsafe fn allocate(size: uint, align: uint) -> *mut u8 { if align <= MIN_ALIGN { - libc_heap::malloc_raw(size) + let ptr = libc::malloc(size as size_t); + if ptr.is_null() { + ::oom(); + } + ptr as *mut u8 } else { let ptr = _aligned_malloc(size as size_t, align as size_t); if ptr.is_null() { @@ -301,7 +312,11 @@ mod imp { #[inline] pub unsafe fn reallocate(ptr: *mut u8, _old_size: uint, size: uint, align: uint) -> *mut u8 { if align <= MIN_ALIGN { - libc_heap::realloc_raw(ptr, size) + let ptr = libc::realloc(ptr as *mut c_void, size as size_t); + if ptr.is_null() { + ::oom(); + } + ptr as *mut u8 } else { let ptr = _aligned_realloc(ptr as *mut c_void, size as size_t, align as size_t); |
