change gc heap API and hide sturctures.
This commit is contained in:
parent
6c065e92c0
commit
5175f0bb8d
|
@ -12,27 +12,10 @@ extern "C" {
|
|||
#define PIC_GC_UNMARK 0
|
||||
#define PIC_GC_MARK 1
|
||||
|
||||
union header {
|
||||
struct {
|
||||
union header *ptr;
|
||||
size_t size;
|
||||
unsigned int mark : 1;
|
||||
} s;
|
||||
long alignment[4];
|
||||
};
|
||||
struct pic_heap;
|
||||
|
||||
struct heap_page {
|
||||
union header *basep, *endp;
|
||||
struct heap_page *next;
|
||||
};
|
||||
|
||||
struct pic_heap {
|
||||
union header base, *freep;
|
||||
struct heap_page *pages;
|
||||
};
|
||||
|
||||
void init_heap(struct pic_heap *);
|
||||
void finalize_heap(struct pic_heap *);
|
||||
struct pic_heap *heap_open();
|
||||
void heap_close(struct pic_heap *);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
|
33
src/gc.c
33
src/gc.c
|
@ -23,8 +23,27 @@
|
|||
# include <string.h>
|
||||
#endif
|
||||
|
||||
union header {
|
||||
struct {
|
||||
union header *ptr;
|
||||
size_t size;
|
||||
unsigned int mark : 1;
|
||||
} s;
|
||||
long alignment[4];
|
||||
};
|
||||
|
||||
struct heap_page {
|
||||
union header *basep, *endp;
|
||||
struct heap_page *next;
|
||||
};
|
||||
|
||||
struct pic_heap {
|
||||
union header base, *freep;
|
||||
struct heap_page *pages;
|
||||
};
|
||||
|
||||
void
|
||||
init_heap(struct pic_heap *heap)
|
||||
heap_init(struct pic_heap *heap)
|
||||
{
|
||||
heap->base.s.ptr = &heap->base;
|
||||
heap->base.s.size = 0; /* not 1, since it must never be used for allocation */
|
||||
|
@ -38,8 +57,18 @@ init_heap(struct pic_heap *heap)
|
|||
#endif
|
||||
}
|
||||
|
||||
struct pic_heap *
|
||||
heap_open()
|
||||
{
|
||||
struct pic_heap *heap;
|
||||
|
||||
heap = (struct pic_heap *)calloc(1, sizeof(struct pic_heap));
|
||||
heap_init(heap);
|
||||
return heap;
|
||||
}
|
||||
|
||||
void
|
||||
finalize_heap(struct pic_heap *heap)
|
||||
heap_close(struct pic_heap *heap)
|
||||
{
|
||||
struct heap_page *page;
|
||||
|
||||
|
|
|
@ -48,8 +48,7 @@ pic_open(int argc, char *argv[], char **envp)
|
|||
pic->rlen = PIC_RESCUE_SIZE;
|
||||
|
||||
/* memory heap */
|
||||
pic->heap = (struct pic_heap *)calloc(1, sizeof(struct pic_heap));
|
||||
init_heap(pic->heap);
|
||||
pic->heap = heap_open();
|
||||
|
||||
/* symbol table */
|
||||
pic->syms = xh_new_str();
|
||||
|
@ -152,8 +151,7 @@ pic_close(pic_state *pic)
|
|||
xh_destroy(pic->macros);
|
||||
|
||||
/* free heaps */
|
||||
finalize_heap(pic->heap);
|
||||
free(pic->heap);
|
||||
heap_close(pic->heap);
|
||||
|
||||
/* free symbol names */
|
||||
for (xh_begin(pic->sym_names, &it); ! xh_isend(&it); xh_next(&it)) {
|
||||
|
|
Loading…
Reference in New Issue