Skip to content

Commit 9450198

Browse files
committed
migrate from exchange_malloc to allocate
This is now only used internally by the compiler.
1 parent 83eefa8 commit 9450198

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

src/liballoc/heap.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,8 @@ pub fn stats_print() {
119119
/// The allocator for unique pointers.
120120
#[cfg(not(test))]
121121
#[lang="exchange_malloc"]
122-
#[inline(always)]
123-
pub unsafe fn exchange_malloc_(size: uint, align: uint) -> *mut u8 {
124-
exchange_malloc(size, align)
125-
}
126-
127-
/// The allocator for unique pointers.
128122
#[inline]
129-
pub unsafe fn exchange_malloc(size: uint, align: uint) -> *mut u8 {
123+
unsafe fn exchange_malloc(size: uint, align: uint) -> *mut u8 {
130124
// The compiler never calls `exchange_free` on ~ZeroSizeType, so zero-size
131125
// allocations can point to this `static`. It would be incorrect to use a null
132126
// pointer, due to enums assuming types like unique pointers are never null.
@@ -167,16 +161,16 @@ unsafe fn closure_exchange_malloc(drop_glue: fn(*mut u8), size: uint, align: uin
167161
#[doc(hidden)]
168162
#[deprecated]
169163
#[cfg(not(test))]
170-
pub unsafe extern "C" fn rust_malloc(size: uint, align: uint) -> *mut u8 {
171-
exchange_malloc(size, align)
164+
pub unsafe extern "C" fn rust_allocate(size: uint, align: uint) -> *mut u8 {
165+
allocate(size, align)
172166
}
173167

174168
// hack for libcore
175169
#[no_mangle]
176170
#[doc(hidden)]
177171
#[deprecated]
178172
#[cfg(not(test))]
179-
pub unsafe extern "C" fn rust_free(ptr: *mut u8, size: uint, align: uint) {
173+
pub unsafe extern "C" fn rust_deallocate(ptr: *mut u8, size: uint, align: uint) {
180174
deallocate(ptr, size, align)
181175
}
182176

src/libarena/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use std::mem;
3838
use std::num;
3939
use std::ptr::read;
4040
use std::rc::Rc;
41-
use std::rt::heap::exchange_malloc;
41+
use std::rt::heap::allocate;
4242

4343
// The way arena uses arrays is really deeply awful. The arrays are
4444
// allocated, and have capacities reserved, but the fill for the array
@@ -358,8 +358,7 @@ impl<T> TypedArenaChunk<T> {
358358
size = size.checked_add(&elems_size).unwrap();
359359

360360
let mut chunk = unsafe {
361-
let chunk = exchange_malloc(size,
362-
mem::min_align_of::<TypedArenaChunk<T>>());
361+
let chunk = allocate(size, mem::min_align_of::<TypedArenaChunk<T>>());
363362
let mut chunk: Box<TypedArenaChunk<T>> = mem::transmute(chunk);
364363
mem::overwrite(&mut chunk.next, next);
365364
chunk

src/libcore/should_not_exist.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ use str::StrSlice;
4444

4545
#[allow(ctypes)]
4646
extern {
47-
fn rust_malloc(size: uint, align: uint) -> *u8;
48-
fn rust_free(ptr: *u8, size: uint, align: uint);
47+
fn rust_allocate(size: uint, align: uint) -> *u8;
48+
fn rust_deallocate(ptr: *u8, size: uint, align: uint);
4949
}
5050

5151
unsafe fn alloc(cap: uint) -> *mut Vec<()> {
5252
let cap = cap.checked_add(&mem::size_of::<Vec<()>>()).unwrap();
5353
// this should use the real alignment, but the new representation will take care of that
54-
let ret = rust_malloc(cap, 8) as *mut Vec<()>;
54+
let ret = rust_allocate(cap, 8) as *mut Vec<()>;
5555
if ret.is_null() {
5656
intrinsics::abort();
5757
}
@@ -119,7 +119,7 @@ impl FromIterator<char> for ~str {
119119
&(*ptr).data,
120120
len);
121121
// FIXME: #13994: port to the sized deallocation API when available
122-
rust_free(ptr as *u8, 0, 8);
122+
rust_deallocate(ptr as *u8, 0, 8);
123123
mem::forget(ret);
124124
ret = mem::transmute(ptr2);
125125
ptr = ptr2;
@@ -191,7 +191,7 @@ impl<A: Clone> Clone for ~[A] {
191191
for j in range(0, *i as int) {
192192
ptr::read(&*p.offset(j));
193193
}
194-
rust_free(ret as *u8, 0, 8);
194+
rust_deallocate(ret as *u8, 0, 8);
195195
});
196196
mem::transmute(ret)
197197
}

src/libstd/slice.rs

+3-3
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, deallocate};
112+
use rt::heap::{allocate, deallocate};
113113
use unstable::finally::try_finally;
114114
use vec::Vec;
115115

@@ -304,7 +304,7 @@ impl<'a, T: Clone> CloneableVector<T> for &'a [T] {
304304

305305
unsafe {
306306
// this should pass the real required alignment
307-
let ret = exchange_malloc(size, 8) as *mut RawVec<()>;
307+
let ret = allocate(size, 8) as *mut RawVec<()>;
308308

309309
let a_size = mem::size_of::<T>();
310310
let a_size = if a_size == 0 {1} else {a_size};
@@ -968,7 +968,7 @@ mod tests {
968968
assert_eq!(v_b[0], 2);
969969
assert_eq!(v_b[1], 3);
970970

971-
// Test on exchange heap.
971+
// Test `Box<[T]>`
972972
let vec_unique = box [1, 2, 3, 4, 5, 6];
973973
let v_d = vec_unique.slice(1u, 6u).to_owned();
974974
assert_eq!(v_d.len(), 5u);

0 commit comments

Comments
 (0)