diff options
| author | Mike Hommey <mh@glandium.org> | 2018-05-15 09:56:46 +0900 |
|---|---|---|
| committer | Mike Hommey <mh@glandium.org> | 2018-05-30 05:35:48 +0900 |
| commit | 0f4ef003ac1691d04f0ce519d1d78696689534aa (patch) | |
| tree | 389cc750501eda02bc699d4ac967f0000a546fa1 /src/liballoc/alloc.rs | |
| parent | 5015fa346c1bf7e295fc16996ed0d3309c84f09a (diff) | |
| download | rust-0f4ef003ac1691d04f0ce519d1d78696689534aa.tar.gz rust-0f4ef003ac1691d04f0ce519d1d78696689534aa.zip | |
Pass a `Layout` to `oom`
As discussed in https://github.com/rust-lang/rust/issues/49668#issuecomment-384893456 and subsequent, there are use-cases where the OOM handler needs to know the size of the allocation that failed. The alignment might also be a cause for allocation failure, so providing it as well can be useful.
Diffstat (limited to 'src/liballoc/alloc.rs')
| -rw-r--r-- | src/liballoc/alloc.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/liballoc/alloc.rs b/src/liballoc/alloc.rs index 4ae8fc649dd..8753c495737 100644 --- a/src/liballoc/alloc.rs +++ b/src/liballoc/alloc.rs @@ -115,7 +115,7 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 { if !ptr.is_null() { ptr as *mut u8 } else { - oom() + oom(layout) } } } @@ -134,12 +134,13 @@ pub(crate) unsafe fn box_free<T: ?Sized>(ptr: Unique<T>) { } #[rustc_allocator_nounwind] -pub fn oom() -> ! { - extern { +pub fn oom(layout: Layout) -> ! { + #[allow(improper_ctypes)] + extern "Rust" { #[lang = "oom"] - fn oom_impl() -> !; + fn oom_impl(layout: Layout) -> !; } - unsafe { oom_impl() } + unsafe { oom_impl(layout) } } #[cfg(test)] @@ -154,7 +155,7 @@ mod tests { unsafe { let layout = Layout::from_size_align(1024, 1).unwrap(); let ptr = Global.alloc_zeroed(layout.clone()) - .unwrap_or_else(|_| oom()); + .unwrap_or_else(|_| oom(layout)); let mut i = ptr.cast::<u8>().as_ptr(); let end = i.offset(layout.size() as isize); |
