use pic_alloc/pic_free in initializing struct pic_heap

This commit is contained in:
Yuichi Nishiwaki 2015-01-22 17:08:41 +09:00
parent 8c67ad863b
commit 42cc5042f3
3 changed files with 8 additions and 8 deletions

View File

@ -57,24 +57,24 @@ heap_init(struct pic_heap *heap)
} }
struct pic_heap * struct pic_heap *
pic_heap_open() pic_heap_open(pic_state *pic)
{ {
struct pic_heap *heap; struct pic_heap *heap;
heap = (struct pic_heap *)calloc(1, sizeof(struct pic_heap)); heap = pic_calloc(pic, 1, sizeof(struct pic_heap));
heap_init(heap); heap_init(heap);
return heap; return heap;
} }
void void
pic_heap_close(struct pic_heap *heap) pic_heap_close(pic_state *pic, struct pic_heap *heap)
{ {
struct heap_page *page; struct heap_page *page;
while (heap->pages) { while (heap->pages) {
page = heap->pages; page = heap->pages;
heap->pages = heap->pages->next; heap->pages = heap->pages->next;
free(page); pic_free(pic, page);
} }
} }

View File

@ -14,8 +14,8 @@ extern "C" {
struct pic_heap; struct pic_heap;
struct pic_heap *pic_heap_open(); struct pic_heap *pic_heap_open(pic_state *);
void pic_heap_close(struct pic_heap *); void pic_heap_close(pic_state *, struct pic_heap *);
#if defined(__cplusplus) #if defined(__cplusplus)
} }

View File

@ -49,7 +49,7 @@ pic_open(int argc, char *argv[], char **envp)
pic->xpend = pic->xpbase + PIC_RESCUE_SIZE; pic->xpend = pic->xpbase + PIC_RESCUE_SIZE;
/* memory heap */ /* memory heap */
pic->heap = pic_heap_open(); pic->heap = pic_heap_open(pic);
/* symbol table */ /* symbol table */
xh_init_str(&pic->syms, sizeof(pic_sym *)); xh_init_str(&pic->syms, sizeof(pic_sym *));
@ -232,7 +232,7 @@ pic_close(pic_state *pic)
pic_gc_run(pic); pic_gc_run(pic);
/* free heaps */ /* free heaps */
pic_heap_close(pic->heap); pic_heap_close(pic, pic->heap);
/* free runtime context */ /* free runtime context */
free(pic->stbase); free(pic->stbase);