mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-30 00:23:41 +00:00
migrate from exchange_malloc
to allocate
This is now only used internally by the compiler.
This commit is contained in:
parent
83eefa88c1
commit
945019830b
@ -119,14 +119,8 @@ pub fn stats_print() {
|
||||
/// The allocator for unique pointers.
|
||||
#[cfg(not(test))]
|
||||
#[lang="exchange_malloc"]
|
||||
#[inline(always)]
|
||||
pub unsafe fn exchange_malloc_(size: uint, align: uint) -> *mut u8 {
|
||||
exchange_malloc(size, align)
|
||||
}
|
||||
|
||||
/// The allocator for unique pointers.
|
||||
#[inline]
|
||||
pub unsafe fn exchange_malloc(size: uint, align: uint) -> *mut u8 {
|
||||
unsafe fn exchange_malloc(size: uint, align: uint) -> *mut u8 {
|
||||
// The compiler never calls `exchange_free` on ~ZeroSizeType, so zero-size
|
||||
// allocations can point to this `static`. It would be incorrect to use a null
|
||||
// pointer, due to enums assuming types like unique pointers are never null.
|
||||
@ -167,8 +161,8 @@ unsafe fn closure_exchange_malloc(drop_glue: fn(*mut u8), size: uint, align: uin
|
||||
#[doc(hidden)]
|
||||
#[deprecated]
|
||||
#[cfg(not(test))]
|
||||
pub unsafe extern "C" fn rust_malloc(size: uint, align: uint) -> *mut u8 {
|
||||
exchange_malloc(size, align)
|
||||
pub unsafe extern "C" fn rust_allocate(size: uint, align: uint) -> *mut u8 {
|
||||
allocate(size, align)
|
||||
}
|
||||
|
||||
// hack for libcore
|
||||
@ -176,7 +170,7 @@ pub unsafe extern "C" fn rust_malloc(size: uint, align: uint) -> *mut u8 {
|
||||
#[doc(hidden)]
|
||||
#[deprecated]
|
||||
#[cfg(not(test))]
|
||||
pub unsafe extern "C" fn rust_free(ptr: *mut u8, size: uint, align: uint) {
|
||||
pub unsafe extern "C" fn rust_deallocate(ptr: *mut u8, size: uint, align: uint) {
|
||||
deallocate(ptr, size, align)
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ use std::mem;
|
||||
use std::num;
|
||||
use std::ptr::read;
|
||||
use std::rc::Rc;
|
||||
use std::rt::heap::exchange_malloc;
|
||||
use std::rt::heap::allocate;
|
||||
|
||||
// The way arena uses arrays is really deeply awful. The arrays are
|
||||
// allocated, and have capacities reserved, but the fill for the array
|
||||
@ -358,8 +358,7 @@ impl<T> TypedArenaChunk<T> {
|
||||
size = size.checked_add(&elems_size).unwrap();
|
||||
|
||||
let mut chunk = unsafe {
|
||||
let chunk = exchange_malloc(size,
|
||||
mem::min_align_of::<TypedArenaChunk<T>>());
|
||||
let chunk = allocate(size, mem::min_align_of::<TypedArenaChunk<T>>());
|
||||
let mut chunk: Box<TypedArenaChunk<T>> = mem::transmute(chunk);
|
||||
mem::overwrite(&mut chunk.next, next);
|
||||
chunk
|
||||
|
@ -44,14 +44,14 @@ use str::StrSlice;
|
||||
|
||||
#[allow(ctypes)]
|
||||
extern {
|
||||
fn rust_malloc(size: uint, align: uint) -> *u8;
|
||||
fn rust_free(ptr: *u8, size: uint, align: uint);
|
||||
fn rust_allocate(size: uint, align: uint) -> *u8;
|
||||
fn rust_deallocate(ptr: *u8, size: uint, align: uint);
|
||||
}
|
||||
|
||||
unsafe fn alloc(cap: uint) -> *mut Vec<()> {
|
||||
let cap = cap.checked_add(&mem::size_of::<Vec<()>>()).unwrap();
|
||||
// this should use the real alignment, but the new representation will take care of that
|
||||
let ret = rust_malloc(cap, 8) as *mut Vec<()>;
|
||||
let ret = rust_allocate(cap, 8) as *mut Vec<()>;
|
||||
if ret.is_null() {
|
||||
intrinsics::abort();
|
||||
}
|
||||
@ -119,7 +119,7 @@ impl FromIterator<char> for ~str {
|
||||
&(*ptr).data,
|
||||
len);
|
||||
// FIXME: #13994: port to the sized deallocation API when available
|
||||
rust_free(ptr as *u8, 0, 8);
|
||||
rust_deallocate(ptr as *u8, 0, 8);
|
||||
mem::forget(ret);
|
||||
ret = mem::transmute(ptr2);
|
||||
ptr = ptr2;
|
||||
@ -191,7 +191,7 @@ impl<A: Clone> Clone for ~[A] {
|
||||
for j in range(0, *i as int) {
|
||||
ptr::read(&*p.offset(j));
|
||||
}
|
||||
rust_free(ret as *u8, 0, 8);
|
||||
rust_deallocate(ret as *u8, 0, 8);
|
||||
});
|
||||
mem::transmute(ret)
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ use ops::Drop;
|
||||
use option::{None, Option, Some};
|
||||
use ptr::RawPtr;
|
||||
use ptr;
|
||||
use rt::heap::{exchange_malloc, deallocate};
|
||||
use rt::heap::{allocate, deallocate};
|
||||
use unstable::finally::try_finally;
|
||||
use vec::Vec;
|
||||
|
||||
@ -304,7 +304,7 @@ impl<'a, T: Clone> CloneableVector<T> for &'a [T] {
|
||||
|
||||
unsafe {
|
||||
// this should pass the real required alignment
|
||||
let ret = exchange_malloc(size, 8) as *mut RawVec<()>;
|
||||
let ret = allocate(size, 8) as *mut RawVec<()>;
|
||||
|
||||
let a_size = mem::size_of::<T>();
|
||||
let a_size = if a_size == 0 {1} else {a_size};
|
||||
@ -968,7 +968,7 @@ mod tests {
|
||||
assert_eq!(v_b[0], 2);
|
||||
assert_eq!(v_b[1], 3);
|
||||
|
||||
// Test on exchange heap.
|
||||
// Test `Box<[T]>`
|
||||
let vec_unique = box [1, 2, 3, 4, 5, 6];
|
||||
let v_d = vec_unique.slice(1u, 6u).to_owned();
|
||||
assert_eq!(v_d.len(), 5u);
|
||||
|
Loading…
Reference in New Issue
Block a user