diff --git a/src/neat/runtime/array.nt b/src/neat/runtime/array.nt index d880909..9b395fe 100644 --- a/src/neat/runtime/array.nt +++ b/src/neat/runtime/array.nt @@ -1,12 +1,11 @@ module neat.runtime.array; +extern(C) void neat_runtime_index_oob(size_t index); + size_t checkIndex(size_t index, size_t length) { // < 0 overflows to >= length. if (index >= length) { - import neat.runtime.stdlib : exit, fprintf, stderr; - - fprintf(stderr, "Array index out of bounds: %zd\n".ptr, index); - exit(1); + neat_runtime_index_oob(index); } return index; } diff --git a/src/runtime.c b/src/runtime.c index f63db61..82c2c82 100644 --- a/src/runtime.c +++ b/src/runtime.c @@ -172,10 +172,19 @@ void print_backtrace() #endif } -void neat_runtime_refcount_violation(struct String s, ptrdiff_t *ptr) +#define FATALERROR __attribute__((cold)) __attribute__((noinline)) __attribute__((noreturn)) + +void FATALERROR neat_runtime_refcount_violation(struct String s, ptrdiff_t *ptr) { printf("<%.*s: refcount logic violated: %zd at %p\n", (int) s.length, s.ptr, *ptr, ptr); print_backtrace(); + exit(1); +} + +void FATALERROR neat_runtime_index_oob(size_t index) +{ + fprintf(stderr, "Array index out of bounds: %zd\n", index); + exit(1); } void neat_runtime_refcount_inc(struct String s, ptrdiff_t *ptr)