Commit 88a6d40724743ce7620c6f3b58fc5413ace797eb

Thomas de Grivel 2024-03-01T16:53:07

remove std headers where possible

diff --git a/libc3/alloc.h b/libc3/alloc.h
index 4c7e01a..af30c85 100644
--- a/libc3/alloc.h
+++ b/libc3/alloc.h
@@ -16,5 +16,6 @@
 #include "types.h"
 
 void * alloc (uw size);
+void   free (void *ptr);
 
 #endif /* LIBC3_ALLOC_H */
diff --git a/libc3/arg.c b/libc3/arg.c
index c6477a0..0f1af99 100644
--- a/libc3/arg.c
+++ b/libc3/arg.c
@@ -10,10 +10,8 @@
  * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
  * THIS SOFTWARE.
  */
-#include <assert.h>
-#include <err.h>
-#include <stdlib.h>
-#include <strings.h>
+#include "alloc.h"
+#include "assert.h"
 #include "arg.h"
 
 s_arg * arg_delete (s_arg *arg)
@@ -52,7 +50,12 @@ uw arg_length (s_arg *arg)
 s_arg * arg_new (void)
 {
   s_arg *arg;
-  if (! (arg = malloc(sizeof(s_arg))))
-    errx(1, "arg_new: out of memory");
-  return arg_init(arg);
+  arg = alloc(sizeof(s_arg));
+  if (! arg)
+    return NULL;
+  if (! arg_init(arg)) {
+    free(arg);
+    return NULL;
+  }
+  return arg;
 }
diff --git a/libc3/f128.c b/libc3/f128.c
index d7f77fe..a8a3138 100644
--- a/libc3/f128.c
+++ b/libc3/f128.c
@@ -10,10 +10,8 @@
  * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
  * THIS SOFTWARE.
  */
-#include <assert.h>
-#include <err.h>
-#include <math.h>
 #include <stdlib.h>
+#include "assert.h"
 #include "integer.h"
 #include "tag.h"
 #include "tag_type.h"
@@ -76,9 +74,10 @@ f128 * f128_init_cast (f128 *x, const s_tag *tag)
   default:
     break;
   }
-  warnx("f128_init_cast: cannot cast %s to f128",
-        tag_type_to_string(tag->type));
-  assert(! "f128_init_cast: cannot cast to f128");
+  err_write_1("f128_init_cast: cannot cast ");
+  err_write_1(tag_type_to_string(tag->type));
+  err_puts(" to F128");
+  assert(! "f128_init_cast: cannot cast to F128");
   return NULL;
 }
 
diff --git a/libc3/f32.c b/libc3/f32.c
index e155a8e..14ed580 100644
--- a/libc3/f32.c
+++ b/libc3/f32.c
@@ -10,8 +10,8 @@
  * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
  * THIS SOFTWARE.
  */
-#include <assert.h>
-#include <err.h>
+#include <stdlib.h>
+#include "assert.h"
 #include "integer.h"
 #include "tag.h"
 #include "tag_type.h"
@@ -73,9 +73,10 @@ f32 * f32_init_cast (f32 *x, const s_tag *tag)
   default:
     break;
   }
-  warnx("f32_init_cast: cannot cast %s to f32",
-        tag_type_to_string(tag->type));
-  assert(! "f32_init_cast: cannot cast to f32");
+  err_write_1("f32_init_cast: cannot cast ");
+  err_write_1(tag_type_to_string(tag->type));
+  err_puts(" to F32");
+  assert(! "f32_init_cast: cannot cast to F32");
   return NULL;
 }
 
diff --git a/libc3/f64.c b/libc3/f64.c
index ab7caf0..32408eb 100644
--- a/libc3/f64.c
+++ b/libc3/f64.c
@@ -10,9 +10,8 @@
  * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
  * THIS SOFTWARE.
  */
-#include <assert.h>
-#include <err.h>
 #include <stdlib.h>
+#include "assert.h"
 #include "integer.h"
 #include "tag.h"
 #include "tag_type.h"
@@ -73,9 +72,10 @@ f64 * f64_init_cast (f64 *x, const s_tag *tag)
   default:
     break;
   }
-  warnx("f64_init_cast: cannot cast %s to f64",
-        tag_type_to_string(tag->type));
-  assert(! "f64_init_cast: cannot cast to f64");
+  err_write_1("f64_init_cast: cannot cast ");
+  err_write_1(tag_type_to_string(tag->type));
+  err_puts(" to F64");
+  assert(! "f64_init_cast: cannot cast to F64");
   return NULL;
 }
 
diff --git a/libc3/fact.c b/libc3/fact.c
index b6063eb..0a21c8b 100644
--- a/libc3/fact.c
+++ b/libc3/fact.c
@@ -11,7 +11,6 @@
  * THIS SOFTWARE.
  */
 #include "assert.h"
-#include <err.h>
 #include "buf.h"
 #include "buf_inspect.h"
 #include "hash.h"
@@ -66,14 +65,14 @@ s_str * fact_inspect (const s_fact *fact, s_str *dest)
   s_buf buf;
   sw size;
   if ((size = buf_inspect_fact_size(fact)) < 0) {
+    err_puts("fact_inspect: size error");
     assert(! "fact_inspect: size error");
-    errx(1, "fact_inspect: size error");
     return NULL;
   }
   buf_init_alloc(&buf, size);
   if (buf_inspect_fact(&buf, fact) != size) {
+    err_puts("fact_inspect: inspect error");
     assert(! "fact_inspect: inspect error");
-    errx(1, "fact_inspect: inspect error");
     return NULL;
   }
   return buf_to_str(&buf, dest);
diff --git a/libc3/fn.c b/libc3/fn.c
index 94a62e0..e066184 100644
--- a/libc3/fn.c
+++ b/libc3/fn.c
@@ -13,7 +13,6 @@
 #include "assert.h"
 #include <stdlib.h>
 #include <string.h>
-#include <strings.h>
 #include "arg.h"
 #include "binding.h"
 #include "buf.h"
diff --git a/libc3/fn_clause.c b/libc3/fn_clause.c
index 77f7c57..02c1002 100644
--- a/libc3/fn_clause.c
+++ b/libc3/fn_clause.c
@@ -12,7 +12,6 @@
  */
 #include "assert.h"
 #include <stdlib.h>
-#include <strings.h>
 #include "arg.h"
 #include "binding.h"
 #include "block.h"
diff --git a/libc3/skiplist.c.in b/libc3/skiplist.c.in
index 8ac66cf..f653350 100644
--- a/libc3/skiplist.c.in
+++ b/libc3/skiplist.c.in
@@ -12,7 +12,6 @@
  */
 #include <assert.h>
 #include <stdlib.h>
-#include <strings.h>
 #include "compare.h"
 #include "_NAME$.h"
 #include "skiplist_node___NAME$.h"
diff --git a/libc3/skiplist__fact.c b/libc3/skiplist__fact.c
index b0de02d..b84381b 100644
--- a/libc3/skiplist__fact.c
+++ b/libc3/skiplist__fact.c
@@ -12,7 +12,6 @@
  */
 #include <assert.h>
 #include <stdlib.h>
-#include <strings.h>
 #include "compare.h"
 #include "fact.h"
 #include "skiplist_node__fact.h"
diff --git a/libc3/tag.c b/libc3/tag.c
index b4e1c1c..084680d 100644
--- a/libc3/tag.c
+++ b/libc3/tag.c
@@ -12,9 +12,7 @@
  */
 #include "assert.h"
 #include <math.h>
-#include <stdlib.h>
 #include <string.h>
-#include <strings.h>
 #include "array.h"
 #include "block.h"
 #include "buf.h"
diff --git a/update_sources b/update_sources
index e6156fd..30395a5 100755
--- a/update_sources
+++ b/update_sources
@@ -42,7 +42,7 @@ test/ic3_test
 test/zero"
 sources C3_OTHER_SOURCES "$C3_OTHER_SOURCES"
 
-C3_EXTERNAL_SOURCES="$(find libffi linenoise ucd2c \( -name '.*' -prune \) -or -type f -print)
+C3_EXTERNAL_SOURCES="$(find linenoise ucd2c \( -name '.*' -prune \) -or -type f -print)
 $(find libtommath -name '*.c' -or -name '*.h')
 libtommath/LICENSE
 libtommath/README.md"