on master help sign in
Add a C data interface in the RTS code.
commit9c75a0b3243a71098237ef985dd51dabb562acd9 authorMatus Tejiscak <ziman@functor.sk> dateThu 21 Jan 2016, 19:12 (11 years ago) parent83421ef
2 files changed+26
rts/idris_rts.c+10 rts/idris_rts.h+16
rts/idris_rts.c+10
@@ -127,6 +127,16 @@ Stats terminate(VM* vm) {
127127 return stats;
128128}
129129
130+CData cdata_allocate(size_t size, CDataFinalizer_t finalizer)
131+{
132+ return c_heap_allocate(size, finalizer);
133+}
134+
135+void cdata_free(CData cd)
136+{
137+ c_heap_free(cd);
138+}
139+
130140void idris_requireAlloc(size_t size) {
131141#ifdef HAS_PTHREAD
132142 VM* vm = pthread_getspecific(vm_key);
rts/idris_rts.h+16
@@ -114,6 +114,22 @@ struct VM_t {
114114
115115typedef struct VM_t VM;
116116
117+
118+/* C data interface: allocation on the C heap.
119+ *
120+ * Although not enforced in code, CData is meant to be opaque
121+ * and non-RTS code (such as libraries or C bindings) should
122+ * access it only in the following three ways:
123+ *
124+ * CData cd = cdata_allocate(...);
125+ * use(cd->data);
126+ * cdata_free(cd); // optionally
127+ *
128+ */
129+typedef CHeapItem * CData;
130+CData cdata_allocate(size_t size, CDataFinalizer_t * finalizer);
131+void cdata_free(CData cd); // explicit freeing not required but available
132+
117133// Create a new VM
118134VM* init_vm(int stack_size, size_t heap_size,
119135 int max_threads);