1 /* emacs edit mode for this file is -*- C -*- */ 2 3 /** 4 * @file cf_assert.h 5 * 6 * assertions for Factory 7 * 8 * @note needs --enable-assertions at configure 9 **/ 10 11 /* This is for compatibility with standard cf_assert.h */ 12 #if defined (SING_NDEBUG) && ! defined (NOASSERT) 13 #define NOASSERT 14 #endif 15 16 /* It should be possible to include this file multiple times for different */ 17 /* settings of NOASSERT */ 18 19 /* {{{ undefines */ 20 #undef __ASSERT 21 #undef __ASSERT1 22 #undef STICKYASSERT 23 #undef STICKYASSERT1 24 #undef ASSERT 25 #undef ASSERT1 26 27 #undef __WARN 28 #undef STICKYWARN 29 #undef WARN 30 31 #undef PVIRT_VOID 32 #undef PVIRT_INTCF 33 #undef PVIRT_BOOL 34 #undef PVIRT_INT 35 #undef PVIRT_CHARCC 36 /* }}} */ 37 38 #ifdef __cplusplus 39 #ifndef NOSTREAMIO 40 #ifdef HAVE_CSTDIO 41 #include <cstdio> 42 #include <cstdlib> 43 #else 44 extern "C" { 45 #include <stdio.h> 46 #include <stdlib.h> 47 } 48 #endif 49 #else 50 #include <stdio.h> 51 #include <stdlib.h> 52 #endif 53 #endif 54 55 /* {{{ permanent macro definitions */ 56 #ifndef __GNUC__ 57 #define __ASSERT(expression, message, file, line) \ 58 (fprintf( stderr, "error: " message "\n%s:%u: failed assertion `%s'\n", \ 59 file, line, expression ), abort(), 0 ) 60 #define __ASSERT1(expression, message, parameter1, file, line) \ 61 (fprintf( stderr, "error: " message "\n%s:%u: failed assertion `%s'\n", \ 62 parameter1, file, line, expression ), abort(), 0 ) 63 64 #define STICKYASSERT(expression, message) \ 65 ((void)((expression) ? 0 : __ASSERT(#expression, message, __FILE__, __LINE__))) 66 #define STICKYASSERT1(expression, message, parameter1) \ 67 ((void)((expression) ? 0 : __ASSERT1(#expression, message, parameter1, __FILE__, __LINE__))) 68 69 #define __WARN(expression, message, file, line) \ 70 (fprintf( stderr, "warning: " message "\n%s:%u: failed assertion `%s'\n", \ 71 file, line, expression ), 0 ) 72 #define STICKYWARN(expression, message) \ 73 ((void)((expression) ? 0 : __WARN(#expression, message, __FILE__, __LINE__))) 74 #else /* __GNUCC__ */ 75 /* use preprocessor macro __PRETTY_FUNCTION__ for more informative output */ 76 #define __ASSERT(expression, message, file, line, function) \ 77 (fprintf( stderr, "error: " message "\n%s:%u: In function `%s':\nfailed assertion `%s'\n", \ 78 file, line, function, expression ), abort(), 0 ) 79 #define __ASSERT1(expression, message, parameter1, file, line, function) \ 80 (fprintf( stderr, "error: " message "\n%s:%u: In function `%s':\nfailed assertion `%s'\n", \ 81 parameter1, file, line, function, expression ), abort(), 0 ) 82 83 #define STICKYASSERT(expression, message) \ 84 ((void)((expression) ? 0 : __ASSERT(#expression, message, __FILE__, __LINE__, __PRETTY_FUNCTION__))) 85 #define STICKYASSERT1(expression, message, parameter1) \ 86 ((void)((expression) ? 0 : __ASSERT1(#expression, message, parameter1, __FILE__, __LINE__, __PRETTY_FUNCTION__))) 87 88 #define __WARN(expression, message, file, line, function) \ 89 (fprintf( stderr, "warning: " message "\n%s:%u: In function `%s':\nfailed assertion `%s'\n", \ 90 file, line, function, expression ), 0 ) 91 #define STICKYWARN(expression, message) \ 92 ((void)((expression) ? 0 : __WARN(#expression, message, __FILE__, __LINE__, __PRETTY_FUNCTION__))) 93 #endif /* __GNUCC__ */ 94 /* }}} */ 95 96 /* {{{ macro definitions dependent on NOASSERT */ 97 #ifndef NOASSERT 98 #ifndef __GNUC__ 99 #define ASSERT(expression, message) \ 100 ((void)((expression) ? 0 : __ASSERT(#expression, message, __FILE__, __LINE__))) 101 #define ASSERT1(expression, message, parameter1) \ 102 ((void)((expression) ? 0 : __ASSERT1(#expression, message, parameter1, __FILE__, __LINE__))) 103 104 #define WARN(expression, message) \ 105 ((void)((expression) ? 0 : __WARN(#expression, message, __FILE__, __LINE__))) 106 #else /* __GNUCC__ */ 107 /* use preprocessor macro __PRETTY_FUNCTION__ for more informative output */ 108 #define ASSERT(expression, message) \ 109 ((void)((expression) ? 0 : __ASSERT(#expression, message, __FILE__, __LINE__, __PRETTY_FUNCTION__))) 110 #define ASSERT1(expression, message, parameter1) \ 111 ((void)((expression) ? 0 : __ASSERT1(#expression, message, parameter1, __FILE__, __LINE__, __PRETTY_FUNCTION__))) 112 113 #define WARN(expression, message) \ 114 ((void)((expression) ? 0 : __WARN(#expression, message, __FILE__, __LINE__, __PRETTY_FUNCTION__))) 115 #endif /* __GNUCC__ */ 116 117 #define PVIRT_VOID(msg) \ 118 { fprintf( stderr, "pure method( " msg " ) called\n" ); abort(); } 119 #define PVIRT_INTCF(msg) \ 120 { fprintf( stderr, "pure method( " msg " ) called\n" ); abort(); return 0; } 121 #define PVIRT_BOOL(msg) \ 122 { fprintf( stderr, "pure method( " msg " ) called\n" ); abort(); return false; } 123 #define PVIRT_INT(msg) \ 124 { fprintf( stderr, "pure method( " msg " ) called\n" ); abort(); return 0; } 125 #define PVIRT_CHARCC(msg) \ 126 { fprintf( stderr, "pure method( " msg " ) called\n" ); abort(); return 0; } 127 #else /* NOASSERT */ 128 #define ASSERT(expression, message) do {} while (0) 129 #define ASSERT1(expression, message, parameter1) do {} while (0) 130 131 #define WARN(expression, message) do {} while (0) 132 133 #define PVIRT_VOID(msg) = 0 134 #define PVIRT_INTCF(msg) = 0 135 #define PVIRT_BOOL(msg) = 0 136 #define PVIRT_INT(msg) = 0 137 #define PVIRT_CHARCC(msg) = 0 138 #endif /* NOASSERT */ 139 /* }}} */ 140