diff options
author | David Härdeman <david@hardeman.nu> | 2020-06-20 19:34:58 +0200 |
---|---|---|
committer | David Härdeman <david@hardeman.nu> | 2020-06-20 19:34:58 +0200 |
commit | ab51ac11e68ce0b075688bf17fc89e0ba645b2ed (patch) | |
tree | 9e029febdc64a52a33c5611a15ad86d247e19a78 /main.h | |
parent | 0721128bcce0790663e1491d8684edaf918874b6 (diff) |
Add new assert macros, convert server.c to use them
Diffstat (limited to 'main.h')
-rw-r--r-- | main.h | 55 |
1 files changed, 35 insertions, 20 deletions
@@ -46,17 +46,47 @@ void __debug(enum debug_lvl lvl, const char *fmt, ...) __attribute__((format(pri } while (0) #define debug(lvl, fmt, ...) __ifdebug((lvl), "%s:%s:%i: " fmt, \ - __func__, __FILE__, __LINE__ \ + __FILE__, __func__, __LINE__ \ __VA_OPT__(,) __VA_ARGS__) #define verbose(fmt, ...) __ifdebug(DBG_VERBOSE, fmt, __VA_ARGS__) #define info(fmt, ...) __ifdebug(DBG_INFO, fmt, __VA_ARGS__) -#define error(fmt, ...) __ifdebug(DBG_ERROR, "%s: " fmt, \ - __func__ __VA_OPT__(,) __VA_ARGS__) +#define error(fmt, ...) __ifdebug(DBG_ERROR, "%s:%s:%i: " fmt, \ + __FILE__, __func__, __LINE__ \ + __VA_OPT__(,) __VA_ARGS__) void __die(const char *fmt, ...) __attribute__((format(printf, 1, 2))); -#define die(fmt, ...) __die("%s:%i: " fmt "\n", __func__, \ - __LINE__ __VA_OPT__(,) __VA_ARGS__) +#define die(fmt, ...) \ + __die("%s:%s:%i: " fmt "\n", \ + __FILE__, __func__, __LINE__ \ + __VA_OPT__(,) __VA_ARGS__) + +#define assert_log(expr, msg) \ + ((expr) ? \ + (true) : \ + (__debug(DBG_ERROR, "%s:%s:%i: assertion \"" msg "\" failed\n", \ + __FILE__, __func__, __LINE__), false)) + +#define assert_return(expr, ...) \ + do { \ + if (!assert_log(expr, #expr)) \ + return __VA_ARGS__; \ + } while (0) + +#define assert_task_alive_or(lvl, t, cmd) \ +do { \ + if (!(t)) { \ + error("invalid task\n"); \ + cmd; \ + } \ + \ + if ((t)->dead) { \ + debug((lvl), "task dead\n"); \ + cmd; \ + } \ +} while(0) + +#define assert_task_alive(lvl, t) assert_task_alive_or((lvl), (t), return) struct uring_task; @@ -95,21 +125,6 @@ struct uring_task { void *priv; }; -#define assert_task_alive_or(lvl, t, cmd) \ -do { \ - if (!(t)) { \ - error("invalid task\n"); \ - cmd; \ - } \ - \ - if ((t)->dead) { \ - debug((lvl), "task dead\n"); \ - cmd; \ - } \ -} while(0) - -#define assert_task_alive(lvl, t) assert_task_alive_or((lvl), (t), return) - struct cfg { uid_t uid; gid_t gid; |