diff options
| author | Simonas Kazlauskas <git@kazlauskas.me> | 2016-01-28 23:59:00 +0200 |
|---|---|---|
| committer | Simonas Kazlauskas <git@kazlauskas.me> | 2016-02-04 15:56:01 +0200 |
| commit | 432460a6fc92e8baecbc4fa175345e78232fe2ed (patch) | |
| tree | d59c70df2e2c0c9234f8134be320a5932be8d792 /src/liballoc | |
| parent | 7b9d6d3bc8730aa565dbb5e285027443696aef0c (diff) | |
| download | rust-432460a6fc92e8baecbc4fa175345e78232fe2ed.tar.gz rust-432460a6fc92e8baecbc4fa175345e78232fe2ed.zip | |
Synthesize calls to box_free language item
This gets rid of Drop(Free, _) MIR construct by synthesizing a call to language item which takes care of dropping instead.
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/heap.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/liballoc/heap.rs b/src/liballoc/heap.rs index 7e7e3c619cb..08b403a60f3 100644 --- a/src/liballoc/heap.rs +++ b/src/liballoc/heap.rs @@ -16,6 +16,8 @@ issue = "27700")] use core::{isize, usize}; +#[cfg(not(test))] +use core::intrinsics::{size_of, min_align_of}; #[allow(improper_ctypes)] extern "C" { @@ -147,6 +149,17 @@ unsafe fn exchange_free(ptr: *mut u8, old_size: usize, align: usize) { deallocate(ptr, old_size, align); } +#[cfg(not(test))] +#[lang = "box_free"] +#[inline] +unsafe fn box_free<T>(ptr: *mut T) { + let size = size_of::<T>(); + // We do not allocate for Box<T> when T is ZST, so deallocation is also not necessary. + if size != 0 { + deallocate(ptr as *mut u8, size, min_align_of::<T>()); + } +} + #[cfg(test)] mod tests { extern crate test; |
