diff --git a/libc3/map.c b/libc3/map.c
index a82b673..7626f44 100644
--- a/libc3/map.c
+++ b/libc3/map.c
@@ -10,8 +10,7 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
-#include <err.h>
+#include "assert.h"
#include <stdlib.h>
#include <string.h>
#include "buf.h"
@@ -28,7 +27,7 @@ s_tag * map_access (const s_map *map, const s_tag *key, s_tag *value)
assert(key);
assert(value);
if (key->type != TAG_SYM) {
- warnx("map_access: only works with symbol key");
+ err_puts("map_access: only works with symbol key");
return NULL;
}
return map_get(map, key, value);
@@ -39,8 +38,10 @@ s_map * map_init_cast (s_map *map, const s_tag *tag)
assert(tag);
if (tag->type == TAG_MAP)
return map_init_copy(map, &tag->data.map);
- warnx("map_init_cast: cannot cast %s to map",
- tag_type_to_string(tag->type));
+ err_write_1("map_init_cast: cannot cast ");
+ err_write_1(tag_type_to_string(tag->type));
+ err_puts(" to Map");
+ assert(! "map_init_cast: cannot cast to Map");
return NULL;
}
@@ -87,13 +88,23 @@ s_map * map_init (s_map *map, uw count)
s_map * map_init_1 (s_map *map, const char *p)
{
s_buf buf;
+ uw len;
sw r;
assert(map);
assert(p);
- buf_init_1(&buf, false, (char *) p);
- if ((r = buf_parse_map(&buf, map)) != (sw) strlen(p)) {
- assert(! "invalid map");
- warnx("invalid map: \"%s\" (%ld)", p, r);
+ len = strlen(p);
+ buf_init(&buf, false, len, (char *) p);
+ buf.wpos = len;
+ r = buf_parse_map(&buf, map);
+ if (r < 0 || (uw) r != len) {
+ err_write_1("map_init_1: invalid map: \"");
+ err_write_1(p);
+ err_write_1("\" => ");
+ err_inspect_sw(&r);
+ err_write_1(" != ");
+ err_inspect_uw(&len);
+ err_write_1("\n");
+ assert(! "map_init_1: invalid map");
return NULL;
}
return map;
@@ -122,7 +133,10 @@ s_map * map_init_from_lists (s_map *map, const s_list *keys,
const s_list *v;
assert(map);
if ((len = list_length(keys)) != list_length(values)) {
- warnx("map_init_from_lists: list length don't match");
+ err_puts("map_init_from_lists:"
+ " keys and values length do not match");
+ assert(! "map_init_from_lists:"
+ " keys and values length do not match");
return NULL;
}
map_init(map, len);
@@ -175,31 +189,50 @@ s_list ** map_map (const s_map *map, const s_fn *fn, s_list **result)
s_map * map_new (uw count)
{
s_map *map;
- if (! (map = malloc(sizeof(s_map)))) {
- warn("map_new");
+ map = calloc(1, sizeof(s_map));
+ if (! map) {
+ err_puts("map_new: failed to allocate memory");
+ assert(! "map_new: failed to allocate memory");
return NULL;
}
- return map_init(map, count);
+ if (! map_init(map, count)) {
+ free(map);
+ return NULL;
+ }
+ return map;
}
s_map * map_new_1 (const char *p)
{
s_map *map;
- if (! (map = malloc(sizeof(s_map)))) {
- warn("map_new");
+ map = calloc(1, sizeof(s_map));
+ if (! map) {
+ err_puts("map_new_1: failed to allocate memory");
+ assert(! "map_new_1: failed to allocate memory");
+ return NULL;
+ }
+ if (! map_init_1(map, p)) {
+ free(map);
return NULL;
}
- return map_init_1(map, p);
+ return map;
}
s_map * map_new_from_lists (const s_list *keys, const s_list *values)
{
s_map *map;
- if (! (map = malloc(sizeof(s_map)))) {
- warn("map_new");
+ map = calloc(1, sizeof(s_map));
+ if (! map) {
+ err_puts("map_new_from_lists: failed to allocate memory");
+ assert(! "map_new_from_lists: failed to allocate memory");
+ return NULL;
+ }
+ if (! map_init_from_lists(map, keys, values)) {
+ free(map);
return NULL;
}
- return map_init_from_lists(map, keys, values);
+ return map;
+
}
s_map * map_set (s_map *map, const s_tag *key, const s_tag *value)
@@ -272,7 +305,8 @@ s_map * map_update_list (const s_map *map, const s_list *alist, s_map *dest)
while (i) {
assert(i->tag.type == TAG_TUPLE && i->tag.data.tuple.count == 2);
if (i->tag.type != TAG_TUPLE || i->tag.data.tuple.count != 2) {
- warnx("map_update_list: not an associative list");
+ err_puts("map_update_list: not an associative list");
+ assert(! "map_update_list: not an associative list");
goto ko;
}
if (! map_set(&tmp, i->tag.data.tuple.tag, i->tag.data.tuple.tag + 1))
diff --git a/libc3/module.c b/libc3/module.c
index 4d3f73a..1538cff 100644
--- a/libc3/module.c
+++ b/libc3/module.c
@@ -10,8 +10,7 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
-#include <err.h>
+#include "assert.h"
#include <string.h>
#include "buf.h"
#include "character.h"
@@ -39,8 +38,9 @@ bool module_ensure_loaded (const s_sym *module, s_facts *facts)
NULL, NULL });
if (! facts_with_cursor_next(&cursor)) {
if (! module_load(module, facts)) {
- warnx("module not found: %s",
- module->str.ptr.ps8);
+ err_write_1("module_ensure_loaded: module not found: ");
+ err_puts(module->str.ptr.pchar);
+ assert(! "module_ensure_loaded: module not found");
facts_with_cursor_clean(&cursor);
return false;
}
@@ -117,7 +117,8 @@ s_str * module_path (const s_sym *module, const s_str *prefix,
return buf_to_str(&out, dest);
error:
buf_clean(&out);
- warnx("module_path: error");
+ err_puts("module_path: error");
+ assert(! "module_path: error");
return NULL;
}
diff --git a/libc3/ptag.c b/libc3/ptag.c
index da28f7b..0af5378 100644
--- a/libc3/ptag.c
+++ b/libc3/ptag.c
@@ -11,7 +11,6 @@
* THIS SOFTWARE.
*/
#include "assert.h"
-#include <err.h>
#include "ptag.h"
#include "tag_type.h"
diff --git a/libc3/ptr.c b/libc3/ptr.c
index 9e8a66c..ee82b04 100644
--- a/libc3/ptr.c
+++ b/libc3/ptr.c
@@ -11,7 +11,6 @@
* THIS SOFTWARE.
*/
#include "assert.h"
-#include <err.h>
#include <stdlib.h>
#include "integer.h"
#include "ptr.h"
@@ -53,10 +52,13 @@ u_ptr_w * ptr_init_cast (u_ptr_w *p, const s_tag *tag)
case TAG_U32: p->p = (void *) ((uw) tag->data.u32); return p;
case TAG_U64: p->p = (void *) ((uw) tag->data.u64); return p;
case TAG_UW: p->p = (void *) ((uw) tag->data.uw); return p;
- default: break;
+ default:
+ break;
}
- warnx("ptr_cast: cannot cast %s to Ptr",
- tag_type_to_string(tag->type));
+ err_write_1("ptr_cast: cannot cast ");
+ err_write_1(tag_type_to_string(tag->type));
+ err_puts(" to Ptr");
+ assert(! "ptr_cast: cannot cast to Ptr");
return NULL;
}
@@ -75,7 +77,8 @@ u_ptr_w * ptr_new (void *p)
u_ptr_w *ptr;
ptr = calloc(1, sizeof(u_ptr_w));
if (! ptr) {
- warn("ptr_new: ptr");
+ err_puts("ptr_new: failed to allocate memory");
+ assert(! "ptr_new: failed to allocate memory");
return NULL;
}
if (! ptr_init(ptr, p)) {
@@ -91,7 +94,8 @@ u_ptr_w * ptr_new_copy (const u_ptr_w *src)
assert(src);
ptr = calloc(1, sizeof(u_ptr_w));
if (! ptr) {
- warn("ptr_new: ptr");
+ err_puts("ptr_new_copy: failed to allocate memory");
+ assert(! "ptr_new_copy: failed to allocate memory");
return NULL;
}
if (! ptr_init_copy(ptr, src)) {
diff --git a/libc3/ptr_free.c b/libc3/ptr_free.c
index 1b11d0f..bacfc67 100644
--- a/libc3/ptr_free.c
+++ b/libc3/ptr_free.c
@@ -10,8 +10,7 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
-#include <err.h>
+#include "assert.h"
#include <stdlib.h>
#include "integer.h"
#include "ptr_free.h"
@@ -62,8 +61,9 @@ u_ptr_w * ptr_free_init_cast (u_ptr_w *p, const s_tag *tag)
case TAG_UW: p->p = (void *) ((uw) tag->data.uw); return p;
default: break;
}
- warnx("ptr_free_init_cast: cannot cast %s to PtrFree",
- tag_type_to_string(tag->type));
+ err_write_1("ptr_free_init_cast: cannot cast ");
+ err_write_1(tag_type_to_string(tag->type));
+ err_puts(" to PtrFree");
assert(! "ptr_free_init_cast: cannot cast to PtrFree");
return NULL;
}
@@ -83,7 +83,8 @@ u_ptr_w * ptr_free_new (void *p)
u_ptr_w *ptr_free;
ptr_free = calloc(1, sizeof(u_ptr_w));
if (! ptr_free) {
- warn("ptr_free_new: ptr_free");
+ err_puts("ptr_free_new: failed to allocate memory");
+ assert(! "ptr_free_new: failed to allocate memory");
return NULL;
}
if (! ptr_free_init(ptr_free, p)) {
@@ -99,7 +100,8 @@ u_ptr_w * ptr_free_new_copy (const u_ptr_w *src)
assert(src);
ptr_free = calloc(1, sizeof(u_ptr_w));
if (! ptr_free) {
- warn("ptr_free_new: ptr_free");
+ err_puts("ptr_free_new_copy: failed to allocate memory");
+ assert(! "ptr_free_new_copy: failed to allocate memory");
return NULL;
}
if (! ptr_free_init_copy(ptr_free, src)) {