diff --git a/src/error.h b/src/error.h index 3bde94b..f41bb30 100644 --- a/src/error.h +++ b/src/error.h @@ -22,25 +22,41 @@ #define FUNCFAILED(f, ...) \ PRINTINTERR(INTERRMSG f "() failed" __VA_OPT__(": %s", __VA_ARGS__)) +#ifndef NO_TRACEBACK +#define ERRCHK_PRINT_(...) \ + do { \ + int __a = 0; \ + __VA_OPT__(PRINTINTERR(__VA_ARGS__); __a = 1;) \ + if (!__a) \ + PRINTINTERR(); \ + } while (0) +#endif +#ifdef NO_TRACEBACK +#define ERRCHK_PRINT_(...) \ + do { \ + __VA_OPT__(PRINTINTERR(__VA_ARGS__);) \ + } while (0) +#endif + /* * If cond is true, return ERR. Also call print_error or * print_errorf if error message or format string is given. */ -#define ERRCHK_RET(cond, ...) \ - do { \ - if (cond) { \ - __VA_OPT__(PRINTINTERR(__VA_ARGS__);) \ - return ERR; \ - } \ +#define ERRCHK_RET(cond, ...) \ + do { \ + if (cond) { \ + ERRCHK_PRINT_(__VA_ARGS__); \ + return ERR; \ + } \ } while (0) -#define ERRCHK_GOTO(cond, ret, label, ...) \ - do { \ - if (cond) { \ - __VA_OPT__(PRINTINTERR(__VA_ARGS__);) \ - ret = ERR; \ - goto label; \ - } \ +#define ERRCHK_GOTO(cond, ret, label, ...) \ + do { \ + if (cond) { \ + ERRCHK_PRINT_(__VA_ARGS__); \ + ret = ERR; \ + goto label; \ + } \ } while (0) #define ERRCHK_MSG_(x) INTERRMSG "'" x "'"