From: Nick Mathewson Date: Sun, 25 Apr 2004 19:37:39 +0000 (+0000) Subject: Add a tor_assert macro that logs failed assertions. X-Git-Tag: debian-version-0.0.5+0.0.6rc2-1~19 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e062ca046ba15d782093ad88312810ee62df272e;p=thirdparty%2Ftor.git Add a tor_assert macro that logs failed assertions. svn:r1695 --- diff --git a/src/common/util.h b/src/common/util.h index 73627f714f..b0120e7d37 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -40,6 +40,18 @@ #define INLINE inline #endif +#ifdef NDEBUG +#define tor_assert(expr) do {} while(0) +#else +#define tor_assert(expr) do { \ + if (!(expr)) { \ + log(LOG_ERR, "%s:%d: %s: Assertion %s failed; aborting.", \ + __FILE__, __LINE__, __FUNCTION__, #expr); \ + assert(expr); /* write to console too. */ \ + abort(); /* unreached */ \ + } } while (0) +#endif + /* legal characters in a filename */ #define CONFIG_LEGAL_FILENAME_CHARACTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_/"