Commit 9b9562688b66d57596cb286fc335a15b27117d70

Thomas de Grivel 2024-07-27T14:49:27

wip bug in struct_access

diff --git a/libkc3/struct.c b/libkc3/struct.c
index b3a4656..cf6aa0e 100644
--- a/libkc3/struct.c
+++ b/libkc3/struct.c
@@ -26,6 +26,7 @@
 s_tag * struct_access (const s_struct *s, const s_sym *key, s_tag *dest)
 {
   const void *data;
+  const s_struct_type *st;
   const s_sym *type;
   s_tag tmp = {0};
   void *tmp_data;
@@ -36,6 +37,13 @@ s_tag * struct_access (const s_struct *s, const s_sym *key, s_tag *dest)
     return NULL;
   if (! sym_to_tag_type(type, &tmp.type))
     return NULL;
+  if (! struct_type_find(type, &st))
+    return NULL;
+  if (st) {
+    tmp.data.struct_.type = st;
+    if (! struct_allocate(&tmp.data.struct_))
+      return NULL;
+  }
   if (! tag_to_pointer(&tmp, type, &tmp_data))
     return NULL;
   if (! data_init_copy(type, tmp_data, data))
diff --git a/test/http/01_socket_buf.kc3 b/test/http/01_socket_buf.kc3
index 25d1ac4..d34b2d8 100644
--- a/test/http/01_socket_buf.kc3
+++ b/test/http/01_socket_buf.kc3
@@ -1,4 +1,4 @@
-quote %Socket.Buf{}
-%Socket.Buf{}
-quote %Socket{}
-%Socket{}
+quote a = %Socket.Buf{}
+a = %Socket.Buf{}
+quote a.buf_rw
+a.buf_rw
diff --git a/test/http/04_server_request.kc3 b/test/http/04_server_request.kc3
index 98de671..e750076 100644
--- a/test/http/04_server_request.kc3
+++ b/test/http/04_server_request.kc3
@@ -4,6 +4,10 @@ quote client = Socket.Buf.connect("localhost", "58000")
 client = Socket.Buf.connect("localhost", "58000")
 quote server_client = Socket.accept(server)
 server_client = Socket.Buf.accept(server)
+quote client.buf_rw
+client.buf_rw
+quote client.buf_rw.w
+client.buf_rw.w
 quote Buf.write_str(client.buf_rw.w, "GET / HTTP/1.0\r\n\r\n")
 Buf.write_str(client.buf_rw.w, "GET / HTTP/1.0\r\n\r\n")
 quote Socket.Buf.close(client)