]> git.lizzy.rs Git - rust.git/commitdiff
global allocators: add a few comments
authorRalf Jung <post@ralfj.de>
Mon, 12 Nov 2018 08:00:39 +0000 (09:00 +0100)
committerRalf Jung <post@ralfj.de>
Mon, 12 Nov 2018 08:01:57 +0000 (09:01 +0100)
src/liballoc/alloc.rs
src/libstd/alloc.rs

index 3bd0c243b39acfd3e6eca39abf5b51c08f52b0ff..1a8a081e16fadc105ae6c1b46221f66f4673b149 100644 (file)
 pub use core::alloc::*;
 
 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]
     #[rustc_allocator_nounwind]
     fn __rust_alloc(size: usize, align: usize) -> *mut u8;
index 485b2ffe1975ed5c5973066ceb1df9d6b9d8efac..9c0573964702e7425428534f0d5aad79fe150add 100644 (file)
 #[derive(Debug, Copy, Clone)]
 pub struct System;
 
+// The Alloc impl just forwards to the GlobalAlloc impl, which is in `std::sys::*::alloc`.
 #[unstable(feature = "allocator_api", issue = "32838")]
 unsafe impl Alloc for System {
     #[inline]
@@ -226,6 +227,10 @@ pub fn rust_oom(layout: Layout) -> ! {
 #[unstable(feature = "alloc_internals", issue = "0")]
 pub mod __default_lib_allocator {
     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 signatures src/librustc_allocator/lib.rs