Skip to content

Commit 69b321c

Browse files
committed
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.
1 parent 32988db commit 69b321c

File tree

4 files changed

+17
-22
lines changed

4 files changed

+17
-22
lines changed

src/libstd/rc.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use option::{Option, Some, None};
3333
use ptr;
3434
use ptr::RawPtr;
3535
use mem::{min_align_of, size_of};
36-
use rt::heap::exchange_free;
36+
use rt::heap::deallocate;
3737

3838
struct RcBox<T> {
3939
value: T,
@@ -105,8 +105,8 @@ impl<T> Drop for Rc<T> {
105105
self.dec_weak();
106106

107107
if self.weak() == 0 {
108-
exchange_free(self.ptr as *mut u8, size_of::<RcBox<T>>(),
109-
min_align_of::<RcBox<T>>())
108+
deallocate(self.ptr as *mut u8, size_of::<RcBox<T>>(),
109+
min_align_of::<RcBox<T>>())
110110
}
111111
}
112112
}
@@ -179,8 +179,8 @@ impl<T> Drop for Weak<T> {
179179
// the weak count starts at 1, and will only go to
180180
// zero if all the strong pointers have disappeared.
181181
if self.weak() == 0 {
182-
exchange_free(self.ptr as *mut u8, size_of::<RcBox<T>>(),
183-
min_align_of::<RcBox<T>>())
182+
deallocate(self.ptr as *mut u8, size_of::<RcBox<T>>(),
183+
min_align_of::<RcBox<T>>())
184184
}
185185
}
186186
}

src/libstd/rt/heap.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,8 @@ pub unsafe fn exchange_malloc(size: uint, align: uint) -> *mut u8 {
165165
#[lang="exchange_free"]
166166
#[inline]
167167
// FIXME: #13994 (rustc should pass align and size here)
168-
pub unsafe fn exchange_free_(ptr: *mut u8) {
169-
exchange_free(ptr, 0, 8)
170-
}
171-
172-
#[inline]
173-
pub unsafe fn exchange_free(ptr: *mut u8, size: uint, align: uint) {
174-
deallocate(ptr, size, align);
168+
unsafe fn exchange_free(ptr: *mut u8) {
169+
deallocate(ptr, 0, 8);
175170
}
176171

177172
// FIXME: #7496
@@ -212,7 +207,7 @@ pub unsafe extern "C" fn rust_malloc(size: uint, align: uint) -> *mut u8 {
212207
#[deprecated]
213208
#[cfg(not(test))]
214209
pub unsafe extern "C" fn rust_free(ptr: *mut u8, size: uint, align: uint) {
215-
exchange_free(ptr, size, align)
210+
deallocate(ptr, size, align)
216211
}
217212

218213
#[cfg(test)]

src/libstd/slice.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ use ops::Drop;
109109
use option::{None, Option, Some};
110110
use ptr::RawPtr;
111111
use ptr;
112-
use rt::heap::{exchange_malloc, exchange_free};
112+
use rt::heap::{exchange_malloc, deallocate};
113113
use unstable::finally::try_finally;
114114
use vec::Vec;
115115

@@ -330,7 +330,7 @@ impl<'a, T: Clone> CloneableVector<T> for &'a [T] {
330330
ptr::read(&*p.offset(j));
331331
}
332332
// FIXME: #13994 (should pass align and size here)
333-
exchange_free(ret as *mut u8, 0, 8);
333+
deallocate(ret as *mut u8, 0, 8);
334334
});
335335
mem::transmute(ret)
336336
}
@@ -377,7 +377,7 @@ impl<'a, T: Clone> CloneableVector<T> for &'a [T] {
377377
ptr::read(&*p.offset(j));
378378
}
379379
// FIXME: #13994 (should pass align and size here)
380-
exchange_free(ret as *mut u8, 0, 8);
380+
deallocate(ret as *mut u8, 0, 8);
381381
});
382382
mem::transmute(ret)
383383
}
@@ -817,7 +817,7 @@ impl<T> Drop for MoveItems<T> {
817817
for _x in *self {}
818818
unsafe {
819819
// FIXME: #13994 (should pass align and size here)
820-
exchange_free(self.allocation, 0, 8)
820+
deallocate(self.allocation, 0, 8)
821821
}
822822
}
823823
}

src/libsync/arc.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
use std::mem;
1717
use std::ptr;
18-
use std::rt::heap::exchange_free;
18+
use std::rt::heap::deallocate;
1919
use std::sync::atomics;
2020
use std::mem::{min_align_of, size_of};
2121

@@ -191,8 +191,8 @@ impl<T: Share + Send> Drop for Arc<T> {
191191

192192
if self.inner().weak.fetch_sub(1, atomics::Release) == 1 {
193193
atomics::fence(atomics::Acquire);
194-
unsafe { exchange_free(self.x as *mut u8, size_of::<ArcInner<T>>(),
195-
min_align_of::<ArcInner<T>>()) }
194+
unsafe { deallocate(self.x as *mut u8, size_of::<ArcInner<T>>(),
195+
min_align_of::<ArcInner<T>>()) }
196196
}
197197
}
198198
}
@@ -242,8 +242,8 @@ impl<T: Share + Send> Drop for Weak<T> {
242242
// the memory orderings
243243
if self.inner().weak.fetch_sub(1, atomics::Release) == 1 {
244244
atomics::fence(atomics::Acquire);
245-
unsafe { exchange_free(self.x as *mut u8, size_of::<ArcInner<T>>(),
246-
min_align_of::<ArcInner<T>>()) }
245+
unsafe { deallocate(self.x as *mut u8, size_of::<ArcInner<T>>(),
246+
min_align_of::<ArcInner<T>>()) }
247247
}
248248
}
249249
}

0 commit comments

Comments
 (0)