Commit d3a48f2bf8dd0953b79a1f8427ff5a3d8d3992bf

Thomas de Grivel 2023-03-17T10:10:37

use system libffi

diff --git a/c3s/configure b/c3s/configure
index fcea77b..adf4099 100755
--- a/c3s/configure
+++ b/c3s/configure
@@ -47,7 +47,7 @@ LDFLAGS="-Wl,--allow-shlib-undefined ${LDFLAGS:=}"
 LIBS="${LIBS:=-lm}"
 
 # Common config for all targets
-CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic"
+CFLAGS="$CFLAGS -W -Wall -Werror -std=c11 -pedantic"
 config_asan
 config_gnu
 pkg_config libbsd-overlay
diff --git a/ic3/configure b/ic3/configure
index ddf76da..635eb17 100755
--- a/ic3/configure
+++ b/ic3/configure
@@ -47,7 +47,7 @@ LDFLAGS="-Wl,--allow-shlib-undefined ${LDFLAGS:-}"
 LIBS="${LIBS:=-lm}"
 
 # Common config for all targets
-CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic"
+CFLAGS="$CFLAGS -W -Wall -Werror -std=c11 -pedantic"
 config_asan
 config_gnu
 pkg_config libbsd-overlay
diff --git a/libc3/cfn.c b/libc3/cfn.c
index 83eb730..a88b983 100644
--- a/libc3/cfn.c
+++ b/libc3/cfn.c
@@ -52,7 +52,7 @@ s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
   /* make result point to tmp value */
   result = cfn_tag_to_ffi_value(&tmp, cfn->result_type);
   if (cfn->arity) {
-    if (! (arg_values = malloc(sizeof(void *) * cfn->arity)))
+    if (! (arg_values = calloc(sizeof(void *), cfn->arity + 1)))
       err(1, "cfn_apply");
     cfn_arg_type = cfn->arg_types;
     a = args;
@@ -127,7 +127,6 @@ s_cfn * cfn_set_type (s_cfn *cfn, s_list *arg_type,
   s_list *a;
   ffi_type **arg_ffi_type = NULL;
   sw arity;
-  ffi_cif cif;
   u8 i = 0;
   ffi_type *result_ffi_type;
   assert(cfn);
@@ -138,7 +137,7 @@ s_cfn * cfn_set_type (s_cfn *cfn, s_list *arg_type,
       assert(arity <= 255);
       errx(1, "cfn_set_arg_types: arity > 255");
     }
-    if (! (arg_ffi_type = malloc(sizeof(ffi_type *) * arity)))
+    if (! (arg_ffi_type = calloc(sizeof(ffi_type *), arity + 1)))
       err(1, "cfn_set_arg_types");
     a = arg_type;
     while (a) {
@@ -157,11 +156,11 @@ s_cfn * cfn_set_type (s_cfn *cfn, s_list *arg_type,
       a = list_next(a);
     }
   }
-  ffi_prep_cif(&cif, FFI_DEFAULT_ABI, arity, result_ffi_type, arg_ffi_type);  
   cfn->arg_types = arg_type;
   cfn->arity = arity;
-  cfn->cif = cif;
   cfn->result_type = result_type;
+  ffi_prep_cif(&cfn->cif, FFI_DEFAULT_ABI, cfn->arity, result_ffi_type,
+               arg_ffi_type);  
   free(arg_ffi_type);
   return cfn;
 }
@@ -253,7 +252,7 @@ e_tag_type cfn_sym_to_tag_type (const s_sym *sym)
   if (sym == sym_1("sym"))
     return TAG_SYM;
   if (sym == sym_1("tag"))
-    return TAG_VOID;
+    return TAG_PTAG;
   if (sym == sym_1("tuple"))
     return TAG_TUPLE;
   assert(! "cfn_sym_to_tag_type: unknown type");
diff --git a/libc3/configure b/libc3/configure
index d53873f..5d82c1b 100755
--- a/libc3/configure
+++ b/libc3/configure
@@ -39,7 +39,7 @@ LDFLAGS="-shared -Wl,--allow-shlib-undefined ${LDFLAGS:-}"
 LIBS="${LIBS:=-lm} -rpath ${PREFIX}/lib"
 
 # Common config for all targets
-CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic -fPIC"
+CFLAGS="$CFLAGS -W -Wall -Werror -std=c11 -pedantic -fPIC"
 config_asan
 config_gnu
 pkg_config libbsd-overlay
diff --git a/libc3/env.c b/libc3/env.c
index 1e3f4b1..30a2c51 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -147,19 +147,19 @@ bool env_eval_call (s_env *env, const s_call *call, s_tag *dest)
 
 bool env_eval_call_arguments (s_env *env, s_list *args, s_list **dest)
 {
-  s_list **t;
+  s_list **tail;
   s_list *tmp;
-  t = &tmp;
+  tail = &tmp;
   while (args) {
-    *t = list_new(NULL);
-    if (! env_eval_tag(env, &args->tag, &(*t)->tag)) {
+    *tail = list_new(NULL);
+    if (! env_eval_tag(env, &args->tag, &(*tail)->tag)) {
       list_delete_all(tmp);
       err_puts("env_eval_call_arguments: invalid argument: ");
       err_inspect(&args->tag);
       err_puts("\n");
       return false;
     }
-    t = &(*t)->next.data.list;
+    tail = &(*tail)->next.data.list;
     args = list_next(args);
   }
   *dest = tmp;
diff --git a/test/configure b/test/configure
index 4ff1129..0213865 100755
--- a/test/configure
+++ b/test/configure
@@ -47,7 +47,7 @@ LDFLAGS="-Wl,--allow-shlib-undefined ${LDFLAGS:=}"
 LIBS="${LIBS:=} -lm"
 
 # Common config for all targets
-CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic"
+CFLAGS="$CFLAGS -W -Wall -Werror -std=c11 -pedantic"
 config_asan
 config_gnu
 pkg_config libbsd-overlay