39#ifndef SDL_ASSERT_LEVEL
40#ifdef SDL_DEFAULT_ASSERT_LEVEL
41#define SDL_ASSERT_LEVEL SDL_DEFAULT_ASSERT_LEVEL
42#elif defined(_DEBUG) || defined(DEBUG) || \
43 (defined(__GNUC__) && !defined(__OPTIMIZE__))
44#define SDL_ASSERT_LEVEL 2
46#define SDL_ASSERT_LEVEL 1
50#ifdef SDL_WIKI_DOCUMENTATION_SECTION
71#define SDL_TriggerBreakpoint() TriggerABreakpointInAPlatformSpecificManner
73#elif defined(_MSC_VER)
75 extern void __cdecl __debugbreak(
void);
76 #define SDL_TriggerBreakpoint() __debugbreak()
79 #define SDL_TriggerBreakpoint() assert(0)
80#elif SDL_HAS_BUILTIN(__builtin_debugtrap)
81 #define SDL_TriggerBreakpoint() __builtin_debugtrap()
82#elif (defined(__GNUC__) || defined(__clang__)) && (defined(__i386__) || defined(__x86_64__))
83 #define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "int $3\n\t" )
84#elif (defined(__GNUC__) || defined(__clang__)) && defined(__riscv)
85 #define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "ebreak\n\t" )
86#elif ( defined(SDL_PLATFORM_APPLE) && (defined(__arm64__) || defined(__aarch64__)) )
87 #define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "brk #22\n\t" )
88#elif defined(SDL_PLATFORM_APPLE) && defined(__arm__)
89 #define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "bkpt #22\n\t" )
90#elif defined(__386__) && defined(__WATCOMC__)
91 #define SDL_TriggerBreakpoint() { _asm { int 0x03 } }
92#elif defined(HAVE_SIGNAL_H) && !defined(__WATCOMC__)
94 #define SDL_TriggerBreakpoint() raise(SIGTRAP)
97 #define SDL_TriggerBreakpoint()
100#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
101# define SDL_FUNCTION __func__
102#elif ((defined(__GNUC__) && (__GNUC__ >= 2)) || defined(_MSC_VER) || defined (__WATCOMC__))
103# define SDL_FUNCTION __FUNCTION__
105# define SDL_FUNCTION "???"
107#define SDL_FILE __FILE__
108#define SDL_LINE __LINE__
128#define SDL_NULL_WHILE_LOOP_CONDITION (0,0)
130#define SDL_NULL_WHILE_LOOP_CONDITION (0)
133#define SDL_disabled_assert(condition) \
134 do { (void) sizeof ((condition)); } while (SDL_NULL_WHILE_LOOP_CONDITION)
193 const char *file,
int line)
195#if __has_feature(attribute_analyzer_noreturn)
196 __attribute__((analyzer_noreturn))
206#ifndef SDL_AssertBreakpoint
207#if defined(ANDROID) && defined(assert)
209#define SDL_AssertBreakpoint()
211#define SDL_AssertBreakpoint() SDL_TriggerBreakpoint()
222#define SDL_enabled_assert(condition) \
224 while ( !(condition) ) { \
225 static struct SDL_AssertData sdl_assert_data = { 0, 0, #condition, 0, 0, 0, 0 }; \
226 const SDL_AssertState sdl_assert_state = SDL_ReportAssertion(&sdl_assert_data, SDL_FUNCTION, SDL_FILE, SDL_LINE); \
227 if (sdl_assert_state == SDL_ASSERTION_RETRY) { \
229 } else if (sdl_assert_state == SDL_ASSERTION_BREAK) { \
230 SDL_AssertBreakpoint(); \
234 } while (SDL_NULL_WHILE_LOOP_CONDITION)
237#ifdef SDL_WIKI_DOCUMENTATION_SECTION
270#define SDL_assert(condition) if (assertion_enabled && (condition)) { trigger_assertion; }
303#define SDL_assert_release(condition) SDL_disabled_assert(condition)
333#define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
336#if SDL_ASSERT_LEVEL == 0
337# define SDL_assert(condition) SDL_disabled_assert(condition)
338# define SDL_assert_release(condition) SDL_disabled_assert(condition)
339# define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
340#elif SDL_ASSERT_LEVEL == 1
341# define SDL_assert(condition) SDL_disabled_assert(condition)
342# define SDL_assert_release(condition) SDL_enabled_assert(condition)
343# define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
344#elif SDL_ASSERT_LEVEL == 2
345# define SDL_assert(condition) SDL_enabled_assert(condition)
346# define SDL_assert_release(condition) SDL_enabled_assert(condition)
347# define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
348#elif SDL_ASSERT_LEVEL == 3
349# define SDL_assert(condition) SDL_enabled_assert(condition)
350# define SDL_assert_release(condition) SDL_enabled_assert(condition)
351# define SDL_assert_paranoid(condition) SDL_enabled_assert(condition)
353# error Unknown assertion level.
378#define SDL_assert_always(condition) SDL_enabled_assert(condition)
@ SDL_ASSERTION_ALWAYS_IGNORE
SDL_AssertState SDL_ReportAssertion(SDL_AssertData *data, const char *func, const char *file, int line)
SDL_AssertState(* SDL_AssertionHandler)(const SDL_AssertData *data, void *userdata)
const SDL_AssertData * SDL_GetAssertionReport(void)
void SDL_ResetAssertionReport(void)
void SDL_SetAssertionHandler(SDL_AssertionHandler handler, void *userdata)
SDL_AssertionHandler SDL_GetDefaultAssertionHandler(void)
SDL_AssertionHandler SDL_GetAssertionHandler(void **puserdata)
const struct SDL_AssertData * next
unsigned int trigger_count