Commit 068f23f51146d05050603c4213b84d9f11fecf3a

Baptiste 2024-08-01T13:35:36

changed buf_init to buf_init_const

diff --git a/libkc3/array.c b/libkc3/array.c
index fa40239..a604a56 100644
--- a/libkc3/array.c
+++ b/libkc3/array.c
@@ -221,7 +221,7 @@ s_array * array_init_1 (s_array *array, const char *p)
   assert(array);
   assert(p);
   len = strlen(p);
-  buf_init(&buf, false, len, (char *) p);
+  buf_init_const(&buf, len, p);
   buf.wpos = len;
   r = buf_parse_array(&buf, &tmp);
   if (r < 0 || (uw) r != len) {
diff --git a/libkc3/block.c b/libkc3/block.c
index c9307c0..63be828 100644
--- a/libkc3/block.c
+++ b/libkc3/block.c
@@ -59,7 +59,7 @@ s_block * block_init_1 (s_block *block, const char *p)
   assert(block);
   assert(p);
   len = strlen(p);
-  buf_init(&buf, false, len, (char *) p);
+  buf_init_const(&buf, len, p);
   buf.wpos = len;
   r = buf_parse_block(&buf, block);
   if (r < 0 || (uw) r != len) {
diff --git a/libkc3/buf_fd.c b/libkc3/buf_fd.c
index b05abef..e1369a3 100644
--- a/libkc3/buf_fd.c
+++ b/libkc3/buf_fd.c
@@ -84,11 +84,6 @@ sw buf_fd_open_r_refill (s_buf *buf)
   if ((uw) avail > size)
     avail = size;
   r = read(fd, buf->ptr.pchar + buf->wpos, avail);
-  if (r < 0) {
-    err_puts("buf_fd_open_r_refill: read");
-    assert(! "buf_fd_open_r_refill: read");
-    return r;
-  }
   if (buf->wpos + r > buf->size) {
     err_puts("buf_fd_open_r_refill: buffer overflow");
     assert(! "buf_fd_open_r_refill: buffer overflow");
diff --git a/libkc3/buf_parse.c b/libkc3/buf_parse.c
index 9264482..324115d 100644
--- a/libkc3/buf_parse.c
+++ b/libkc3/buf_parse.c
@@ -2949,7 +2949,7 @@ sw buf_parse_paren_sym (s_buf *buf, const s_sym **dest)
   s_buf_save save;
   const s_sym *tmp;
   s_buf        tmp_buf;
-  s8           tmp_buf_data[64] = {0};
+  char         tmp_buf_data[64] = {0};
   buf_save_init(buf, &save);
   if ((r = buf_read_1(buf, "(")) <= 0)
     goto clean;
@@ -2973,7 +2973,7 @@ sw buf_parse_paren_sym (s_buf *buf, const s_sym **dest)
         break;
       result += r;
       buf_init(&tmp_buf, false, sizeof(tmp_buf_data),
-               (char *) tmp_buf_data);
+              tmp_buf_data);
       buf_inspect_sym(&tmp_buf, &tmp);
       buf_write_1(&tmp_buf, "[");
       if ((r = buf_parse_uw(buf, &b)) <= 0)
diff --git a/libkc3/call.c b/libkc3/call.c
index 7be110a..e4a14f1 100644
--- a/libkc3/call.c
+++ b/libkc3/call.c
@@ -54,7 +54,7 @@ s_call * call_init_1 (s_call *call, const char *p)
   uw len;
   sw r;
   len = strlen(p);
-  buf_init(&buf, false, len, (char *) p);
+  buf_init_const(&buf, len, p);
   buf.wpos = len;
   r = buf_parse_call(&buf, call);
   if (r < 0 || (uw) r != len) {
diff --git a/libkc3/cow.c b/libkc3/cow.c
index 7327388..ee7f0a5 100644
--- a/libkc3/cow.c
+++ b/libkc3/cow.c
@@ -77,7 +77,7 @@ s_cow * cow_init_1 (s_cow *cow, const char *utf8)
   uw len;
   sw r;
   len = strlen(utf8);
-  buf_init(&buf, false, len, (char *) utf8); // buf is read-only
+  buf_init_const(&buf, len, utf8); // buf is read-only
   buf.wpos = len;
   r = buf_parse_cow(&buf, cow);
   if (r < 0 || (uw) r != len) {
diff --git a/libkc3/fn.c b/libkc3/fn.c
index 5275062..0f24da9 100644
--- a/libkc3/fn.c
+++ b/libkc3/fn.c
@@ -58,7 +58,7 @@ s_fn * fn_init (s_fn *fn, const s_sym *module)
   return fn;
 }
 
-s_fn * fn_init_1 (s_fn *fn, char *p)
+s_fn * fn_init_1 (s_fn *fn, const char *p)
 {
   s_buf buf;
   uw len;
@@ -66,7 +66,7 @@ s_fn * fn_init_1 (s_fn *fn, char *p)
   assert(fn);
   assert(p);
   len = strlen(p);
-  buf_init(&buf, false, len, (char *) p);
+  buf_init_const(&buf, len, p);
   buf.wpos = len;
   r = buf_parse_fn(&buf, fn);
   if (r < 0 || (uw) r != len) {
diff --git a/libkc3/fn.h b/libkc3/fn.h
index 5a1aeb7..568e325 100644
--- a/libkc3/fn.h
+++ b/libkc3/fn.h
@@ -24,7 +24,7 @@
 /* Stack-allocation compatible functions, call fn_clean after use. */
 void   fn_clean (s_fn *fn);
 s_fn * fn_init (s_fn *fn, const s_sym *module);
-s_fn * fn_init_1 (s_fn *fn, char *p);
+s_fn * fn_init_1 (s_fn *fn, const char *p);
 s_fn * fn_init_cast (s_fn *fn, const s_sym * const *type,
                      const s_tag *tag);
 s_fn * fn_init_copy (s_fn *fn, const s_fn *src);
diff --git a/libkc3/integer.c b/libkc3/integer.c
index f9072ab..0021305 100644
--- a/libkc3/integer.c
+++ b/libkc3/integer.c
@@ -250,7 +250,7 @@ s_integer * integer_init_1 (s_integer *i, const char *p)
   assert(i);
   assert(p);
   // FIXME
-  buf_init_1(&buf, false, (char *) p);
+  buf_init_1_const(&buf, p);
   buf_parse_integer(&buf, i);
   return i;
 }
diff --git a/libkc3/map.c b/libkc3/map.c
index 84331ad..68c8022 100644
--- a/libkc3/map.c
+++ b/libkc3/map.c
@@ -117,7 +117,7 @@ s_map * map_init_1 (s_map *map, const char *p)
   assert(map);
   assert(p);
   len = strlen(p);
-  buf_init(&buf, false, len, (char *) p);
+  buf_init_const(&buf, len, p);
   buf.wpos = len;
   r = buf_parse_map(&buf, map);
   if (r < 0 || (uw) r != len) {
diff --git a/libkc3/ratio.c b/libkc3/ratio.c
index f96b997..259a38f 100644
--- a/libkc3/ratio.c
+++ b/libkc3/ratio.c
@@ -124,7 +124,7 @@ s_ratio * ratio_init_1 (s_ratio *q, const char *p)
   if (! p)
     return NULL;
   len = strlen(p);
-  buf_init(&buf, false, len, (char *) p); // buf is read-only
+  buf_init_const(&buf, len, p); // buf is read-only
   buf.wpos = len;
   r = buf_parse_ratio(&buf, &tmp);
   if (r < 0 || (uw) r != len) {
diff --git a/libkc3/s.c.in b/libkc3/s.c.in
index bd0a933..97c7f47 100644
--- a/libkc3/s.c.in
+++ b/libkc3/s.c.in
@@ -113,7 +113,7 @@ s_bits$ * s_bits$_init_str (s_bits$ *s, const s_str *str)
 {
   s_buf buf;
   s_bits$ tmp = 0;
-  buf_init(&buf, false, str->size, (char *) str->ptr.pchar);
+  buf_init_const(&buf, str->size, str->ptr.pchar);
   buf.wpos = str->size;
   if (buf_parse_s_bits$(&buf, &tmp) <= 0) {
     err_puts("s_bits$_init_str: buf_parse_s_bits$");
diff --git a/libkc3/s16.c b/libkc3/s16.c
index 1b474c8..4a5711f 100644
--- a/libkc3/s16.c
+++ b/libkc3/s16.c
@@ -113,7 +113,7 @@ s16 * s16_init_str (s16 *s, const s_str *str)
 {
   s_buf buf;
   s16 tmp = 0;
-  buf_init(&buf, false, str->size, (char *) str->ptr.pchar);
+  buf_init_const(&buf, str->size, str->ptr.pchar);
   buf.wpos = str->size;
   if (buf_parse_s16(&buf, &tmp) <= 0) {
     err_puts("s16_init_str: buf_parse_s16");
diff --git a/libkc3/s32.c b/libkc3/s32.c
index 685360d..2e6a5e4 100644
--- a/libkc3/s32.c
+++ b/libkc3/s32.c
@@ -113,7 +113,7 @@ s32 * s32_init_str (s32 *s, const s_str *str)
 {
   s_buf buf;
   s32 tmp = 0;
-  buf_init(&buf, false, str->size, (char *) str->ptr.pchar);
+  buf_init_const(&buf, str->size, str->ptr.pchar);
   buf.wpos = str->size;
   if (buf_parse_s32(&buf, &tmp) <= 0) {
     err_puts("s32_init_str: buf_parse_s32");
diff --git a/libkc3/s64.c b/libkc3/s64.c
index 6c49e2f..eb04fab 100644
--- a/libkc3/s64.c
+++ b/libkc3/s64.c
@@ -113,7 +113,7 @@ s64 * s64_init_str (s64 *s, const s_str *str)
 {
   s_buf buf;
   s64 tmp = 0;
-  buf_init(&buf, false, str->size, (char *) str->ptr.pchar);
+  buf_init_const(&buf, str->size, str->ptr.pchar);
   buf.wpos = str->size;
   if (buf_parse_s64(&buf, &tmp) <= 0) {
     err_puts("s64_init_str: buf_parse_s64");
diff --git a/libkc3/s8.c b/libkc3/s8.c
index e1f89dc..a7b899d 100644
--- a/libkc3/s8.c
+++ b/libkc3/s8.c
@@ -113,7 +113,7 @@ s8 * s8_init_str (s8 *s, const s_str *str)
 {
   s_buf buf;
   s8 tmp = 0;
-  buf_init(&buf, false, str->size, (char *) str->ptr.pchar);
+  buf_init_const(&buf, str->size, str->ptr.pchar);
   buf.wpos = str->size;
   if (buf_parse_s8(&buf, &tmp) <= 0) {
     err_puts("s8_init_str: buf_parse_s8");
diff --git a/libkc3/str.c b/libkc3/str.c
index 0f7783e..2ab90a6 100644
--- a/libkc3/str.c
+++ b/libkc3/str.c
@@ -375,7 +375,7 @@ s_str * str_init_slice (s_str *str, const s_str *src, sw start, sw end)
   s_str tmp = {0};
   assert(str);
   assert(src);
-  buf_init(&buf, false, src->size, (char *) src->ptr.pchar);
+  buf_init_const(&buf, src->size, src->ptr.pchar);
   if (! str_sw_pos_to_uw(start, src->size, &buf.rpos)) {
     err_puts("str_init_slice: str_sw_pos_to_uw: start");
     assert(! "str_init_slice: str_sw_pos_to_uw: start");
diff --git a/libkc3/sw.c b/libkc3/sw.c
index dc0cbc4..d9e7651 100644
--- a/libkc3/sw.c
+++ b/libkc3/sw.c
@@ -113,7 +113,7 @@ sw * sw_init_str (sw *s, const s_str *str)
 {
   s_buf buf;
   sw tmp = 0;
-  buf_init(&buf, false, str->size, (char *) str->ptr.pchar);
+  buf_init_const(&buf, str->size, str->ptr.pchar);
   buf.wpos = str->size;
   if (buf_parse_sw(&buf, &tmp) <= 0) {
     err_puts("sw_init_str: buf_parse_sw");
diff --git a/libkc3/tuple.c b/libkc3/tuple.c
index 0d0ec66..fa96fc8 100644
--- a/libkc3/tuple.c
+++ b/libkc3/tuple.c
@@ -64,7 +64,7 @@ s_tuple * tuple_init_1 (s_tuple *tuple, const char *p)
   assert(tuple);
   assert(p);
   len = strlen(p);
-  buf_init(&buf, false, len, (char *) p);
+  buf_init_const(&buf, len, p);
   buf.wpos = len;
   r = buf_parse_tuple(&buf, tuple);
   if (r < 0 || (uw) r != len) {