Separate alloc::heap::Alloc trait for stage0 #[global_allocator]
This commit is contained in:
parent
e521b8b472
commit
5e5a0c21fc
|
@ -19,7 +19,6 @@ dependencies = [
|
|||
name = "alloc_jemalloc"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"alloc 0.0.0",
|
||||
"alloc_system 0.0.0",
|
||||
"build_helper 0.1.0",
|
||||
"cc 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -32,7 +31,6 @@ dependencies = [
|
|||
name = "alloc_system"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"alloc 0.0.0",
|
||||
"compiler_builtins 0.0.0",
|
||||
"core 0.0.0",
|
||||
"dlmalloc 0.0.0",
|
||||
|
|
|
@ -22,11 +22,6 @@ use core::usize;
|
|||
#[doc(inline)]
|
||||
pub use core::alloc::*;
|
||||
|
||||
#[doc(hidden)]
|
||||
pub mod __core {
|
||||
pub use core::*;
|
||||
}
|
||||
|
||||
extern "Rust" {
|
||||
#[allocator]
|
||||
#[rustc_allocator_nounwind]
|
||||
|
|
|
@ -0,0 +1,98 @@
|
|||
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
pub use alloc::{Excess, Layout, AllocErr, CannotReallocInPlace};
|
||||
use core::alloc::Alloc as CoreAlloc;
|
||||
|
||||
#[doc(hidden)]
|
||||
pub mod __core {
|
||||
pub use core::*;
|
||||
}
|
||||
|
||||
/// Compatibility with older versions of #[global_allocator] during bootstrap
|
||||
pub unsafe trait Alloc {
|
||||
unsafe fn alloc(&mut self, layout: Layout) -> Result<*mut u8, AllocErr>;
|
||||
unsafe fn dealloc(&mut self, ptr: *mut u8, layout: Layout);
|
||||
fn oom(&mut self, err: AllocErr) -> !;
|
||||
fn usable_size(&self, layout: &Layout) -> (usize, usize);
|
||||
unsafe fn realloc(&mut self,
|
||||
ptr: *mut u8,
|
||||
layout: Layout,
|
||||
new_layout: Layout) -> Result<*mut u8, AllocErr>;
|
||||
unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<*mut u8, AllocErr>;
|
||||
unsafe fn alloc_excess(&mut self, layout: Layout) -> Result<Excess, AllocErr>;
|
||||
unsafe fn realloc_excess(&mut self,
|
||||
ptr: *mut u8,
|
||||
layout: Layout,
|
||||
new_layout: Layout) -> Result<Excess, AllocErr>;
|
||||
unsafe fn grow_in_place(&mut self,
|
||||
ptr: *mut u8,
|
||||
layout: Layout,
|
||||
new_layout: Layout) -> Result<(), CannotReallocInPlace>;
|
||||
unsafe fn shrink_in_place(&mut self,
|
||||
ptr: *mut u8,
|
||||
layout: Layout,
|
||||
new_layout: Layout) -> Result<(), CannotReallocInPlace>;
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
unsafe impl<T> Alloc for T where T: CoreAlloc {
|
||||
unsafe fn alloc(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> {
|
||||
CoreAlloc::alloc(self, layout)
|
||||
}
|
||||
|
||||
unsafe fn dealloc(&mut self, ptr: *mut u8, layout: Layout) {
|
||||
CoreAlloc::dealloc(self, ptr, layout)
|
||||
}
|
||||
|
||||
fn oom(&mut self, err: AllocErr) -> ! {
|
||||
CoreAlloc::oom(self, err)
|
||||
}
|
||||
|
||||
fn usable_size(&self, layout: &Layout) -> (usize, usize) {
|
||||
CoreAlloc::usable_size(self, layout)
|
||||
}
|
||||
|
||||
unsafe fn realloc(&mut self,
|
||||
ptr: *mut u8,
|
||||
layout: Layout,
|
||||
new_layout: Layout) -> Result<*mut u8, AllocErr> {
|
||||
CoreAlloc::realloc(self, ptr, layout, new_layout)
|
||||
}
|
||||
|
||||
unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> {
|
||||
CoreAlloc::alloc_zeroed(self, layout)
|
||||
}
|
||||
|
||||
unsafe fn alloc_excess(&mut self, layout: Layout) -> Result<Excess, AllocErr> {
|
||||
CoreAlloc::alloc_excess(self, layout)
|
||||
}
|
||||
|
||||
unsafe fn realloc_excess(&mut self,
|
||||
ptr: *mut u8,
|
||||
layout: Layout,
|
||||
new_layout: Layout) -> Result<Excess, AllocErr> {
|
||||
CoreAlloc::realloc_excess(self, ptr, layout, new_layout)
|
||||
}
|
||||
|
||||
unsafe fn grow_in_place(&mut self,
|
||||
ptr: *mut u8,
|
||||
layout: Layout,
|
||||
new_layout: Layout) -> Result<(), CannotReallocInPlace> {
|
||||
CoreAlloc::grow_in_place(self, ptr, layout, new_layout)
|
||||
}
|
||||
|
||||
unsafe fn shrink_in_place(&mut self,
|
||||
ptr: *mut u8,
|
||||
layout: Layout,
|
||||
new_layout: Layout) -> Result<(), CannotReallocInPlace> {
|
||||
CoreAlloc::shrink_in_place(self, ptr, layout, new_layout)
|
||||
}
|
||||
}
|
|
@ -153,10 +153,16 @@ pub mod alloc;
|
|||
#[unstable(feature = "allocator_api", issue = "32838")]
|
||||
#[rustc_deprecated(since = "1.27.0", reason = "module renamed to `alloc`")]
|
||||
/// Use the `alloc` module instead.
|
||||
#[cfg(not(stage0))]
|
||||
pub mod heap {
|
||||
pub use alloc::*;
|
||||
}
|
||||
|
||||
#[unstable(feature = "allocator_api", issue = "32838")]
|
||||
#[rustc_deprecated(since = "1.27.0", reason = "module renamed to `alloc`")]
|
||||
#[cfg(stage0)]
|
||||
pub mod heap;
|
||||
|
||||
// Primitive types using the heaps above
|
||||
|
||||
// Need to conditionally define the mod from `boxed.rs` to avoid
|
||||
|
|
|
@ -12,7 +12,6 @@ test = false
|
|||
doc = false
|
||||
|
||||
[dependencies]
|
||||
alloc = { path = "../liballoc" }
|
||||
alloc_system = { path = "../liballoc_system" }
|
||||
core = { path = "../libcore" }
|
||||
libc = { path = "../rustc/libc_shim" }
|
||||
|
|
|
@ -32,7 +32,7 @@ pub use contents::*;
|
|||
mod contents {
|
||||
use core::ptr;
|
||||
|
||||
use core::heap::{Alloc, AllocErr, Layout};
|
||||
use core::alloc::{Alloc, AllocErr, Layout};
|
||||
use alloc_system::System;
|
||||
use libc::{c_int, c_void, size_t};
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ test = false
|
|||
doc = false
|
||||
|
||||
[dependencies]
|
||||
alloc = { path = "../liballoc" }
|
||||
core = { path = "../libcore" }
|
||||
libc = { path = "../rustc/libc_shim" }
|
||||
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
|
||||
|
|
|
@ -41,7 +41,7 @@ const MIN_ALIGN: usize = 8;
|
|||
#[allow(dead_code)]
|
||||
const MIN_ALIGN: usize = 16;
|
||||
|
||||
use core::heap::{Alloc, AllocErr, Layout, Excess, CannotReallocInPlace};
|
||||
use core::alloc::{Alloc, AllocErr, Layout, Excess, CannotReallocInPlace};
|
||||
|
||||
#[unstable(feature = "allocator_api", issue = "32838")]
|
||||
pub struct System;
|
||||
|
@ -121,7 +121,7 @@ mod platform {
|
|||
|
||||
use MIN_ALIGN;
|
||||
use System;
|
||||
use core::heap::{Alloc, AllocErr, Layout};
|
||||
use core::alloc::{Alloc, AllocErr, Layout};
|
||||
|
||||
#[unstable(feature = "allocator_api", issue = "32838")]
|
||||
unsafe impl<'a> Alloc for &'a System {
|
||||
|
@ -283,7 +283,7 @@ mod platform {
|
|||
|
||||
use MIN_ALIGN;
|
||||
use System;
|
||||
use core::heap::{Alloc, AllocErr, Layout, CannotReallocInPlace};
|
||||
use core::alloc::{Alloc, AllocErr, Layout, CannotReallocInPlace};
|
||||
|
||||
type LPVOID = *mut u8;
|
||||
type HANDLE = LPVOID;
|
||||
|
@ -495,7 +495,7 @@ mod platform {
|
|||
mod platform {
|
||||
extern crate dlmalloc;
|
||||
|
||||
use core::heap::{Alloc, AllocErr, Layout, Excess, CannotReallocInPlace};
|
||||
use core::alloc::{Alloc, AllocErr, Layout, Excess, CannotReallocInPlace};
|
||||
use System;
|
||||
use self::dlmalloc::GlobalDlmalloc;
|
||||
|
||||
|
|
Loading…
Reference in New Issue