Fix crash on 32-bit systems

This commit is contained in:
Justin Ethier 2016-11-22 02:58:01 -05:00
parent ddefaa4167
commit 5810b7c035
2 changed files with 7 additions and 4 deletions

5
gc.c
View file

@ -1417,9 +1417,12 @@ void gc_collector()
//sweep : //sweep :
for (heap_type = 0; heap_type < NUM_HEAP_TYPES; heap_type++) { for (heap_type = 0; heap_type < NUM_HEAP_TYPES; heap_type++) {
gc_sweep(gc_get_heap()->heap[heap_type], heap_type, &freed_tmp); gc_heap *h = gc_get_heap()->heap[heap_type];
if (h) {
gc_sweep(h, heap_type, &freed_tmp);
freed += freed_tmp; freed += freed_tmp;
} }
}
// TODO: this loop only includes smallest 2 heaps, is that sufficient?? // TODO: this loop only includes smallest 2 heaps, is that sufficient??
for (heap_type = 0; heap_type < 2; heap_type++) { for (heap_type = 0; heap_type < 2; heap_type++) {

View file

@ -262,8 +262,8 @@ static bool set_insert(ck_hs_t * hs, const void *value)
void gc_init_heap(long heap_size) void gc_init_heap(long heap_size)
{ {
size_t initial_heap_size = INITIAL_HEAP_SIZE; size_t initial_heap_size = INITIAL_HEAP_SIZE;
Cyc_heap = malloc(sizeof(gc_heap_root)); Cyc_heap = calloc(1, sizeof(gc_heap_root));
Cyc_heap->heap = malloc(sizeof(gc_heap *) * NUM_HEAP_TYPES); Cyc_heap->heap = calloc(1, sizeof(gc_heap *) * NUM_HEAP_TYPES);
Cyc_heap->heap[HEAP_REST] = gc_heap_create(HEAP_REST, initial_heap_size, 0, 0); Cyc_heap->heap[HEAP_REST] = gc_heap_create(HEAP_REST, initial_heap_size, 0, 0);
Cyc_heap->heap[HEAP_SM] = gc_heap_create(HEAP_SM, initial_heap_size, 0, 0); Cyc_heap->heap[HEAP_SM] = gc_heap_create(HEAP_SM, initial_heap_size, 0, 0);
Cyc_heap->heap[HEAP_64] = gc_heap_create(HEAP_64, initial_heap_size, 0, 0); Cyc_heap->heap[HEAP_64] = gc_heap_create(HEAP_64, initial_heap_size, 0, 0);