include: move BUG_*() macros to separate header

Yet another step of uncluttering includes: move out the BUG_* macros
into a separate header, which then is included as-needed.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt
2024-02-15 23:33:46 +00:00
committed by Peter Hutterer
parent a8bb924af1
commit 442aec2219
22 changed files with 60 additions and 27 deletions

33
include/bug.h Normal file
View File

@@ -0,0 +1,33 @@
#ifndef _XSERVER_OS_BUG_H
#define _XSERVER_OS_BUG_H
#include "os.h"
/* Don't use this directly, use BUG_WARN or BUG_WARN_MSG instead */
#define __BUG_WARN_MSG(cond, with_msg, ...) \
do { if (cond) { \
ErrorFSigSafe("BUG: triggered 'if (" #cond ")'\n"); \
ErrorFSigSafe("BUG: %s:%u in %s()\n", \
__FILE__, __LINE__, __func__); \
if (with_msg) ErrorFSigSafe(__VA_ARGS__); \
xorg_backtrace(); \
} } while(0)
#define BUG_WARN_MSG(cond, ...) \
__BUG_WARN_MSG(cond, 1, __VA_ARGS__)
#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 /* _XSERVER_OS_BUG_H */

View File

@@ -416,31 +416,4 @@ typedef struct _CharInfo *CharInfoPtr; /* also in fonts/include/font.h */
extern _X_EXPORT unsigned long globalSerialNumber;
extern _X_EXPORT unsigned long serverGeneration;
/* Don't use this directly, use BUG_WARN or BUG_WARN_MSG instead */
#define __BUG_WARN_MSG(cond, with_msg, ...) \
do { if (cond) { \
ErrorFSigSafe("BUG: triggered 'if (" #cond ")'\n"); \
ErrorFSigSafe("BUG: %s:%u in %s()\n", \
__FILE__, __LINE__, __func__); \
if (with_msg) ErrorFSigSafe(__VA_ARGS__); \
xorg_backtrace(); \
} } while(0)
#define BUG_WARN_MSG(cond, ...) \
__BUG_WARN_MSG(cond, 1, __VA_ARGS__)
#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 */