smallbox2/
global_alloc.rs1use core::alloc::Layout;
2
3#[cfg(all(not(feature = "std"), feature = "global_alloc_fill"))]
5extern "Rust" {
6 #[rustc_allocator]
14 #[rustc_allocator_nounwind]
15 fn __rust_alloc(size: usize, align: usize) -> *mut u8;
16 #[rustc_allocator_nounwind]
17 fn __rust_dealloc(ptr: *mut u8, size: usize, align: usize);
18}
19
20#[inline(always)]
22pub unsafe fn alloc(layout: Layout) -> *mut u8 {
23 #[cfg(all(not(feature = "std"), feature = "global_alloc_fill"))]
24 return __rust_alloc(layout.size(), layout.align());
25 #[cfg(not(all(not(feature = "std"), feature = "global_alloc_fill")))]
26 std::alloc::alloc(layout)
27}
28
29#[inline(always)]
31pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
32 #[cfg(all(not(feature = "std"), feature = "global_alloc_fill"))]
33 return __rust_dealloc(ptr, layout.size(), layout.align());
34 #[cfg(not(all(not(feature = "std"), feature = "global_alloc_fill")))]
35 std::alloc::dealloc(ptr, layout)
36}