Commit 33cc4d8cb6575fcd5db8a73e278e28eef608598f

Thomas de Grivel 2024-08-10T14:43:27

fix compilation

diff --git a/libkc3/inspect.c b/libkc3/inspect.c
index c10ccb2..65afdaf 100644
--- a/libkc3/inspect.c
+++ b/libkc3/inspect.c
@@ -14,6 +14,7 @@
 #include "buf.h"
 #include "buf_inspect.h"
 #include "inspect.h"
+#include "integer.h"
 
 s_str * inspect_array (const s_array *array, s_str *dest)
 {
@@ -185,7 +186,7 @@ s_str * inspect_list (const s_list *x, s_str *dest)
   return NULL;
 }
 
-s_str * ratio_inspect (const s_ratio *src, s_str *dest)
+s_str * inspect_ratio (const s_ratio *src, s_str *dest)
 {
   s_buf buf;
   s_pretty pretty = {0};
@@ -201,18 +202,41 @@ s_str * ratio_inspect (const s_ratio *src, s_str *dest)
     return NULL;
   r = buf_inspect_ratio(&buf, src);
   if (r != size) {
-   err_write_1("ratio_inspect: ");
+   err_write_1("inspect_ratio: ");
    err_inspect_sw(&r);
    err_write_1(" != ");
    err_inspect_sw(&size);
    err_write_1("\n");
-   assert(! "ratio_inspect: invalid ratio");
+   assert(! "inspect_ratio: buf_inspect_ratio != size");
    return NULL;
   }
   assert(buf.wpos == (uw) size);
   return buf_to_str(&buf, dest);
 }
 
+s_str * inspect_str (const s_str *str, s_str *dest)
+{
+  s_buf buf;
+  s_pretty pretty = {0};
+  sw size;
+  size = buf_inspect_str_size(&pretty, str);
+  if (size < 0) {
+    err_puts("inspect_str: buf_inspect_str_size");
+    assert(! "inspect_str: buf_inspect_str_size");
+    return NULL;
+  }
+  buf_init_alloc(&buf, size);
+  buf_inspect_str(&buf, str);
+  assert(buf.wpos == buf.size);
+  if (buf.wpos != buf.size) {
+    buf_clean(&buf);
+    err_puts("inspect_str: buf_inspect_str");
+    assert(! "inspect_str: buf_inspect_str");
+    return NULL;
+  }
+  return buf_to_str(&buf, dest);
+}
+
 s_str * inspect_sym (const s_sym *sym, s_str *dest)
 {
   s_buf buf;
@@ -249,3 +273,26 @@ s_str * inspect_tag (const s_tag *tag, s_str *dest)
   }
   return buf_to_str(&buf, dest);
 }
+
+s_str * inspect_tuple (const s_tuple *tuple, s_str *dest)
+{
+  s_buf buf;
+  s_pretty pretty = {0};
+  sw size;
+  size = buf_inspect_tuple_size(&pretty, tuple);
+  if (size < 0) {
+    err_puts("inspect_tuple: buf_inspect_tuple_size");
+    assert(! "inspect_tuple: buf_inspect_tuple_size");
+    return NULL;
+  }
+  buf_init_alloc(&buf, size);
+  buf_inspect_tuple(&buf, tuple);
+  assert(buf.wpos == buf.size);
+  if (buf.wpos != buf.size) {
+    buf_clean(&buf);
+    err_puts("inspect_tuple: buf_inspect_tuple");
+    assert(! "inspect_tuple: buf_inspect_tuple");
+    return NULL;
+  }
+  return buf_to_str(&buf, dest);
+}
diff --git a/libkc3/str.c b/libkc3/str.c
index 4fd602f..dcf0f5c 100644
--- a/libkc3/str.c
+++ b/libkc3/str.c
@@ -41,8 +41,9 @@
   s_str * str_init_ ## name (s_str *str, type x)                       \
   {                                                                    \
     s_buf buf;                                                         \
+    s_pretty pretty = {0};                                             \
     sw size;                                                           \
-    size = buf_inspect_ ## name ## _size(&x);                          \
+    size = buf_inspect_ ## name ## _size(&pretty, &x);                 \
     if (size <= 0)                                                     \
       return NULL;                                                     \
     buf_init_alloc(&buf, size);                                        \
@@ -58,8 +59,9 @@
   s_str * str_init_ ## type (s_str *str, type x)                       \
   {                                                                    \
     s_buf buf;                                                         \
+    s_pretty pretty = {0};                                             \
     sw size;                                                           \
-    size = buf_inspect_ ## type ## _decimal_size(&x);                  \
+    size = buf_inspect_ ## type ## _decimal_size(&pretty, &x);         \
     if (size <= 0)                                                     \
       return NULL;                                                     \
     buf_init_alloc(&buf, size);                                        \
@@ -72,9 +74,10 @@
   s_str * str_init_ ## name (s_str *str, const s_ ## name *x)          \
   {                                                                    \
     s_buf buf;                                                         \
+    s_pretty pretty = {0};                                             \
     sw r;                                                              \
     sw size;                                                           \
-    size = buf_inspect_ ## name ## _size(x);                           \
+    size = buf_inspect_ ## name ## _size(&pretty, x);                  \
     if (! size)                                                        \
       return str_init_empty(str);                                      \
     if (size < 0) {                                                    \
@@ -511,19 +514,6 @@ s_str * str_init_vf (s_str *str, const char *fmt, va_list ap)
   return str_init(str, s, len, s);
 }
 
-s_str * str_inspect (const s_str *src, s_str *dest)
-{
-  s_buf buf;
-  sw size;
-  size = buf_inspect_str_size(src);
-  if (size <= 0)
-    return NULL;
-  buf_init_alloc(&buf, size);
-  buf_inspect_str(&buf, src);
-  assert(buf.wpos == (uw) size);
-  return buf_to_str(&buf, dest);
-}
-
 sw str_length_utf8 (const s_str *str)
 {
   character c;
diff --git a/libkc3/tuple.c b/libkc3/tuple.c
index fa96fc8..451adb1 100644
--- a/libkc3/tuple.c
+++ b/libkc3/tuple.c
@@ -124,24 +124,6 @@ s_tuple * tuple_init_copy (s_tuple *tuple, const s_tuple *src)
   return tuple;
 }
 
-s_str * tuple_inspect (const s_tuple *x, s_str *dest)
-{
-  s_buf buf;
-  sw r;
-  sw size;
-  size = buf_inspect_tuple_size(x);
-  buf_init_alloc(&buf, size);
-  if ((r = buf_inspect_tuple(&buf, x)) < 0)
-    goto error;
-  assert(r == size);
-  if (r != size)
-    goto error;
-  return buf_to_str(&buf, dest);
- error:
-  buf_clean(&buf);
-  return NULL;
-}
-
 s_tuple * tuple_new (uw count)
 {
   s_tuple *tuple;