Commit c8b31ddb93f6d610b98e58ad4721e07638fab86b

Thomas de Grivel 2024-07-21T13:36:07

fix cfn_apply

diff --git a/Makefile b/Makefile
index 06e15e7..b9edbb2 100644
--- a/Makefile
+++ b/Makefile
@@ -159,7 +159,11 @@ gdb_test_ekc3:
 	${MAKE} -C test gdb_test_ekc3
 
 gdb_test_http:
-	${MAKE} debug
+	${MAKE} -C libtommath debug
+	${MAKE} -C ucd2c
+	${MAKE} -C libkc3 debug
+	${MAKE} -C ikc3 debug
+	${MAKE} -C kc3s debug
 	${MAKE} -C test gdb_test_http
 
 gen:
diff --git a/lib/kc3/0.1/http.kc3 b/lib/kc3/0.1/http.kc3
index 46f0992..cfdd4b2 100644
--- a/lib/kc3/0.1/http.kc3
+++ b/lib/kc3/0.1/http.kc3
@@ -1,14 +1,14 @@
 defmodule Socket do
 
-  dlopen(__DIR__ + "http.so")
-
   defstruct [fd: (S32) 0]
 
+  dlopen(__DIR__ + "http.so")
+
   def accept = cfn Socket "socket_init_accept" (Result, Socket)
 
   def close = cfn Void "socket_close" (Socket)
 
-  # listen : Str host, U16 port
+  # listen(host, port)
   def listen = cfn Socket "socket_init_listen" (Result, Str, U16)
 
 end
diff --git a/libkc3/cfn.c b/libkc3/cfn.c
index b3dfc7d..8022e03 100644
--- a/libkc3/cfn.c
+++ b/libkc3/cfn.c
@@ -17,6 +17,7 @@
 #include "cfn.h"
 #include "list.h"
 #include "str.h"
+#include "struct.h"
 #include "sym.h"
 #include "tag.h"
 #include "tag_type.h"
@@ -326,6 +327,20 @@ s_tag * cfn_tag_init (s_tag *tag, const s_sym *type)
     assert(! "cfn_tag_init: invalid type");
     return NULL;
   }
+  if (tmp.type == TAG_STRUCT) {
+    if (! struct_init(&tmp.data.struct_, type)) {
+      err_write_1("cfn_tag_init: struct_init: ");
+      err_puts(type->str.ptr.pchar);
+      assert(! "cfn_tag_init: struct_init");
+      return NULL;
+    }
+    if (! struct_allocate(&tmp.data.struct_)) {
+      err_write_1("cfn_tag_init: struct_allocate: ");
+      err_puts(type->str.ptr.pchar);
+      assert(! "cfn_tag_init: struct_allocate");
+      return NULL;
+    }
+  }
   *tag = tmp;
   return tag;
 }