diff --git a/libc3/str.c b/libc3/str.c
index 5947ccf..3218392 100644
--- a/libc3/str.c
+++ b/libc3/str.c
@@ -11,7 +11,6 @@
* THIS SOFTWARE.
*/
#include "assert.h"
-#include <err.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -80,8 +79,8 @@ sw str_character_position (const s_str *str, character c)
i++;
}
if (r < 0) {
+ err_puts("str_character_position: invalid str character utf8");
assert(! "str_character_position: invalid str character utf8");
- errx(1, "str_character_position: invalid str character utf8");
}
return -1;
}
@@ -291,8 +290,11 @@ s_str * str_init_slice (s_str *str, const s_str *src, sw start, sw end)
! str_sw_pos_to_uw(end, src->size, &buf.wpos))
return NULL;
if (buf.rpos > buf.wpos) {
- warnx("str_init_slice: invalid positions: %lu > %lu",
- buf.rpos, buf.wpos);
+ err_write_1("str_init_slice: invalid positions: ");
+ err_inspect_uw(&buf.rpos);
+ err_write_1(" > ");
+ err_inspect_uw(&buf.wpos);
+ err_write_1("\n");
assert(! "str_init_slice: invalid positions");
return NULL;
}
@@ -313,8 +315,11 @@ s_str * str_init_vf (s_str *str, const char *fmt, va_list ap)
int len;
char *s;
len = vasprintf(&s, fmt, ap);
- if (len < 0)
- err(1, "vasprintf");
+ if (len < 0) {
+ err_puts("str_init_vf: vasprintf");
+ assert(! "str_init_vf: vasprintf");
+ return NULL;
+ }
return str_init(str, s, len, s);
}
@@ -348,9 +353,12 @@ sw str_length_utf8 (const s_str *str)
s_str * str_new (char *free, uw size, const char *p)
{
s_str *str;
- str = malloc(sizeof(s_str));
- if (! str)
- err(1, "out of memory");
+ str = calloc(1, sizeof(s_str));
+ if (! str) {
+ err_puts("str_new: failed to allocate memory");
+ assert(! "str_new: failed to allocate memory");
+ return NULL;
+ }
str_init(str, free, size, p);
return str;
}
@@ -367,11 +375,16 @@ s_str * str_new_cpy (const char *p, uw size)
char *a;
s_str *str;
if (! (a = malloc(size))) {
- warn("str_new_cpy");
+ err_puts("str_new_cpy: failed to allocate memory");
+ assert(! "str_new_cpy: failed to allocate memory");
return NULL;
}
memcpy(a, p, size);
str = str_new(a, size, a);
+ if (! str) {
+ free(a);
+ return NULL;
+ }
return str;
}
@@ -381,11 +394,16 @@ s_str * str_new_copy (const s_str *src)
s_str *dest;
assert(src);
if (! (a = malloc(src->size))) {
- warn("str_new_copy");
+ err_puts("str_new_copy: failed to allocate memory");
+ assert(! "str_new_copy: failed to allocate memory");
return NULL;
}
memcpy(a, src->ptr.p, src->size);
dest = str_new(a, src->size, a);
+ if (! dest) {
+ free(a);
+ return NULL;
+ }
return dest;
}
@@ -412,8 +430,11 @@ s_str * str_new_vf (const char *fmt, va_list ap)
char *s;
s_str *dest;
len = vasprintf(&s, fmt, ap);
- if (len < 0)
- err(1, "vasprintf");
+ if (len < 0) {
+ err_puts("str_new_vf: vasprintf");
+ assert(! "str_new_vf: vasprintf");
+ return NULL;
+ }
dest = str_new(s, len, s);
return dest;
}
@@ -633,8 +654,11 @@ uw * str_sw_pos_to_uw (sw pos, uw max_pos, uw *dest)
assert(dest);
if (pos >= 0) {
if ((uw) pos > max_pos) {
- warnx("str_sw_pos_to_uw: index out of bounds: %ld > %lu",
- pos, max_pos);
+ err_write_1("str_sw_pos_to_uw: index too large: ");
+ err_inspect_sw(&pos);
+ err_write_1(" > ");
+ err_inspect_uw(&max_pos);
+ err_write_1("\n");
assert(! "str_sw_pos_to_uw: index too large");
return NULL;
}
@@ -644,8 +668,11 @@ uw * str_sw_pos_to_uw (sw pos, uw max_pos, uw *dest)
if (max_pos > SW_MAX || pos >= (sw) -max_pos)
*dest = max_pos - pos;
else {
- warnx("str_sw_pos_to_uw: index out of bounds: %ld < -%lu",
- pos, max_pos);
+ err_write_1("str_sw_pos_to_uw: index too low: ");
+ err_inspect_sw(&pos);
+ err_write_1(" < -");
+ err_inspect_uw(&max_pos);
+ err_write_1("\n");
assert(! "str_sw_pos_to_uw: index too low");
return NULL;
}
diff --git a/libc3/struct.c b/libc3/struct.c
index 0260e56..c96a2ec 100644
--- a/libc3/struct.c
+++ b/libc3/struct.c
@@ -11,7 +11,6 @@
* THIS SOFTWARE.
*/
#include "assert.h"
-#include <err.h>
#include <stdlib.h>
#include <string.h>
#include "data.h"
@@ -33,8 +32,8 @@ s_struct * struct_allocate (s_struct *s)
tmp.free_data = true;
tmp.data = calloc(1, tmp.type->size);
if (! tmp.data) {
- warn("struct_allocate: data");
- assert(! "struct_allocate: data: failed to allocate memory");
+ err_puts("struct_allocate: failed to allocate memory");
+ assert(! "struct_allocate: failed to allocate memory");
return NULL;
}
*s = tmp;
@@ -126,9 +125,10 @@ s_struct * struct_init_cast (s_struct *s, const s_tag *tag)
default:
break;
}
- warnx("struct_init_cast: cannot cast %s to Struct",
- tag_type_to_string(tag->type));
- //assert(! "struct_init_cast: cannot cast to Struct");
+ err_write_1("struct_init_cast: cannot cast ");
+ err_write_1(tag_type_to_string(tag->type));
+ err_puts(" to Struct");
+ assert(! "struct_init_cast: cannot cast to Struct");
return NULL;
}
@@ -196,8 +196,8 @@ s_struct * struct_init_from_lists (s_struct *s, const s_sym *module,
return NULL;
tmp.tag = calloc(tmp.type->map.count, sizeof(s_tag));
if (! tmp.tag) {
- err_puts("struct_init_from_lists: tag");
- assert(! "struct_init_from_lists: failed to allocate memory");
+ err_puts("struct_init_from_lists: failed to allocate memory (tag)");
+ assert(! "struct_init_from_lists: failed to allocate memory (tag)");
return NULL;
}
k = keys;
@@ -205,14 +205,15 @@ s_struct * struct_init_from_lists (s_struct *s, const s_sym *module,
while (k && v) {
assert(k->tag.type == TAG_SYM);
if (k->tag.type != TAG_SYM) {
- warnx("struct_init_from_lists: key that is not a symbol: %s",
- tag_type_to_string(k->tag.type));
+ err_write_1("struct_init_from_lists: key that is not a symbol: ");
+ err_puts(tag_type_to_string(k->tag.type));
assert(! "struct_init_from_lists: key that is not a symbol");
goto ko;
}
if (! struct_find_key_index(&tmp, k->tag.data.sym, &i)) {
- warnx("struct_init_from_lists: cannot find key in defstruct: %s",
- k->tag.data.sym->str.ptr.ps8);
+ err_write_1("struct_init_from_lists:"
+ " cannot find key in defstruct: ");
+ err_puts(k->tag.data.sym->str.ptr.pchar);
assert(! "struct_init_from_lists: cannot find key in defstruct");
goto ko;
}
@@ -256,7 +257,8 @@ s_struct * struct_new (const s_sym *module)
assert(module);
s = calloc(1, sizeof(s_struct));
if (! s) {
- warn("struct_new: %s: calloc", module->str.ptr.ps8);
+ err_puts("struct_new: failed to allocate memory");
+ assert(! "struct_new: failed to allocate memory");
return NULL;
}
if (! struct_init(s, module)) {
@@ -272,7 +274,8 @@ s_struct * struct_new_1 (const s8 *p)
assert(p);
s = calloc(1, sizeof(s_struct));
if (! s) {
- warn("struct_new_1: %s: calloc", p);
+ err_puts("struct_new_1: failed to allocate memory");
+ assert(! "struct_new_1: failed to allocate memory");
return NULL;
}
if (! struct_init_1(s, p)) {
@@ -288,7 +291,8 @@ s_struct * struct_new_copy (const s_struct *src)
assert(src);
s = calloc(1, sizeof(s_struct));
if (! s) {
- warn("struct_new_copy: calloc");
+ err_puts("struct_new_copy: failed to allocate memory");
+ assert(! "struct_new_copy: failed to allocate memory");
return NULL;
}
if (! struct_init_copy(s, src)) {
diff --git a/libc3/tag_type.c b/libc3/tag_type.c
index 1b649df..c357262 100644
--- a/libc3/tag_type.c
+++ b/libc3/tag_type.c
@@ -10,7 +10,6 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <err.h>
#include "c3.h"
#include "buf_inspect.h"
#include "buf_parse.h"
@@ -60,7 +59,7 @@ bool tag_type_size (e_tag_type type, uw *dest)
case TAG_UNQUOTE: *dest = sizeof(s_unquote); return true;
case TAG_VAR: *dest = sizeof(s_tag); return true;
}
- warnx("tag_type_size: invalid tag type: %d", type);
+ err_puts("tag_type_size: invalid tag type");
assert(! "tag_type_size: invalid tag type");
return false;
}
@@ -107,8 +106,8 @@ bool tag_type_to_ffi_type (e_tag_type type, ffi_type **dest)
case TAG_VAR: *dest = &ffi_type_pointer; return true;
case TAG_VOID: *dest = &ffi_type_void; return true;
}
- warnx("tag_type_to_ffi_type: unknown tag type: %d", type);
- assert(! "tag_type_to_ffi_type: unknown tag type");
+ err_puts("tag_type_to_ffi_type: invalid tag type");
+ assert(! "tag_type_to_ffi_type: invalid tag type");
return false;
}
@@ -154,7 +153,7 @@ const char * tag_type_to_string (e_tag_type tag_type)
case TAG_UNQUOTE: return "Unquote";
case TAG_VAR: return "Var";
}
- warnx("tag_type_to_string: unknown tag type: %d", tag_type);
- assert(! "tag_type_to_string: unknown tag type");
+ err_puts("tag_type_to_string: invalid tag type");
+ assert(! "tag_type_to_string: invalid tag type");
return NULL;
}