Skip to content

Commit b6b6bc0

Browse files
authored
Rollup merge of #77738 - RalfJung:alloc-error-handler-comment, r=Amanieu
fix __rust_alloc_error_handler comment `__rust_alloc_error_handler` was added in the same `extern` block as the allocator functions, but the comment there was not actually correct for `__rust_alloc_error_handler`. So move it down to the rest of the default allocator handling with a fixed comment. At least the comment reflects my understanding of what happens, please check carefully. :) r? @Amanieu Cc @haraldh
2 parents 45e3574 + b6bedc8 commit b6b6bc0

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

library/alloc/src/alloc.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ mod tests;
1414

1515
extern "Rust" {
1616
// These are the magic symbols to call the global allocator. rustc generates
17-
// them from the `#[global_allocator]` attribute if there is one, or uses the
18-
// default implementations in libstd (`__rdl_alloc` etc in `src/libstd/alloc.rs`)
17+
// them to call `__rg_alloc` etc if there is a `#[global_allocator]` attribute
18+
// (the code expanding that attribute macro generates those functions), or to call
19+
// the default implementations in libstd (`__rdl_alloc` etc in `src/libstd/alloc.rs`)
1920
// otherwise.
2021
#[rustc_allocator]
2122
#[rustc_allocator_nounwind]
@@ -26,8 +27,6 @@ extern "Rust" {
2627
fn __rust_realloc(ptr: *mut u8, old_size: usize, align: usize, new_size: usize) -> *mut u8;
2728
#[rustc_allocator_nounwind]
2829
fn __rust_alloc_zeroed(size: usize, align: usize) -> *mut u8;
29-
#[rustc_allocator_nounwind]
30-
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;
3130
}
3231

3332
/// The global memory allocator.
@@ -323,6 +322,16 @@ pub(crate) unsafe fn box_free<T: ?Sized>(ptr: Unique<T>) {
323322
}
324323
}
325324

325+
// # Allocation error handler
326+
327+
extern "Rust" {
328+
// This is the magic symbol to call the global alloc error handler. rustc generates
329+
// it to call `__rg_oom` if there is a `#[alloc_error_handler]`, or to call the
330+
// default implementations below (`__rdl_oom`) otherwise.
331+
#[rustc_allocator_nounwind]
332+
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;
333+
}
334+
326335
/// Abort on memory allocation error or failure.
327336
///
328337
/// Callers of memory allocation APIs wishing to abort computation
@@ -367,7 +376,7 @@ pub fn handle_alloc_error(layout: Layout) -> ! {
367376
#[doc(hidden)]
368377
#[allow(unused_attributes)]
369378
#[unstable(feature = "alloc_internals", issue = "none")]
370-
pub mod __default_lib_allocator {
379+
pub mod __alloc_error_handler {
371380
use crate::alloc::Layout;
372381

373382
// called via generated `__rust_alloc_error_handler`

0 commit comments

Comments
 (0)