return an AllocError instead of panicing in Heap::with_cell_capacity
This commit is contained in:
@@ -596,7 +596,7 @@ impl Heap {
|
|||||||
self.resource_err_loc
|
self.resource_err_loc
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn with_cell_capacity(cap: usize) -> Result<Self, usize> {
|
pub(crate) fn with_cell_capacity(cap: usize) -> Result<Self, AllocError> {
|
||||||
let ptr = unsafe {
|
let ptr = unsafe {
|
||||||
let layout = alloc::Layout::from_size_align(
|
let layout = alloc::Layout::from_size_align(
|
||||||
cap * size_of::<HeapCellValue>(),
|
cap * size_of::<HeapCellValue>(),
|
||||||
@@ -607,7 +607,7 @@ impl Heap {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if ptr.is_null() {
|
if ptr.is_null() {
|
||||||
panic!("could not allocate {} bytes for heap!", heap_index!(cap))
|
Err(AllocError)
|
||||||
} else {
|
} else {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
inner: InnerHeap {
|
inner: InnerHeap {
|
||||||
|
|||||||
Reference in New Issue
Block a user