MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / try_alloc

Function try_alloc

crates/core/src/error/boxed.rs:14–24  ·  view source on GitHub ↗
(layout: Layout)

Source from the content-addressed store, hash-verified

12/// Same as `alloc::alloc::alloc`: layout must have non-zero size.
13#[inline]
14pub(crate) unsafe fn try_alloc(layout: Layout) -> Result<NonNull<u8>, OutOfMemory> {
15 // Safety: same as our safety conditions.
16 debug_assert!(layout.size() > 0);
17 let ptr = unsafe { std_alloc::alloc::alloc(layout) };
18
19 if let Some(ptr) = NonNull::new(ptr) {
20 Ok(ptr)
21 } else {
22 Err(OutOfMemory::new(layout.size()))
23 }
24}
25
26/// Create a `Box<T>`, or return an `OutOfMemory` error.
27#[inline]

Callers 3

try_new_uninit_boxFunction · 0.70
new_uninit_boxFunction · 0.50
new_uninit_boxed_sliceFunction · 0.50

Calls 4

allocFunction · 0.85
OkFunction · 0.85
newFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected