Commit f54669a76c9ecbfe2495c9f1c6c2dd6da2f15848

Thomas de Grivel 2024-09-18T18:59:55

wip cow

diff --git a/libkc3/data.c b/libkc3/data.c
index d0dcaf1..6e37efe 100644
--- a/libkc3/data.c
+++ b/libkc3/data.c
@@ -613,6 +613,8 @@ void * data_init_copy (const s_sym *type, void *data, const void *src)
     return cfn_init_copy(data, src);
   if (type == &g_sym_Character)
     return character_init_copy(data, src);
+  if (type == &g_sym_Cow)
+    return pcow_init_copy(data, src);
   if (type == &g_sym_F32)
     return f32_init_copy(data, src);
   if (type == &g_sym_F64)
diff --git a/libkc3/kc3.h b/libkc3/kc3.h
index 893c332..357bba2 100644
--- a/libkc3/kc3.h
+++ b/libkc3/kc3.h
@@ -66,6 +66,7 @@
 #include "kc3_main.h"
 #include "list.h"
 #include "map.h"
+#include "pcow.h"
 #include "ptag.h"
 #include "ptr.h"
 #include "ptr_free.h"
diff --git a/libkc3/pcow.c b/libkc3/pcow.c
index bee541d..e4bc7a4 100644
--- a/libkc3/pcow.c
+++ b/libkc3/pcow.c
@@ -18,6 +18,9 @@
 s_tag * pcow_assign (s_cow * const *cow, const s_tag *value,
                      s_tag *dest)
 {
+  assert(cow);
+  assert(value);
+  assert(dest);
   if (cow_ref(*cow) < 0)
     return NULL;
   if (! tag_init_copy(cow_read_write(*cow), value))
@@ -65,9 +68,16 @@ s_cow ** pcow_init_copy (s_cow **p, s_cow * const *src)
 {
   assert(p);
   assert(src);
-  if (! src || ! *src)
+  if (! src || ! *src) {
+    err_puts("pcow_init_copy: NULL src");
+    assert(! "pcow_init_copy: NULL src");
     return NULL;
-  cow_ref(*src);
+  }
+  if (cow_ref(*src) < 0) {
+    err_puts("pcow_init_copy: cow_ref");
+    assert(! "pcow_init_copy: cow_ref");
+    return NULL;
+  }
   *p = *src;
   return p;
 }