Galago - desktop presence framework

galago-assert.h

Go to the documentation of this file.
00001 
00021 #ifndef _GALAGO_ASSERT_H_
00022 #define _GALAGO_ASSERT_H_
00023 
00024 #include <libgalago/galago-log.h>
00025 
00026 #ifdef __cplusplus
00027 extern "C" {
00028 #endif
00029 
00030 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
00031 # define GALAGO_BOOLEAN_EXPR(expr) \
00032     __extension__ ({ \
00033         (expr ? 1 : 0); \
00034     })
00035 
00036 # define GALAGO_LIKELY(expr) (__builtin_expect (GALAGO_BOOLEAN_EXPR(expr), 1))
00037 # define GALAGO_UNLIKELY(expr) (__builtin_expect (GALAGO_BOOLEAN_EXPR(expr), 0))
00038 #else
00039 # define GALAGO_LIKELY(expr) (expr)
00040 # define GALAGO_UNLIKELY(expr) (expr)
00041 #endif
00042 
00043 #ifdef __GNUC__
00044 # define galago_return_if_fail(cond) \
00045     if (GALAGO_UNLIKELY(!(cond))) \
00046     { \
00047         galago_log(GALAGO_LOG_ASSERT, \
00048                    "file %s: line %d (%s): assertion `%s' failed\n", \
00049                    __FILE__, \
00050                    __LINE__, \
00051                    __PRETTY_FUNCTION__, \
00052                    #cond); \
00053         return; \
00054     }
00055 
00056 # define galago_return_val_if_fail(cond, value) \
00057     if (GALAGO_UNLIKELY(!(cond))) \
00058     { \
00059         galago_log(GALAGO_LOG_ASSERT, \
00060                    "file %s: line %d (%s): assertion `%s' failed\n", \
00061                    __FILE__, \
00062                    __LINE__, \
00063                    __PRETTY_FUNCTION__, \
00064                    #cond); \
00065         return (value); \
00066     }
00067 
00068 # define galago_goto_if_fail(cond, label) \
00069     if (GALAGO_UNLIKELY(!(cond))) \
00070     { \
00071         galago_log(GALAGO_LOG_ASSERT, \
00072                    "file %s: line %d (%s): assertion `%s' failed\n", \
00073                    __FILE__, \
00074                    __LINE__, \
00075                    __PRETTY_FUNCTION__, \
00076                    #cond); \
00077         goto label; \
00078     }
00079 
00080 #else /* !__GNUC__ */
00081 
00082 # define galago_return_if_fail(cond) \
00083     if (GALAGO_UNLIKELY(!(cond))) \
00084     { \
00085         galago_log(GALAGO_LOG_ASSERT, \
00086                    "file %s: line %d: assertion `%s' failed\n", \
00087                    __FILE__, \
00088                    __LINE__, \
00089                    #cond); \
00090         return; \
00091     }
00092 
00093 # define galago_return_val_if_fail(cond, value) \
00094     if (GALAGO_UNLIKELY(!(cond))) \
00095     { \
00096         galago_log(GALAGO_LOG_ASSERT, \
00097                    "file %s: line %d: assertion `%s' failed\n", \
00098                    __FILE__, \
00099                    __LINE__, \
00100                    #cond); \
00101         return (value); \
00102     }
00103 
00104 # define galago_return_if_fail(cond, label) \
00105     if (GALAGO_UNLIKELY(!(cond))) \
00106     { \
00107         galago_log(GALAGO_LOG_ASSERT, \
00108                    "file %s: line %d: assertion `%s' failed\n", \
00109                    __FILE__, \
00110                    __LINE__, \
00111                    #cond); \
00112         goto label; \
00113     }
00114 
00115 #endif /* !__GNUC__ */
00116 
00117 #ifdef __cplusplus
00118 }
00119 #endif
00120 
00121 #endif /* _GALAGO_ASSERT_H_ */