on master help sign in
Add a C data interface in the RTS code.
9c75a0bMatus Tejiscak
rts/idris_rts.c+10
@@ -127,6 +127,16 @@ Stats terminate(VM* vm) {
127 return stats;
127 return stats;
128}
128}
129
129
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+
130void idris_requireAlloc(size_t size) {
140void idris_requireAlloc(size_t size) {
131#ifdef HAS_PTHREAD
141#ifdef HAS_PTHREAD
132 VM* vm = pthread_getspecific(vm_key);
142 VM* vm = pthread_getspecific(vm_key);
rts/idris_rts.h+16
@@ -114,6 +114,22 @@ struct VM_t {
114
114
115typedef struct VM_t VM;
115typedef struct VM_t VM;
116
116
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+
117// Create a new VM
133// Create a new VM
118VM* init_vm(int stack_size, size_t heap_size,
134VM* init_vm(int stack_size, size_t heap_size,
119 int max_threads);
135 int max_threads);