diff options
| author | Oliver 'ker' Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2016-11-11 11:55:47 +0100 |
|---|---|---|
| committer | Oliver 'ker' Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2016-11-11 13:36:10 +0100 |
| commit | 323c20c8a4747aa96285c90005a00aa43228af8e (patch) | |
| tree | 763caab11bdebe7b3b6f4258ac72d83e8f426bd8 /src/liballoc | |
| parent | 3ac9ec7dfdd3839f03b94e70d7187a30e7b7f759 (diff) | |
| download | rust-323c20c8a4747aa96285c90005a00aa43228af8e.tar.gz rust-323c20c8a4747aa96285c90005a00aa43228af8e.zip | |
[breaking-change] change the `box_free` item to accept pointers to unsized types
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/heap.rs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/liballoc/heap.rs b/src/liballoc/heap.rs index bfed8a8e83a..12809171b74 100644 --- a/src/liballoc/heap.rs +++ b/src/liballoc/heap.rs @@ -17,7 +17,7 @@ use core::{isize, usize}; #[cfg(not(test))] -use core::intrinsics::{min_align_of, size_of}; +use core::intrinsics::{min_align_of_val, size_of_val}; #[allow(improper_ctypes)] extern "C" { @@ -152,11 +152,12 @@ unsafe fn exchange_free(ptr: *mut u8, old_size: usize, align: usize) { #[cfg(not(test))] #[lang = "box_free"] #[inline] -unsafe fn box_free<T>(ptr: *mut T) { - let size = size_of::<T>(); +unsafe fn box_free<T: ?Sized>(ptr: *mut T) { + let size = size_of_val(&*ptr); + let align = min_align_of_val(&*ptr); // 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>()); + deallocate(ptr as *mut u8, size, align); } } |
