Skip to content

Commit 3efa247

Browse files
committed
default_alloc_error_hook: call the default hook for alloc instead of duplicating it
1 parent b758149 commit 3efa247

File tree

3 files changed

+3
-12
lines changed

3 files changed

+3
-12
lines changed

library/alloc/src/alloc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ pub mod __alloc_error_handler {
407407
// called via generated `__rust_alloc_error_handler` if there is no
408408
// `#[alloc_error_handler]`.
409409
#[rustc_std_internal_symbol]
410-
pub unsafe fn __rdl_oom(size: usize, _align: usize) -> ! {
410+
pub fn __rdl_oom(size: usize, _align: usize) -> ! {
411411
extern "Rust" {
412412
// This symbol is emitted by rustc next to __rust_alloc_error_handler.
413413
// Its value depends on the -Zoom={panic,abort} compiler option.

library/std/src/alloc.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -344,17 +344,7 @@ pub fn take_alloc_error_hook() -> fn(Layout) {
344344
}
345345

346346
fn default_alloc_error_hook(layout: Layout) {
347-
extern "Rust" {
348-
// This symbol is emitted by rustc next to __rust_alloc_error_handler.
349-
// Its value depends on the -Zoom={panic,abort} compiler option.
350-
static __rust_alloc_error_handler_should_panic: u8;
351-
}
352-
353-
if unsafe { __rust_alloc_error_handler_should_panic != 0 } {
354-
panic!("memory allocation of {} bytes failed", layout.size());
355-
} else {
356-
rtprintpanic!("memory allocation of {} bytes failed\n", layout.size());
357-
}
347+
alloc::alloc::__alloc_error_handler::__rdl_oom(layout.size(), layout.align());
358348
}
359349

360350
#[cfg(not(test))]

library/std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@
362362
// Library features (alloc):
363363
// tidy-alphabetical-start
364364
#![feature(alloc_layout_extra)]
365+
#![feature(alloc_internals)]
365366
#![feature(allocator_api)]
366367
#![feature(get_mut_unchecked)]
367368
#![feature(map_try_insert)]

0 commit comments

Comments
 (0)