Improved error messages
This commit is contained in:
parent
095970170c
commit
f77a45095a
@ -10,8 +10,8 @@
|
||||
// Convert negative indices to back-indexed without branching: index0 = index + (index < 0)*(len+1)) - 1
|
||||
#define $Array_get(type, x, i) ({ const array_t *$arr = x; int64_t $index = (int64_t)(i); \
|
||||
int64_t $off = $index + ($index < 0) * ($arr->length + 1) - 1; \
|
||||
if (__builtin_expect($off < 0 && $off >= $arr->length, 0)) \
|
||||
fail("Invalid array index: %ld (array has length %ld)", $index, $arr->length); \
|
||||
if (__builtin_expect($off < 0 || $off >= $arr->length, 0)) \
|
||||
fail("Invalid array index: %ld (array has length %ld)\n", $index, $arr->length); \
|
||||
*(type*)($arr->data + $arr->stride * $off);})
|
||||
#define $Array_get_unchecked(type, x, i) ({ const array_t *$arr = x; int64_t $index = (int64_t)(i); \
|
||||
int64_t $off = $index + ($index < 0) * ($arr->length + 1) - 1; \
|
||||
|
@ -20,11 +20,13 @@ extern bool USE_COLOR;
|
||||
|
||||
public const char *SSS_HASH_VECTOR = "sss hash vector ----------------------------------------------";;
|
||||
|
||||
public void fail(const char *fmt, ...)
|
||||
public void fail(CORD fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vfprintf(stderr, fmt, args);
|
||||
if (USE_COLOR) fputs("\x1b[31;7m FAIL: \x1b[m ", stderr);
|
||||
else fputs("FAIL: ", stderr);
|
||||
CORD_vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
raise(SIGABRT);
|
||||
}
|
||||
@ -145,7 +147,7 @@ public void __doctest(void *expr, TypeInfo *type, CORD expected, const char *fil
|
||||
if (!success) {
|
||||
if (filename && file)
|
||||
fprint_span(stderr, file, file->text+start, file->text+end, "\x1b[31;1m", 2, USE_COLOR);
|
||||
fail(USE_COLOR ? "\x1b[31;1mExpected: \x1b[32;7m%s\x1b[0m\n\x1b[31;1m But got: \x1b[31;7m%s\x1b[0m\n" : "Expected: %s\n But got: %s\n",
|
||||
fail(USE_COLOR ? "\x1b[31;1mDoctest failure:\nExpected: \x1b[32;7m%s\x1b[0m\n\x1b[31;1m But got: \x1b[31;7m%s\x1b[0m\n" : "Doctest failure:\nExpected: %s\n But got: %s\n",
|
||||
expected, expr_str);
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
#define $Table_get(table_expr, key_t, val_t, key_expr, info_expr) ({ \
|
||||
const table_t *$t = table_expr; key_t $k = key_expr; const TypeInfo* $info = info_expr; \
|
||||
const val_t *$v = Table_get($t, &$k, $info); \
|
||||
if (__builtin_expect($v == NULL, 0)) fail("The key %r is not in this table", generic_as_str(&$k, no, $info->TableInfo.key)); \
|
||||
if (__builtin_expect($v == NULL, 0)) fail("The key %r is not in this table\n", generic_as_str(&$k, USE_COLOR, $info->TableInfo.key)); \
|
||||
*$v; })
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user