Skip to content

Commit b6cadb4

Browse files
robert-w-griesphil-opp
authored andcommitted
Custom oom handler that calls panic instead of intrinsics::abort (#7)
1 parent 7979db9 commit b6cadb4

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ unsafe impl Alloc for Heap {
132132
unsafe fn dealloc(&mut self, ptr: *mut u8, layout: Layout) {
133133
self.deallocate(ptr, layout)
134134
}
135+
136+
fn oom(&mut self, _: AllocErr) -> ! {
137+
panic!("Out of memory");
138+
}
135139
}
136140

137141
pub struct LockedHeap(Mutex<Heap>);
@@ -171,6 +175,10 @@ unsafe impl<'a> Alloc for &'a LockedHeap {
171175
unsafe fn dealloc(&mut self, ptr: *mut u8, layout: Layout) {
172176
self.0.lock().deallocate(ptr, layout)
173177
}
178+
179+
fn oom(&mut self, _: AllocErr) -> ! {
180+
panic!("Out of memory");
181+
}
174182
}
175183

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

0 commit comments

Comments
 (0)