Make expect and check use unlikely

This commit is contained in:
apio 2022-12-05 13:35:33 +01:00
parent ea7893ba71
commit 7cc139c3f7
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -8,6 +8,18 @@ extern _noreturn bool __check_failed(const char* file, const char* line, const c
#define STRINGIZE_VALUE_OF(x) STRINGIZE(x)
#endif
#define check(expr) (expr) || __check_failed(__FILE__, STRINGIZE_VALUE_OF(__LINE__), __PRETTY_FUNCTION__, #expr)
#define expect(expr, message) \
(expr) || __check_failed(__FILE__, STRINGIZE_VALUE_OF(__LINE__), __PRETTY_FUNCTION__, message)
do { \
if (!(expr)) [[unlikely]] \
{ \
__check_failed(__FILE__, STRINGIZE_VALUE_OF(__LINE__), __PRETTY_FUNCTION__, message); \
} \
} while (0)
#define check(expr) \
do { \
if (!(expr)) [[unlikely]] \
{ \
__check_failed(__FILE__, STRINGIZE_VALUE_OF(__LINE__), __PRETTY_FUNCTION__, #expr); \
} \
} while (0)