summaryrefslogtreecommitdiff
path: root/testsuite/tests/ffi/should_run/4221_c.c
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/ffi/should_run/4221_c.c')
-rw-r--r--testsuite/tests/ffi/should_run/4221_c.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/testsuite/tests/ffi/should_run/4221_c.c b/testsuite/tests/ffi/should_run/4221_c.c
new file mode 100644
index 0000000000..0c5ca228c1
--- /dev/null
+++ b/testsuite/tests/ffi/should_run/4221_c.c
@@ -0,0 +1,26 @@
+#include<stdio.h>
+#include<stdlib.h>
+
+typedef double (*hs_function_ptr)(double);
+
+typedef struct {
+ hs_function_ptr fn;
+ void (*free_fn)(hs_function_ptr);
+} fn_blob;
+
+fn_blob* create_fn_blob(hs_function_ptr fn, void (*free_fn)(hs_function_ptr)) {
+ fn_blob* new_blob = malloc(sizeof(fn_blob));
+ new_blob->fn = fn;
+ new_blob->free_fn = free_fn;
+ return new_blob;
+}
+
+double call_fn_blob(fn_blob* fn_blob, double arg) {
+ return(fn_blob->fn(arg));
+}
+
+void free_fn_blob(fn_blob* dead_blob) {
+ dead_blob->free_fn(dead_blob->fn);
+ free(dead_blob);
+}
+