Commit 2a12f50631cc4d6cecdd2bd83a8113df8fd18628

Thomas de Grivel 2023-11-10T11:05:03

C3.type

diff --git a/README.md b/README.md
index 73e7fcb..e222012 100644
--- a/README.md
+++ b/README.md
@@ -239,6 +239,8 @@ All these list formats are supported in pattern matching.
 ## TODO
 
  - libc3
+   - c3
+     - [DONE] tag_type
    - facts
      - negative facts : 4 + 2n = not 3 + 2n
      - with ignore variables
diff --git a/libc3/cfn.c b/libc3/cfn.c
index d81a8c2..8cae70c 100644
--- a/libc3/cfn.c
+++ b/libc3/cfn.c
@@ -47,7 +47,6 @@ s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
     return NULL;
   }
   if (cfn->cif.rtype == &ffi_type_pointer) {
-    cfn_tag_init(&tmp2, cfn->result_type);
     cfn_tag_init(&tmp, cfn->result_type);
     /* make result point to result_pointer */
     result_pointer = tag_to_ffi_pointer(&tmp, cfn->result_type);
@@ -68,13 +67,15 @@ s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
     while (cfn_arg_types) {
       assert(cfn_arg_types->tag.type == TAG_SYM);
       if (cfn_arg_types->tag.data.sym == sym_1("Result") ||
-          cfn_arg_types->tag.data.sym == sym_1("&result"))
+          cfn_arg_types->tag.data.sym == sym_1("&result")) {
+        cfn_tag_init(&tmp2, cfn->result_type);
         if (cfn->cif.rtype == &ffi_type_pointer) {
           arg_pointers[i] = tag_to_ffi_pointer(&tmp2, cfn->result_type);
           arg_values[i] = &arg_pointers[i];
         }
         else
           arg_values[i] = tag_to_ffi_pointer(&tmp2, cfn->result_type);
+      }
       else {
         if (cfn->cif.arg_types[i] == &ffi_type_pointer) {
           arg_pointers[i] =
diff --git a/libc3/tag.c b/libc3/tag.c
index 24346af..6a37253 100644
--- a/libc3/tag.c
+++ b/libc3/tag.c
@@ -8646,7 +8646,7 @@ void * tag_to_ffi_pointer (s_tag *tag, const s_sym *type)
   case TAG_SYM:
     if (type == sym_1("Sym") ||
         type == sym_1("sym"))
-      return (void *) tag->data.sym;
+      return (void *) &tag->data.sym;
     if (type == sym_1("Str") ||
         type == sym_1("str"))
       return (void *) &tag->data.sym->str;