heap: replace exchange_free
with deallocate
The `std::rt::heap` API is Rust's global allocator, so there's no need to have this as a separate API.
This commit is contained in:
parent
32988db2bd
commit
69b321c84b
@ -33,7 +33,7 @@ use option::{Option, Some, None};
|
|||||||
use ptr;
|
use ptr;
|
||||||
use ptr::RawPtr;
|
use ptr::RawPtr;
|
||||||
use mem::{min_align_of, size_of};
|
use mem::{min_align_of, size_of};
|
||||||
use rt::heap::exchange_free;
|
use rt::heap::deallocate;
|
||||||
|
|
||||||
struct RcBox<T> {
|
struct RcBox<T> {
|
||||||
value: T,
|
value: T,
|
||||||
@ -105,8 +105,8 @@ impl<T> Drop for Rc<T> {
|
|||||||
self.dec_weak();
|
self.dec_weak();
|
||||||
|
|
||||||
if self.weak() == 0 {
|
if self.weak() == 0 {
|
||||||
exchange_free(self.ptr as *mut u8, size_of::<RcBox<T>>(),
|
deallocate(self.ptr as *mut u8, size_of::<RcBox<T>>(),
|
||||||
min_align_of::<RcBox<T>>())
|
min_align_of::<RcBox<T>>())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,8 +179,8 @@ impl<T> Drop for Weak<T> {
|
|||||||
// the weak count starts at 1, and will only go to
|
// the weak count starts at 1, and will only go to
|
||||||
// zero if all the strong pointers have disappeared.
|
// zero if all the strong pointers have disappeared.
|
||||||
if self.weak() == 0 {
|
if self.weak() == 0 {
|
||||||
exchange_free(self.ptr as *mut u8, size_of::<RcBox<T>>(),
|
deallocate(self.ptr as *mut u8, size_of::<RcBox<T>>(),
|
||||||
min_align_of::<RcBox<T>>())
|
min_align_of::<RcBox<T>>())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,13 +165,8 @@ pub unsafe fn exchange_malloc(size: uint, align: uint) -> *mut u8 {
|
|||||||
#[lang="exchange_free"]
|
#[lang="exchange_free"]
|
||||||
#[inline]
|
#[inline]
|
||||||
// FIXME: #13994 (rustc should pass align and size here)
|
// FIXME: #13994 (rustc should pass align and size here)
|
||||||
pub unsafe fn exchange_free_(ptr: *mut u8) {
|
unsafe fn exchange_free(ptr: *mut u8) {
|
||||||
exchange_free(ptr, 0, 8)
|
deallocate(ptr, 0, 8);
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub unsafe fn exchange_free(ptr: *mut u8, size: uint, align: uint) {
|
|
||||||
deallocate(ptr, size, align);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: #7496
|
// FIXME: #7496
|
||||||
@ -212,7 +207,7 @@ pub unsafe extern "C" fn rust_malloc(size: uint, align: uint) -> *mut u8 {
|
|||||||
#[deprecated]
|
#[deprecated]
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
pub unsafe extern "C" fn rust_free(ptr: *mut u8, size: uint, align: uint) {
|
pub unsafe extern "C" fn rust_free(ptr: *mut u8, size: uint, align: uint) {
|
||||||
exchange_free(ptr, size, align)
|
deallocate(ptr, size, align)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -109,7 +109,7 @@ use ops::Drop;
|
|||||||
use option::{None, Option, Some};
|
use option::{None, Option, Some};
|
||||||
use ptr::RawPtr;
|
use ptr::RawPtr;
|
||||||
use ptr;
|
use ptr;
|
||||||
use rt::heap::{exchange_malloc, exchange_free};
|
use rt::heap::{exchange_malloc, deallocate};
|
||||||
use unstable::finally::try_finally;
|
use unstable::finally::try_finally;
|
||||||
use vec::Vec;
|
use vec::Vec;
|
||||||
|
|
||||||
@ -330,7 +330,7 @@ impl<'a, T: Clone> CloneableVector<T> for &'a [T] {
|
|||||||
ptr::read(&*p.offset(j));
|
ptr::read(&*p.offset(j));
|
||||||
}
|
}
|
||||||
// FIXME: #13994 (should pass align and size here)
|
// FIXME: #13994 (should pass align and size here)
|
||||||
exchange_free(ret as *mut u8, 0, 8);
|
deallocate(ret as *mut u8, 0, 8);
|
||||||
});
|
});
|
||||||
mem::transmute(ret)
|
mem::transmute(ret)
|
||||||
}
|
}
|
||||||
@ -377,7 +377,7 @@ impl<'a, T: Clone> CloneableVector<T> for &'a [T] {
|
|||||||
ptr::read(&*p.offset(j));
|
ptr::read(&*p.offset(j));
|
||||||
}
|
}
|
||||||
// FIXME: #13994 (should pass align and size here)
|
// FIXME: #13994 (should pass align and size here)
|
||||||
exchange_free(ret as *mut u8, 0, 8);
|
deallocate(ret as *mut u8, 0, 8);
|
||||||
});
|
});
|
||||||
mem::transmute(ret)
|
mem::transmute(ret)
|
||||||
}
|
}
|
||||||
@ -817,7 +817,7 @@ impl<T> Drop for MoveItems<T> {
|
|||||||
for _x in *self {}
|
for _x in *self {}
|
||||||
unsafe {
|
unsafe {
|
||||||
// FIXME: #13994 (should pass align and size here)
|
// FIXME: #13994 (should pass align and size here)
|
||||||
exchange_free(self.allocation, 0, 8)
|
deallocate(self.allocation, 0, 8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::rt::heap::exchange_free;
|
use std::rt::heap::deallocate;
|
||||||
use std::sync::atomics;
|
use std::sync::atomics;
|
||||||
use std::mem::{min_align_of, size_of};
|
use std::mem::{min_align_of, size_of};
|
||||||
|
|
||||||
@ -191,8 +191,8 @@ impl<T: Share + Send> Drop for Arc<T> {
|
|||||||
|
|
||||||
if self.inner().weak.fetch_sub(1, atomics::Release) == 1 {
|
if self.inner().weak.fetch_sub(1, atomics::Release) == 1 {
|
||||||
atomics::fence(atomics::Acquire);
|
atomics::fence(atomics::Acquire);
|
||||||
unsafe { exchange_free(self.x as *mut u8, size_of::<ArcInner<T>>(),
|
unsafe { deallocate(self.x as *mut u8, size_of::<ArcInner<T>>(),
|
||||||
min_align_of::<ArcInner<T>>()) }
|
min_align_of::<ArcInner<T>>()) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -242,8 +242,8 @@ impl<T: Share + Send> Drop for Weak<T> {
|
|||||||
// the memory orderings
|
// the memory orderings
|
||||||
if self.inner().weak.fetch_sub(1, atomics::Release) == 1 {
|
if self.inner().weak.fetch_sub(1, atomics::Release) == 1 {
|
||||||
atomics::fence(atomics::Acquire);
|
atomics::fence(atomics::Acquire);
|
||||||
unsafe { exchange_free(self.x as *mut u8, size_of::<ArcInner<T>>(),
|
unsafe { deallocate(self.x as *mut u8, size_of::<ArcInner<T>>(),
|
||||||
min_align_of::<ArcInner<T>>()) }
|
min_align_of::<ArcInner<T>>()) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user