aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib/print.h
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-04-14 17:00:15 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-04-14 17:00:15 -0400
commit938b9b96e20d7233492dbdb2fbb396ffebb51b96 (patch)
tree8235dac9ae352f1b708d12a491acd6650720cefc /src/stdlib/print.h
parentc3cec08ce94b25eb19588d333c738a24e96abac4 (diff)
Reworking of stack traces (back to using addr2line) for compatibility
and improved output quality
Diffstat (limited to 'src/stdlib/print.h')
-rw-r--r--src/stdlib/print.h29
1 files changed, 3 insertions, 26 deletions
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 <unistd.h>
#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);
}