]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add a tor_assert macro that logs failed assertions.
authorNick Mathewson <nickm@torproject.org>
Sun, 25 Apr 2004 19:37:39 +0000 (19:37 +0000)
committerNick Mathewson <nickm@torproject.org>
Sun, 25 Apr 2004 19:37:39 +0000 (19:37 +0000)
svn:r1695

src/common/util.h

index 73627f714fd846c82ff71443c71eb6cfcc3777e8..b0120e7d3700e7295b4bda4f31ab6082dd8b915f 100644 (file)
 #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.-_/"