Benny Prijono | 0a749f1 | 2005-10-31 21:02:30 +0000 | [diff] [blame^] | 1 | /* $Header: /pjproject-0.3/pjlib/include/pj/assert.h 4 10/14/05 12:25a Bennylp $ */
|
| 2 | #ifndef __PJ_ASSERT_H__
|
| 3 | #define __PJ_ASSERT_H__
|
| 4 |
|
| 5 | /**
|
| 6 | * @file assert.h
|
| 7 | * @brief Assertion macro pj_assert().
|
| 8 | */
|
| 9 |
|
| 10 | #include <pj/config.h>
|
| 11 | #include <pj/compat/assert.h>
|
| 12 |
|
| 13 | /**
|
| 14 | * @defgroup pj_assert Assertion Macro
|
| 15 | * @ingroup PJ_MISC
|
| 16 | * @{
|
| 17 | *
|
| 18 | * Assertion and other helper macros for sanity checking.
|
| 19 | */
|
| 20 |
|
| 21 | /**
|
| 22 | * @hideinitializer
|
| 23 | * Check during debug build that an expression is true. If the expression
|
| 24 | * computes to false during run-time, then the program will stop at the
|
| 25 | * offending statements.
|
| 26 | * For release build, this macro will not do anything.
|
| 27 | *
|
| 28 | * @param expr The expression to be evaluated.
|
| 29 | */
|
| 30 | #define pj_assert(expr) assert(expr)
|
| 31 |
|
| 32 |
|
| 33 | /**
|
| 34 | * @hideinitializer
|
| 35 | * If #PJ_ENABLE_EXTRA_CHECK is declared and non-zero, then
|
| 36 | * #PJ_ASSERT_RETURN macro will evaluate the expression in @a expr during
|
| 37 | * run-time. If the expression yields false, assertion will be triggered
|
| 38 | * and the current function will return with the specified return value.
|
| 39 | *
|
| 40 | * If #PJ_ENABLE_EXTRA_CHECK is not declared or is zero, then no run-time
|
| 41 | * checking will be performed. The macro simply evaluates to pj_assert(expr).
|
| 42 | */
|
| 43 | #if defined(PJ_ENABLE_EXTRA_CHECK) && PJ_ENABLE_EXTRA_CHECK != 0
|
| 44 | # define PJ_ASSERT_RETURN(expr,retval) \
|
| 45 | do { \
|
| 46 | pj_assert(expr); \
|
| 47 | if (!(expr)) return retval; \
|
| 48 | } while (0)
|
| 49 | #else
|
| 50 | # define PJ_ASSERT_RETURN(expr,retval) pj_assert(expr)
|
| 51 | #endif
|
| 52 |
|
| 53 | /** @} */
|
| 54 |
|
| 55 | #endif /* __PJ_ASSERT_H__ */
|
| 56 |
|