00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00050 #ifndef _fast_assert_h_
00051 #define _fast_assert_h_
00052
00053 typedef struct assertion_data {
00054 const char *file, *expr;
00055 unsigned line;
00056 } assertion_data;
00057
00058 void G_GNUC_NORETURN NON_NULL_PARAM((1)) REGPARM(1)
00059 assertion_failure(const assertion_data * const data);
00060
00061 void NON_NULL_PARAM((1)) REGPARM(1)
00062 assertion_warning(const assertion_data * const data);
00063
00064 #define RUNTIME_ASSERT(expr) fast_assert(expr, #expr)
00065 #define RUNTIME_UNREACHABLE() fast_assert_not_reached()
00066
00067 #define fast_assert(expr, expr_string) \
00068 G_STMT_START { \
00069 if (G_UNLIKELY(!(expr))) { \
00070 static const struct assertion_data assertion_data_ = { \
00071 __FILE__, expr_string, __LINE__ \
00072 }; \
00073 assertion_failure(&assertion_data_); \
00074 } \
00075 } G_STMT_END
00076
00077 #define fast_assert_not_reached() \
00078 G_STMT_START { \
00079 static const struct assertion_data assertion_data_ = { \
00080 __FILE__, NULL, __LINE__ \
00081 }; \
00082 assertion_failure(&assertion_data_); \
00083 } G_STMT_END
00084
00085 #define return_unless(expr) return_unless_intern((expr), #expr)
00086
00087 #define return_unless_intern(expr, expr_string) \
00088 G_STMT_START { \
00089 if (G_UNLIKELY(!(expr))) { \
00090 static const struct assertion_data assertion_data_ = { \
00091 __FILE__, expr_string, __LINE__ \
00092 }; \
00093 assertion_warning(&assertion_data_); \
00094 return; \
00095 } \
00096 } G_STMT_END
00097
00098 #define return_value_unless(expr, val) \
00099 return_value_unless_intern((expr), #expr, val)
00100
00101 #define return_value_unless_intern(expr, expr_string, val) \
00102 G_STMT_START { \
00103 if (G_UNLIKELY(!(expr))) { \
00104 static const struct assertion_data assertion_data_ = { \
00105 __FILE__, expr_string, __LINE__ \
00106 }; \
00107 assertion_warning(&assertion_data_); \
00108 return (val); \
00109 } \
00110 } G_STMT_END
00111
00112 #ifdef FAST_ASSERTIONS
00113
00114 #undef g_assert
00115 #define g_assert(expr) fast_assert((expr), #expr)
00116
00117 #undef g_assert_not_reached
00118 #define g_assert_not_reached() fast_assert_not_reached()
00119
00120 #undef g_return_if_fail
00121 #define g_return_if_fail(expr) return_unless_intern((expr), #expr)
00122
00123 #undef g_return_val_if_fail
00124 #define g_return_val_if_fail(expr, val) \
00125 return_value_unless_intern((expr), #expr, (val))
00126
00127 #endif
00128
00129 #endif
00130