#ifdef G_DISABLE_CHECKS
/**
* g_return_if_fail:
* @expr: the expression to check
*
* Verifies that the expression @expr, usually representing a precondition,
* evaluates to %TRUE. If the function returns a value, use
* g_return_val_if_fail() instead.
*
* If @expr evaluates to %FALSE, the current function should be considered to
* have undefined behaviour (a programmer error). The only correct solution
* to such an error is to change the module that is calling the current
* function, so that it avoids this incorrect call.
*
* To make this undefined behaviour visible, if @expr evaluates to %FALSE,
* the result is usually that a critical message is logged and the current
* function returns.
*
* If `G_DISABLE_CHECKS` is defined then the check is not performed. You
* should therefore not depend on any side effects of @expr.
*
* To debug failure of a g_return_if_fail() check, run the code under a debugger
* with `G_DEBUG=fatal-criticals` or `G_DEBUG=fatal-warnings` defined in the
* environment (see [Running GLib Applications](glib-running.html)):
*
* |[
* G_DEBUG=fatal-warnings gdb ./my-program
* ]|
*
* Any unrelated failures can be skipped over in
* [gdb](https://www.gnu.org/software/gdb/) using the `continue` command.
*/
#define g_return_if_fail(expr) G_STMT_START{ (void)0; }G_STMT_END
/**
* g_return_val_if_fail:
* @expr: the expression to check
* @val: the value to return from the current function
* if the expression is not true
*
* Verifies that the expression @expr, usually representing a precondition,
* evaluates to %TRUE. If the function does not return a value, use
* g_return_if_fail() instead.
*
* If @expr evaluates to %FALSE, the current function should be considered to
* have undefined behaviour (a programmer error). The only correct solution
* to such an error is to change the module that is calling the current
* function, so that it avoids this incorrect call.
*
* To make this undefined behaviour visible, if @expr evaluates to %FALSE,
* the result is usually that a critical message is logged and @val is
* returned from the current function.
*
* If `G_DISABLE_CHECKS` is defined then the check is not performed. You
* should therefore not depend on any side effects of @expr.
*
* See g_return_if_fail() for guidance on how to debug failure of this check.
*/
#define g_return_val_if_fail(expr,val) G_STMT_START{ (void)0; }G_STMT_END
/**
* g_return_if_reached:
*
* Logs a critical message and returns from the current function.
* This can only be used in functions which do not return a value.
*
* See g_return_if_fail() for guidance on how to debug failure of this check.
*/
#define g_return_if_reached() G_STMT_START{ return; }G_STMT_END
/**
* g_return_val_if_reached:
* @val: the value to return from the current function
*
* Logs a critical message and returns @val.
*
* See g_return_if_fail() for guidance on how to debug failure of this check.
*/
#define g_return_val_if_reached(val) G_STMT_START{ return (val); }G_STMT_END
#else /* !G_DISABLE_CHECKS */
#define g_return_if_fail(expr) G_STMT_START{ \
if G_LIKELY(expr) { } else \
{ \
g_return_if_fail_warning (G_LOG_DOMAIN, \
G_STRFUNC, \
#expr); \
return; \
}; }G_STMT_END
#define g_return_val_if_fail(expr,val) G_STMT_START{ \
if G_LIKELY(expr) { } else \
{ \
g_return_if_fail_warning (G_LOG_DOMAIN, \
G_STRFUNC, \
#expr); \
return (val); \
}; }G_STMT_END
#define g_return_if_reached() G_STMT_START{ \
g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_CRITICAL, \
"file %s: line %d (%s): should not be reached", \
__FILE__, \
__LINE__, \
G_STRFUNC); \
return; }G_STMT_END
#define g_return_val_if_reached(val) G_STMT_START{ \
g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_CRITICAL, \
"file %s: line %d (%s): should not be reached", \
__FILE__, \
__LINE__, \
G_STRFUNC); \
return (val); }G_STMT_END
#endif /* !G_DISABLE_CHECKS */
在makefile中 --enable-debug={no,mininum,yes}可以控制此开关
--enable-debug
. Turns on various amounts of debugging support. Setting this to 'no' disables g_assert(), g_return_if_fail(), g_return_val_if_fail() and all cast checks between different object types. Setting it to 'minimum' disables only cast checks. Setting it to 'yes' enables runtime debugging. The default is 'minimum'. Note that 'no' is fast, but dangerous as it tends to destabilize even mostly bug-free software by changing the effect of many bugs from simple warnings into fatal crashes. Thus--enable-debug=no
should not be used for stable releases of GLib.