diff options
Diffstat (limited to 'src/libstd/rt')
| -rw-r--r-- | src/libstd/rt/global_heap.rs | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/libstd/rt/global_heap.rs b/src/libstd/rt/global_heap.rs index 7d54c3faf42..c8808b6e821 100644 --- a/src/libstd/rt/global_heap.rs +++ b/src/libstd/rt/global_heap.rs @@ -68,7 +68,7 @@ pub unsafe fn realloc_raw(ptr: *mut u8, size: uint) -> *mut u8 { } /// The allocator for unique pointers without contained managed pointers. -#[cfg(not(test))] +#[cfg(not(test), stage0)] #[lang="exchange_malloc"] #[inline] pub unsafe fn exchange_malloc(size: uint) -> *mut u8 { @@ -85,6 +85,23 @@ pub unsafe fn exchange_malloc(size: uint) -> *mut u8 { } } +/// The allocator for unique pointers without contained managed pointers. +#[cfg(not(test), not(stage0))] +#[lang="exchange_malloc"] +#[inline] +pub unsafe fn exchange_malloc(size: uint, _align: uint) -> *mut u8 { + // The compiler never calls `exchange_free` on ~ZeroSizeType, so zero-size + // allocations can point to this `static`. It would be incorrect to use a null + // pointer, due to enums assuming types like unique pointers are never null. + static EMPTY: () = (); + + if size == 0 { + &EMPTY as *() as *mut u8 + } else { + malloc_raw(size) + } +} + // FIXME: #7496 #[cfg(not(test))] #[lang="closure_exchange_malloc"] @@ -118,6 +135,32 @@ pub unsafe fn exchange_free(ptr: *u8) { free(ptr as *mut c_void); } +// hack for libcore +#[no_mangle] +#[doc(hidden)] +#[deprecated] +#[cfg(stage0)] +pub extern "C" fn rust_malloc(size: uint) -> *mut u8 { + unsafe { exchange_malloc(size) } +} + +// hack for libcore +#[no_mangle] +#[doc(hidden)] +#[deprecated] +#[cfg(not(stage0))] +pub extern "C" fn rust_malloc(size: uint, align: uint) -> *mut u8 { + unsafe { exchange_malloc(size, align) } +} + +// hack for libcore +#[no_mangle] +#[doc(hidden)] +#[deprecated] +pub extern "C" fn rust_free(ptr: *u8) { + unsafe { exchange_free(ptr) } +} + #[cfg(test)] mod bench { extern crate test; |
