Skip to content

Custom oom handler that calls panic instead of abort #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 15, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ unsafe impl Alloc for Heap {
unsafe fn dealloc(&mut self, ptr: *mut u8, layout: Layout) {
self.deallocate(ptr, layout)
}

fn oom(&mut self, _: AllocErr) -> ! {
panic!("Out of memory");
}
}

pub struct LockedHeap(Mutex<Heap>);
Expand Down Expand Up @@ -171,6 +175,10 @@ unsafe impl<'a> Alloc for &'a LockedHeap {
unsafe fn dealloc(&mut self, ptr: *mut u8, layout: Layout) {
self.0.lock().deallocate(ptr, layout)
}

fn oom(&mut self, _: AllocErr) -> ! {
panic!("Out of memory");
}
}

/// Align downwards. Returns the greatest x with alignment `align`
Expand Down