[PATCH 1/4] include: add BUG_RETURN_* macros

Alan Coopersmith alan.coopersmith at oracle.com
Tue May 15 10:50:15 PDT 2012


On 05/15/12 03:26 AM, Peter Hutterer wrote:
> Helper functions to avoid things like
> 
> if (foo) {
>     BUG_WARN(foo);
>     return 1;
> }
> 
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---
>  include/misc.h |   12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/include/misc.h b/include/misc.h
> index 41c1333..fea74b8 100644
> --- a/include/misc.h
> +++ b/include/misc.h
> @@ -381,4 +381,16 @@ extern _X_EXPORT unsigned long serverGeneration;
>  
>  #define BUG_WARN(cond)  __BUG_WARN_MSG(cond, 0, NULL)
>  
> +#define BUG_RETURN(cond) \
> +        do { if (cond) { __BUG_WARN_MSG(cond, 0, NULL); return; } } while(0)
> +
> +#define BUG_RETURN_MSG(cond, ...) \
> +        do { if (cond) { __BUG_WARN_MSG(cond, 1, __VA_ARGS__); return; } } while(0)
> +
> +#define BUG_RETURN_VAL(cond, val) \
> +        do { if (cond) { __BUG_WARN_MSG(cond, 0, NULL); return (val); } } while(0)
> +
> +#define BUG_RETURN_VAL_MSG(cond, val, ...) \
> +        do { if (cond) { __BUG_WARN_MSG(cond, 1, __VA_ARGS__); return (val); } } while(0)
> +
>  #endif                          /* MISC_H */

Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>

-- 
	-Alan Coopersmith-              alan.coopersmith at oracle.com
	 Oracle Solaris Engineering - http://blogs.oracle.com/alanc


More information about the xorg-devel mailing list