00001
00002
00003
00004
00005
00006
00007 #ifndef __WVASSERT_H
00008 #define __WVASSERT_H
00009
00010 #include <assert.h>
00011
00012 #include "wvcrash.h"
00013 #include "wvstring.h"
00014
00015
00016
00017
00018
00019
00020
00021
00022 class WvCrashWill
00023 {
00024 public:
00025
00026 WvCrashWill(const char *will);
00027 WvCrashWill(WVSTRING_FORMAT_DECL);
00028
00029
00030 ~WvCrashWill();
00031
00032
00033 void rewrite(const char *will);
00034 void rewrite(WVSTRING_FORMAT_DECL);
00035 private:
00036 WvString old_will;
00037 };
00038
00039 #ifdef NDEBUG
00040
00041 # define wvassert(expr) (__ASSERT_VOID_CAST (0))
00042 # define wvassert_perror(errnum) (__ASSERT_VOID_CAST (0))
00043
00044 #else // Not NDEBUG
00045
00046 static inline void __wvcrash_leave_will()
00047 {
00048 }
00049
00050 static inline void __wvcrash_leave_will(const char *will)
00051 {
00052 wvcrash_leave_will(will);
00053 }
00054
00055 static inline void __wvcrash_leave_will(WVSTRING_FORMAT_DECL)
00056 {
00057 wvcrash_leave_will(WvFastString(WVSTRING_FORMAT_CALL));
00058 }
00059
00060
00061
00062
00063
00064 # define wvassert(expr, args...) \
00065 (__ASSERT_VOID_CAST ((expr) ? 0 : \
00066 (__wvcrash_leave_will (args), \
00067 (__assert_fail (__STRING(expr), __FILE__, __LINE__, \
00068 __ASSERT_FUNCTION), 0))))
00069
00070
00071
00072
00073
00074 # define wvassert_perror(errnum, args...) \
00075 (__ASSERT_VOID_CAST (!(errnum) ? 0 : \
00076 (__wvcrash_leave_will (args), \
00077 (__assert_perror_fail ((errnum), __FILE__, __LINE__, \
00078 __ASSERT_FUNCTION), 0))))
00079
00080 #endif // NDEBUG
00081
00082 #endif // WVASSERT_H