@@ -4,11 +4,15 @@
44#include <stdbool.h>
55#include <stddef.h>
66
7+/* *** C heap ***
8+ * Objects with finalizers. Mark&sweep-collected.
9+ */
10+
711typedef void CDataFinalizer_t(void *);
812
913typedef struct CHeapItem {
1014 void * data;
11− CDataFinalizer_t * finalizer; // responsible for freeing the passed pointer, too
15+ CDataFinalizer_t * finalizer; // should free() the passed data pointer, too
1216 bool is_used;
1317 struct CHeapItem * next;
1418 struct CHeapItem ** prev_next;
@@ -19,7 +23,7 @@ typedef struct CHeap {
1923} CHeap;
2024
2125void c_heap_init(CHeap * c_heap);
22−void c_heap_destroy(CHeap * c_heap);
26+void c_heap_destroy(CHeap * c_heap); // will call finalizers on everything
2327void c_heap_insert_if_needed(CHeap * c_heap, CHeapItem * item);
2428void c_heap_mark_item(CHeapItem * item);
2529void c_heap_sweep(CHeap * c_heap);
@@ -29,6 +33,10 @@ CHeapItem * c_heap_create_item(void * data, CDataFinalizer_t * finalizer);
2933CHeapItem * c_heap_allocate(size_t size, CDataFinalizer_t * finalizer);
3034void c_heap_free(CHeapItem * item);
3135
36+/* *** Idris heap **
37+ * Objects without finalizers. Cheney-collected.
38+ */
39+
3240typedef struct {
3341 char* next; // Next allocated chunk. Should always (heap <= next < end).
3442 char* heap; // Point to bottom of heap