FreeRDP
assert.h
1 
21 #ifndef WINPR_ASSERT_H
22 #define WINPR_ASSERT_H
23 
24 #include <stdlib.h>
25 #include <assert.h>
26 
27 #include <winpr/winpr.h>
28 #include <winpr/wtypes.h>
29 #include <winpr/wlog.h>
30 #include <winpr/debug.h>
31 
32 #if defined(WITH_VERBOSE_WINPR_ASSERT) && (WITH_VERBOSE_WINPR_ASSERT != 0)
33 #define winpr_internal_assert(cond, file, fkt, line) \
34  do \
35  { \
36  if (!(cond)) \
37  winpr_int_assert(#cond, (file), (fkt), (line)); \
38  } while (0)
39 
40 #ifdef __cplusplus
41 extern "C"
42 {
43 #endif
44 
45  static INLINE WINPR_NORETURN(void winpr_int_assert(const char* condstr, const char* file,
46  const char* fkt, size_t line))
47  {
48  wLog* _log_cached_ptr = WLog_Get("com.freerdp.winpr.assert");
49  WLog_Print(_log_cached_ptr, WLOG_FATAL, "%s [%s:%s:%" PRIuz "]", condstr, file, fkt, line);
50  winpr_log_backtrace_ex(_log_cached_ptr, WLOG_FATAL, 20);
51  abort();
52  }
53 
54 #ifdef __cplusplus
55 }
56 #endif
57 
58 #else
59 #define winpr_internal_assert(cond, file, fkt, line) assert(cond)
60 #endif
61 
62 #define WINPR_ASSERT_AT(cond, file, fkt, line) \
63  do \
64  { \
65  WINPR_PRAGMA_DIAG_PUSH \
66  WINPR_PRAGMA_DIAG_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE \
67  WINPR_PRAGMA_DIAG_TAUTOLOGICAL_VALUE_RANGE_COMPARE \
68  WINPR_PRAGMA_DIAG_IGNORED_UNKNOWN_PRAGMAS \
69  WINPR_DO_COVERITY_PRAGMA(coverity compliance block \(deviate "CONSTANT_EXPRESSION_RESULT" \
70  "WINPR_ASSERT" \) \
71  \(deviate "NO_EFFECT" \
72  "WINPR_ASSERT" \)) \
73  \
74  winpr_internal_assert((cond), (file), (fkt), (line)); \
75  \
76  WINPR_DO_COVERITY_PRAGMA(coverity compliance end_block "CONSTANT_EXPRESSION_RESULT" \
77  "NO_EFFECT") \
78  WINPR_PRAGMA_DIAG_POP \
79  } while (0)
80 #define WINPR_ASSERT(cond) WINPR_ASSERT_AT((cond), __FILE__, __func__, __LINE__)
81 
82 #ifdef __cplusplus
83 extern "C"
84 {
85 #endif
86 #if defined(__cplusplus) && (__cplusplus >= 201703L) // C++ 17
87 #define WINPR_STATIC_ASSERT(cond) static_assert(cond)
88 #elif defined(__cplusplus) && (__cplusplus >= 201103L) // C++ 11
89 #define WINPR_STATIC_ASSERT(cond) static_assert(cond, #cond)
90 #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L) // C23
91 #define WINPR_STATIC_ASSERT(cond) static_assert(cond)
92 #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) // C11
93 #define WINPR_STATIC_ASSERT(cond) _Static_assert(cond, #cond)
94 #else
95 WINPR_PRAGMA_WARNING("static-assert macro not supported on this platform")
96 #define WINPR_STATIC_ASSERT(cond) assert(cond)
97 #endif
98 
99 #ifdef __cplusplus
100 }
101 #endif
102 
103 #endif /* WINPR_ERROR_H */