From: Jay Freeman (saurik) Date: Mon, 28 Sep 2015 01:53:45 +0000 (-0700) Subject: Allow more useful error messages in _assert macro. X-Git-Tag: v2.1.0~86 X-Git-Url: https://git.cameronkatri.com/ldid.git/commitdiff_plain/eff987d296c6ad358f4c848f29a1891b3a25f345 Allow more useful error messages in _assert macro. --- diff --git a/ldid.cpp b/ldid.cpp index 0cb8dd2..8c03ef6 100644 --- a/ldid.cpp +++ b/ldid.cpp @@ -51,15 +51,16 @@ #line #define _assert__(line) \ _assert___(line) -#define _assert_(e) \ - throw __FILE__ "(" _assert__(__LINE__) "): _assert(" e ")" -#define _assert(expr) \ +#define _assert_(expr, format, ...) \ do if (!(expr)) { \ - fprintf(stderr, "%s(%u): _assert(%s); errno=%u\n", __FILE__, __LINE__, #expr, errno); \ - _assert_(#expr); \ + fprintf(stderr, "%s(%u): _assert(): " format "\n", __FILE__, __LINE__, ## __VA_ARGS__); \ + throw __FILE__ "(" _assert__(__LINE__) "): _assert(" #expr ")"; \ } while (false) +#define _assert(expr) \ + _assert_(expr, "%s", #expr) + #define _syscall(expr) ({ \ __typeof__(expr) _value; \ do if ((long) (_value = (expr)) != -1) \ @@ -68,7 +69,7 @@ case EINTR: \ continue; \ default: \ - _assert(false); \ + _assert_(false, "errno=%u", errno); \ } while (true); \ _value; \ })