From 2abe83df686ed64c4f4df711ac3c1fd12131c2e4 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 5 Dec 2011 14:02:51 +1000 Subject: [PATCH] include: add BUG_WARN_MSG for custom error message on bug condition __BUG_WARN_MSG is a simple helper to enable call with and without varargs. I couldn't find a way to otherwise do this without getting gcc warnings. Signed-off-by: Peter Hutterer Reviewed-by: Chase Douglas --- include/misc.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/misc.h b/include/misc.h index ef86fa539..d9811ca60 100644 --- a/include/misc.h +++ b/include/misc.h @@ -359,11 +359,18 @@ typedef struct _CharInfo *CharInfoPtr; /* also in fonts/include/font.h */ extern _X_EXPORT unsigned long globalSerialNumber; extern _X_EXPORT unsigned long serverGeneration; -#define BUG_WARN(cond) \ +/* Don't use this directly, use BUG_WARN or BUG_WARN_MSG instead */ +#define __BUG_WARN_MSG(cond, with_msg, ...) \ do { if (cond) { \ ErrorF("BUG: triggered 'if (" #cond ")'\nBUG: %s:%d in %s()\n", \ __FILE__, __LINE__, __func__); \ + if (with_msg) ErrorF(__VA_ARGS__); \ xorg_backtrace(); \ } } while(0) +#define BUG_WARN_MSG(cond, msg, ...) \ + __BUG_WARN_MSG(cond, 1, msg, __VA_ARGS__) + +#define BUG_WARN(cond) __BUG_WARN_MSG(cond, 0, NULL) + #endif /* MISC_H */