25 #include "SDL_config.h"
33 #ifndef SDL_ASSERT_LEVEL
34 #ifdef SDL_DEFAULT_ASSERT_LEVEL
35 #define SDL_ASSERT_LEVEL SDL_DEFAULT_ASSERT_LEVEL
36 #elif defined(_DEBUG) || defined(DEBUG) || \
37 (defined(__GNUC__) && !defined(__OPTIMIZE__))
38 #define SDL_ASSERT_LEVEL 2
40 #define SDL_ASSERT_LEVEL 1
52 extern void __cdecl __debugbreak(
void);
53 #define SDL_TriggerBreakpoint() __debugbreak()
54 #elif ( (!defined(__NACL__)) && ((defined(__GNUC__) || defined(__clang__)) && (defined(__i386__) || defined(__x86_64__))) )
55 #define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "int $3\n\t" )
56 #elif ( defined(__APPLE__) && defined(__arm64__) )
57 #define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "brk #22\n\t" )
58 #elif defined(__386__) && defined(__WATCOMC__)
59 #define SDL_TriggerBreakpoint() { _asm { int 0x03 } }
60 #elif defined(HAVE_SIGNAL_H) && !defined(__WATCOMC__)
62 #define SDL_TriggerBreakpoint() raise(SIGTRAP)
65 #define SDL_TriggerBreakpoint()
68 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
69 # define SDL_FUNCTION __func__
70 #elif ((__GNUC__ >= 2) || defined(_MSC_VER) || defined (__WATCOMC__))
71 # define SDL_FUNCTION __FUNCTION__
73 # define SDL_FUNCTION "???"
75 #define SDL_FILE __FILE__
76 #define SDL_LINE __LINE__
96 #define SDL_NULL_WHILE_LOOP_CONDITION (0,0)
98 #define SDL_NULL_WHILE_LOOP_CONDITION (0)
101 #define SDL_disabled_assert(condition) \
102 do { (void) sizeof ((condition)); } while (SDL_NULL_WHILE_LOOP_CONDITION)
109 SDL_ASSERTION_IGNORE,
110 SDL_ASSERTION_ALWAYS_IGNORE
116 unsigned int trigger_count;
117 const char *condition;
118 const char *filename;
120 const char *
function;
124 #if (SDL_ASSERT_LEVEL > 0)
127 extern DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(
SDL_AssertData *,
130 #if defined(__clang__)
131 #if __has_feature(attribute_analyzer_noreturn)
135 __attribute__((analyzer_noreturn))
147 #define SDL_enabled_assert(condition) \
149 while ( !(condition) ) { \
150 static struct SDL_AssertData sdl_assert_data = { \
151 0, 0, #condition, 0, 0, 0, 0 \
153 const SDL_AssertState sdl_assert_state = SDL_ReportAssertion(&sdl_assert_data, SDL_FUNCTION, SDL_FILE, SDL_LINE); \
154 if (sdl_assert_state == SDL_ASSERTION_RETRY) { \
156 } else if (sdl_assert_state == SDL_ASSERTION_BREAK) { \
157 SDL_TriggerBreakpoint(); \
161 } while (SDL_NULL_WHILE_LOOP_CONDITION)
166 #if SDL_ASSERT_LEVEL == 0
167 # define SDL_assert(condition) SDL_disabled_assert(condition)
168 # define SDL_assert_release(condition) SDL_disabled_assert(condition)
169 # define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
170 #elif SDL_ASSERT_LEVEL == 1
171 # define SDL_assert(condition) SDL_disabled_assert(condition)
172 # define SDL_assert_release(condition) SDL_enabled_assert(condition)
173 # define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
174 #elif SDL_ASSERT_LEVEL == 2
175 # define SDL_assert(condition) SDL_enabled_assert(condition)
176 # define SDL_assert_release(condition) SDL_enabled_assert(condition)
177 # define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
178 #elif SDL_ASSERT_LEVEL == 3
179 # define SDL_assert(condition) SDL_enabled_assert(condition)
180 # define SDL_assert_release(condition) SDL_enabled_assert(condition)
181 # define SDL_assert_paranoid(condition) SDL_enabled_assert(condition)
183 # error Unknown assertion level.
187 #define SDL_assert_always(condition) SDL_enabled_assert(condition)
190 typedef SDL_AssertState (SDLCALL *SDL_AssertionHandler)(
213 extern DECLSPEC
void SDLCALL SDL_SetAssertionHandler(
214 SDL_AssertionHandler handler,
227 extern DECLSPEC SDL_AssertionHandler SDLCALL SDL_GetDefaultAssertionHandler(
void);
244 extern DECLSPEC SDL_AssertionHandler SDLCALL SDL_GetAssertionHandler(
void **puserdata);
268 extern DECLSPEC
const SDL_AssertData * SDLCALL SDL_GetAssertionReport(
void);
277 extern DECLSPEC
void SDLCALL SDL_ResetAssertionReport(
void);
281 #define SDL_assert_state SDL_AssertState
282 #define SDL_assert_data SDL_AssertData
Definition: SDL_assert.h:114