[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Add a tor_assert macro that logs failed assertions.



Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv4687/src/common

Modified Files:
	util.h 
Log Message:
Add a tor_assert macro that logs failed assertions.

Index: util.h
===================================================================
RCS file: /home/or/cvsroot/src/common/util.h,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -d -r1.55 -r1.56
--- util.h	7 Apr 2004 21:36:03 -0000	1.55
+++ util.h	25 Apr 2004 19:37:39 -0000	1.56
@@ -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.-_/"