From 938b9b96e20d7233492dbdb2fbb396ffebb51b96 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 14 Apr 2025 17:00:15 -0400 Subject: Reworking of stack traces (back to using addr2line) for compatibility and improved output quality --- src/stdlib/print.h | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) (limited to 'src/stdlib/print.h') diff --git a/src/stdlib/print.h b/src/stdlib/print.h index 0b911ed6..60c9c139 100644 --- a/src/stdlib/print.h +++ b/src/stdlib/print.h @@ -24,35 +24,12 @@ #include #include "datatypes.h" +#include "mapmacro.h" #ifndef PRINT_COLOR #define PRINT_COLOR 0 #endif -#define EVAL0(...) __VA_ARGS__ -#define EVAL1(...) EVAL0(EVAL0(EVAL0(__VA_ARGS__))) -#define EVAL2(...) EVAL1(EVAL1(EVAL1(__VA_ARGS__))) -#define EVAL3(...) EVAL2(EVAL2(EVAL2(__VA_ARGS__))) -#define EVAL4(...) EVAL3(EVAL3(EVAL3(__VA_ARGS__))) -#define EVAL(...) EVAL4(EVAL4(EVAL4(__VA_ARGS__))) - -#define MAP_END(...) -#define MAP_OUT -#define MAP_COMMA , - -#define MAP_GET_END2() 0, MAP_END -#define MAP_GET_END1(...) MAP_GET_END2 -#define MAP_GET_END(...) MAP_GET_END1 -#define MAP_NEXT0(test, next, ...) next MAP_OUT - -#define MAP_LIST_NEXT1(test, next) MAP_NEXT0(test, MAP_COMMA next, 0) -#define MAP_LIST_NEXT(test, next) MAP_LIST_NEXT1(MAP_GET_END test, next) - -#define MAP_LIST0(f, x, peek, ...) f(x) MAP_LIST_NEXT(peek, MAP_LIST1)(f, peek, __VA_ARGS__) -#define MAP_LIST1(f, x, peek, ...) f(x) MAP_LIST_NEXT(peek, MAP_LIST0)(f, peek, __VA_ARGS__) - -#define MAP_LIST(f, ...) EVAL(MAP_LIST1(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) - // GCC lets you define macro-like functions which are always inlined and never // compiled using this combination of flags. See: https://gcc.gnu.org/onlinedocs/gcc/Inline.html #ifndef PRINT_FN @@ -108,10 +85,10 @@ PRINT_FN _print_float(FILE *f, float x) { return fprintf(f, hl("%g"), (double)x) PRINT_FN _print_double(FILE *f, double x) { return fprintf(f, hl("%g"), x); } PRINT_FN _print_pointer(FILE *f, void *p) { return fprintf(f, hl("%p"), p); } PRINT_FN _print_bool(FILE *f, bool b) { return fputs(b ? hl("yes") : hl("no"), f); } -PRINT_FN _print_str(FILE *f, const char *s) { return fputs(s, f); } +PRINT_FN _print_str(FILE *f, const char *s) { return fputs(s ? s : "(null)", f); } int _print_char(FILE *f, char c); int _print_quoted(FILE *f, quoted_t quoted); -PRINT_FN _print_string_slice(FILE *f, string_slice_t slice) { return fwrite(slice.str, 1, slice.length, f); } +PRINT_FN _print_string_slice(FILE *f, string_slice_t slice) { return slice.str ? fwrite(slice.str, 1, slice.length, f) : (size_t)fputs("(null)", f); } PRINT_FN _print_hex(FILE *f, hex_format_t hex) { return fprintf(f, hex.no_prefix ? (hex.uppercase ? hl("%0*"FMT64"X") : hl("%0*"FMT64"x")) : (hex.uppercase ? hl("0x%0*"FMT64"X") : hl("%#0*"FMT64"x")), hex.digits, hex.n); } -- cgit v1.2.3