Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

fast_assert.h

Go to the documentation of this file.
00001 /*
00002  * $Id: fast_assert.h 12628 2006-12-17 04:17:40Z cbiere $
00003  *
00004  * Copyright (c) 2006, Christian Biere
00005  *
00006  *----------------------------------------------------------------------
00007  * This file is part of gtk-gnutella.
00008  *
00009  *  gtk-gnutella is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  gtk-gnutella is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with gtk-gnutella; if not, write to the Free Software
00021  *  Foundation, Inc.:
00022  *      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 /* FAST_ASSERTIONS */
00128 
00129 #endif /* _fast_assert_h_ */
00130 /* vi: set ts=4 sw=4 cindent: */

Generated on Sat Jun 30 17:53:23 2007 for gtk-gnutella by  doxygen 1.3.9.1