Commit 5c98ba44dc6b1fc1746a9924c432252dcd58e8cb

Thomas de Grivel 2024-08-27T16:03:52

wip struct with void

diff --git a/libkc3/struct.c b/libkc3/struct.c
index 3550c21..7cbc1aa 100644
--- a/libkc3/struct.c
+++ b/libkc3/struct.c
@@ -225,6 +225,7 @@ s_struct * struct_init_1 (s_struct *s, const char *p)
   uw len;
   sw r;
   s_struct tmp = {0};
+  s_struct tmp2 = {0};
   assert(s);
   assert(p);
   len = strlen(p);
@@ -238,18 +239,19 @@ s_struct * struct_init_1 (s_struct *s, const char *p)
       struct_clean(&tmp);
     return NULL;
   }
-  if (false) {
+  if (true) {
     err_write_1("\nstruct_init_1: tmp = ");
     err_inspect_struct(&tmp);
     err_write_1("\n");
   }
-  if (! env_eval_struct(&g_kc3_env, &tmp, s)) {
+  if (! env_eval_struct(&g_kc3_env, &tmp, &tmp2)) {
     err_puts("struct_init_1: env_eval_struct");
     assert(! "struct_init_1: env_eval_struct");
     struct_clean(&tmp);
     return NULL;
   }
   struct_clean(&tmp);
+  *s = tmp2;
   return s;
 }
 
@@ -294,8 +296,8 @@ s_struct * struct_init_copy (s_struct *s, const s_struct *src)
         type = tmp.type->map.value[i].data.var.type;
       else if (! tag_type(tmp.type->map.value + i, &type))
         goto ko;
-      if (! data_init_copy(type, (s8 *) tmp.data +
-                           tmp.type->offset[i],
+      if (! data_init_copy(type,
+                           (s8 *) tmp.data + tmp.type->offset[i],
                            (s8 *) src->data + tmp.type->offset[i]))
         goto ko;
       i++;
diff --git a/libkc3/tag.c b/libkc3/tag.c
index 9335f17..11049ea 100644
--- a/libkc3/tag.c
+++ b/libkc3/tag.c
@@ -1002,10 +1002,13 @@ bool tag_to_const_pointer (const s_tag *tag, const s_sym *type,
                            const void **dest)
 {
   e_tag_type tag_type;
+  if (type == &g_sym_Tag) {
+    *dest = tag;
+    return true;
+  }
   if (! sym_to_tag_type(type, &tag_type))
     return false;
-  if (type != &g_sym_Tag &&
-      tag->type != tag_type) {
+  if (tag->type != tag_type) {
     err_write_1("tag_to_const_pointer: cannot cast ");
     err_write_1(tag_type_to_string(tag->type));
     err_write_1(" to ");