diff options
| author | Daniel Micay <danielmicay@gmail.com> | 2014-04-25 21:24:51 -0400 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2014-05-10 19:58:17 -0400 |
| commit | 03a5eb4b5295ada37e1e42ad1299857fcb8e81e9 (patch) | |
| tree | 2875f04ed21bf44867487e6ce4280a6d9431d663 /src/libstd | |
| parent | 1b1ca6d5465ef4de12b1adf25cd4598f261c660d (diff) | |
| download | rust-03a5eb4b5295ada37e1e42ad1299857fcb8e81e9.tar.gz rust-03a5eb4b5295ada37e1e42ad1299857fcb8e81e9.zip | |
add an align parameter to exchange_malloc
Closes #13094
Diffstat (limited to 'src/libstd')
| -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; |
