Skip to content

Commit 99986a5

Browse files
committed
Rollup merge of rust-lang#55889 - RalfJung:global-alloc, r=alexcrichton
global allocators: add a few comments These comments answer some questions that came up when I tried to understand how the control flow works for the global allocator, `Global` and `System`. r? @alexcrichton
2 parents c246a29 + 075983c commit 99986a5

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/liballoc/alloc.rs

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ use core::usize;
2121
pub use core::alloc::*;
2222

2323
extern "Rust" {
24+
// These are the magic symbols to call the global allocator. rustc generates
25+
// them from the `#[global_allocator]` attribute if there is one, or uses the
26+
// default implementations in libstd (`__rdl_alloc` etc in `src/libstd/alloc.rs`)
27+
// otherwise.
2428
#[allocator]
2529
#[rustc_allocator_nounwind]
2630
fn __rust_alloc(size: usize, align: usize) -> *mut u8;

src/libstd/alloc.rs

+5
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ pub use alloc_crate::alloc::*;
142142
#[derive(Debug, Copy, Clone)]
143143
pub struct System;
144144

145+
// The Alloc impl just forwards to the GlobalAlloc impl, which is in `std::sys::*::alloc`.
145146
#[unstable(feature = "allocator_api", issue = "32838")]
146147
unsafe impl Alloc for System {
147148
#[inline]
@@ -226,6 +227,10 @@ pub fn rust_oom(layout: Layout) -> ! {
226227
#[unstable(feature = "alloc_internals", issue = "0")]
227228
pub mod __default_lib_allocator {
228229
use super::{System, Layout, GlobalAlloc};
230+
// These magic symbol names are used as a fallback for implementing the
231+
// `__rust_alloc` etc symbols (see `src/liballoc/alloc.rs) when there is
232+
// no `#[global_allocator]` attribute.
233+
229234
// for symbol names src/librustc/middle/allocator.rs
230235
// for signatures src/librustc_allocator/lib.rs
231236

0 commit comments

Comments
 (0)