mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-10-10 08:18:14 +03:00
Fix bug when loading heap
Need to grow as needed.
This commit is contained in:
@@ -50,6 +50,7 @@ extern size_t heap_size;
|
||||
|
||||
void heap_init(void);
|
||||
void heap_delete(void);
|
||||
void heap_grow(size_t new_size);
|
||||
|
||||
int32_t heap_alloc_slot(enum vm_pointer_type type);
|
||||
void heap_ref(int slot);
|
||||
|
||||
+3
-1
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "system4/string.h"
|
||||
#include "vm.h"
|
||||
#include "vm/heap.h"
|
||||
@@ -45,8 +46,9 @@ static const char *vm_ptrtype_string(enum vm_pointer_type type) {
|
||||
return "INVALID POINTER TYPE";
|
||||
}
|
||||
|
||||
static void heap_grow(size_t new_size)
|
||||
void heap_grow(size_t new_size)
|
||||
{
|
||||
assert(new_size > heap_size);
|
||||
heap = xrealloc(heap, sizeof(struct vm_pointer) * new_size);
|
||||
heap_free_stack = xrealloc(heap_free_stack, sizeof(int32_t) * new_size);
|
||||
for (size_t i = heap_size; i < new_size; i++) {
|
||||
|
||||
@@ -256,6 +256,9 @@ static void delete_heap(void)
|
||||
// Out-of-order allocations would break the above assumption!
|
||||
static void alloc_heap_slot(int slot)
|
||||
{
|
||||
if ((size_t)slot >= heap_size) {
|
||||
heap_grow(heap_size * 2);
|
||||
}
|
||||
heap_free_stack[slot] = heap_free_stack[heap_free_ptr];
|
||||
heap_free_ptr++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user