[breaking-change] change the box_free
item to accept pointers to unsized types
This commit is contained in:
parent
3ac9ec7dfd
commit
323c20c8a4
@ -46,8 +46,8 @@ unsafe fn deallocate(ptr: *mut u8, _size: usize, _align: usize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[lang = "box_free"]
|
#[lang = "box_free"]
|
||||||
unsafe fn box_free<T>(ptr: *mut T) {
|
unsafe fn box_free<T: ?Sized>(ptr: *mut T) {
|
||||||
deallocate(ptr as *mut u8, ::core::mem::size_of::<T>(), ::core::mem::align_of::<T>());
|
deallocate(ptr as *mut u8, ::core::mem::size_of_val(&*ptr), ::core::mem::align_of_val(&*ptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[start]
|
#[start]
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
use core::{isize, usize};
|
use core::{isize, usize};
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
use core::intrinsics::{min_align_of, size_of};
|
use core::intrinsics::{min_align_of_val, size_of_val};
|
||||||
|
|
||||||
#[allow(improper_ctypes)]
|
#[allow(improper_ctypes)]
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -152,11 +152,12 @@ unsafe fn exchange_free(ptr: *mut u8, old_size: usize, align: usize) {
|
|||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
#[lang = "box_free"]
|
#[lang = "box_free"]
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn box_free<T>(ptr: *mut T) {
|
unsafe fn box_free<T: ?Sized>(ptr: *mut T) {
|
||||||
let size = size_of::<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.
|
// We do not allocate for Box<T> when T is ZST, so deallocation is also not necessary.
|
||||||
if size != 0 {
|
if size != 0 {
|
||||||
deallocate(ptr as *mut u8, size, min_align_of::<T>());
|
deallocate(ptr as *mut u8, size, align);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user