]> Repositorios git - scryer-prolog.git/commitdiff
return an AllocError instead of panicing in Heap::with_cell_capacity
authorSkgland <[email protected]>
Thu, 20 Nov 2025 20:13:17 +0000 (21:13 +0100)
committerBennet Bleßmann <[email protected]>
Thu, 20 Nov 2025 20:13:17 +0000 (21:13 +0100)
src/machine/heap.rs

index 3c92f29b29c9eee4b1ec34b4a915f3ad9cb611b0..18c7addfcbc808eb44a1ddfb44623c2d4dc30d2f 100644 (file)
@@ -596,7 +596,7 @@ impl Heap {
         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 layout = alloc::Layout::from_size_align(
                 cap * size_of::<HeapCellValue>(),
@@ -607,7 +607,7 @@ impl Heap {
         };
 
         if ptr.is_null() {
-            panic!("could not allocate {} bytes for heap!", heap_index!(cap))
+            Err(AllocError)
         } else {
             Ok(Self {
                 inner: InnerHeap {