summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-04-25 19:37:39 +0000
committerNick Mathewson <nickm@torproject.org>2004-04-25 19:37:39 +0000
commite062ca046ba15d782093ad88312810ee62df272e (patch)
tree4d6d38e27e5009603c066528729c7ea03d87fd98
parent70bbd0cafabeae9854ba15158f5cc6635b2c0291 (diff)
downloadtor-e062ca046ba15d782093ad88312810ee62df272e.tar.gz
tor-e062ca046ba15d782093ad88312810ee62df272e.zip
Add a tor_assert macro that logs failed assertions.
svn:r1695
-rw-r--r--src/common/util.h12
1 files changed, 12 insertions, 0 deletions
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.-_/"