commit d0ff2188c4987a836a09e0d3a4d934dfa0160efe
parent 84ad7f4f859b7b9b72328efbfc97ede6a095b787
Author: hhvn <dev@hhvn.uk>
Date: Sun, 15 Jan 2023 13:44:53 +0000
Custom assert()
Diffstat:
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/err.c b/src/err.c
@@ -14,7 +14,7 @@
void
_err(int code, char *type, char *file, int line, const char *func, char *fmt, ...) {
va_list ap;
- int col = (code >= 0 ? 160 : 166);
+ int col = (code != CODE_WARN ? 160 : 166);
fprintf(stderr, STANDOUT ">>>" NORMAL " At %s:%d in %s\n"
STANDOUT ">>>" NORMAL " %s: ", col, file, line, func, col, type);
@@ -25,11 +25,9 @@ _err(int code, char *type, char *file, int line, const char *func, char *fmt, ..
#ifdef DEBUG
raise(SIGTRAP);
#else
- if (code >= 1024)
- raise(code - RAISE);
+ if (code == CODE_ASSERT)
+ raise(SIGABRT);
if (code >= 0)
exit(code);
#endif /* DEBUG */
}
-
-
diff --git a/src/main.h b/src/main.h
@@ -32,9 +32,12 @@ extern int quit;
extern int view_before_smenu;
/* err.c */
+#define CODE_WARN -1
+#define CODE_ASSERT -2
#define ERR(code, type, fmt, ...) _err(code, type, __FILE__, __LINE__, __func__, fmt, ##__VA_ARGS__)
#define error(code, fmt, ...) ERR(code, "error", fmt, ##__VA_ARGS__)
-#define warning(fmt, ...) ERR(-1, "warning", fmt, ##__VA_ARGS__)
+#define warning(fmt, ...) ERR(CODE_WARN, "warning", fmt, ##__VA_ARGS__)
+#define assert(x) ((void)((x) || (ERR(CODE_ASSERT, "assertion failed", "%s\n", #x),0)))
void _err(int code, char *type, char *file, int line, const char *func, char *fmt, ...);
/* mem.c */