global allocators: add a few comments
This commit is contained in:
parent
d1d79ae3ad
commit
075983c70b
|
@ -21,6 +21,10 @@ use core::usize;
|
||||||
pub use core::alloc::*;
|
pub use core::alloc::*;
|
||||||
|
|
||||||
extern "Rust" {
|
extern "Rust" {
|
||||||
|
// These are the magic symbols to call the global allocator. rustc generates
|
||||||
|
// them from the `#[global_allocator]` attribute if there is one, or uses the
|
||||||
|
// default implementations in libstd (`__rdl_alloc` etc in `src/libstd/alloc.rs`)
|
||||||
|
// otherwise.
|
||||||
#[allocator]
|
#[allocator]
|
||||||
#[rustc_allocator_nounwind]
|
#[rustc_allocator_nounwind]
|
||||||
fn __rust_alloc(size: usize, align: usize) -> *mut u8;
|
fn __rust_alloc(size: usize, align: usize) -> *mut u8;
|
||||||
|
|
|
@ -142,6 +142,7 @@ pub use alloc_crate::alloc::*;
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub struct System;
|
pub struct System;
|
||||||
|
|
||||||
|
// The Alloc impl just forwards to the GlobalAlloc impl, which is in `std::sys::*::alloc`.
|
||||||
#[unstable(feature = "allocator_api", issue = "32838")]
|
#[unstable(feature = "allocator_api", issue = "32838")]
|
||||||
unsafe impl Alloc for System {
|
unsafe impl Alloc for System {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -226,6 +227,10 @@ pub fn rust_oom(layout: Layout) -> ! {
|
||||||
#[unstable(feature = "alloc_internals", issue = "0")]
|
#[unstable(feature = "alloc_internals", issue = "0")]
|
||||||
pub mod __default_lib_allocator {
|
pub mod __default_lib_allocator {
|
||||||
use super::{System, Layout, GlobalAlloc};
|
use super::{System, Layout, GlobalAlloc};
|
||||||
|
// These magic symbol names are used as a fallback for implementing the
|
||||||
|
// `__rust_alloc` etc symbols (see `src/liballoc/alloc.rs) when there is
|
||||||
|
// no `#[global_allocator]` attribute.
|
||||||
|
|
||||||
// for symbol names src/librustc/middle/allocator.rs
|
// for symbol names src/librustc/middle/allocator.rs
|
||||||
// for signatures src/librustc_allocator/lib.rs
|
// for signatures src/librustc_allocator/lib.rs
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue