2323#define SDL_assert_h_
2424
2525#include "SDL_stdinc.h"
26-
2726#include "begin_code.h"
2827/* Set up for C function definitions, even when using C++ */
2928#ifdef __cplusplus
@@ -33,8 +32,7 @@ extern "C" {
3332#ifndef SDL_ASSERT_LEVEL
3433#ifdef SDL_DEFAULT_ASSERT_LEVEL
3534#define SDL_ASSERT_LEVEL SDL_DEFAULT_ASSERT_LEVEL
36- #elif defined(_DEBUG ) || defined(DEBUG ) || \
37- (defined(__GNUC__ ) && !defined(__OPTIMIZE__ ))
35+ #elif defined(_DEBUG ) || defined(DEBUG ) || (defined(__GNUC__ ) && !defined(__OPTIMIZE__ ))
3836#define SDL_ASSERT_LEVEL 2
3937#else
4038#define SDL_ASSERT_LEVEL 1
@@ -49,37 +47,44 @@ assert can have unique static variables associated with it.
4947
5048#if defined(_MSC_VER )
5149/* Don't include intrin.h here because it contains C++ code */
52- extern void __cdecl __debugbreak (void );
53- #define SDL_TriggerBreakpoint () __debugbreak()
50+ extern void __cdecl __debugbreak (void );
51+ #define SDL_TriggerBreakpoint () __debugbreak()
5452#elif _SDL_HAS_BUILTIN (__builtin_debugtrap )
55- #define SDL_TriggerBreakpoint () __builtin_debugtrap()
56- #elif ( (!defined(__NACL__ )) && ((defined(__GNUC__ ) || defined(__clang__ )) && (defined(__i386__ ) || defined(__x86_64__ ))) )
57- #define SDL_TriggerBreakpoint () __asm__ __volatile__ ( "int $3\n\t" )
53+ #define SDL_TriggerBreakpoint () __builtin_debugtrap()
54+ #elif ((!defined(__NACL__ )) && \
55+ ((defined(__GNUC__ ) || defined(__clang__ )) && (defined(__i386__ ) || defined(__x86_64__ ))))
56+ #define SDL_TriggerBreakpoint () __asm__ __volatile__("int $3\n\t")
5857#elif (defined(__GNUC__ ) || defined(__clang__ )) && defined(__riscv )
59- #define SDL_TriggerBreakpoint () __asm__ __volatile__ ( "ebreak\n\t" )
60- #elif ( defined(__APPLE__ ) && (defined(__arm64__ ) || defined(__aarch64__ )) ) /* this might work on other ARM targets, but this is a known quantity... */
61- #define SDL_TriggerBreakpoint () __asm__ __volatile__ ( "brk #22\n\t" )
58+ #define SDL_TriggerBreakpoint () __asm__ __volatile__("ebreak\n\t")
59+ #elif (defined(__APPLE__ ) && \
60+ (defined(__arm64__ ) || defined(__aarch64__ ))) /* this might work on other ARM targets, but \
61+ this is a known quantity... */
62+ #define SDL_TriggerBreakpoint () __asm__ __volatile__("brk #22\n\t")
6263#elif defined(__APPLE__ ) && defined(__arm__ )
63- #define SDL_TriggerBreakpoint () __asm__ __volatile__ ( "bkpt #22\n\t" )
64+ #define SDL_TriggerBreakpoint () __asm__ __volatile__( "bkpt #22\n\t")
6465#elif defined(__386__ ) && defined(__WATCOMC__ )
65- #define SDL_TriggerBreakpoint () { _asm { int 0x03 } }
66+ #define SDL_TriggerBreakpoint () \
67+ { \
68+ _asm { int 0x03 } \
69+ }
6670#elif defined(HAVE_SIGNAL_H ) && !defined(__WATCOMC__ )
67- #include <signal.h>
68- #define SDL_TriggerBreakpoint () raise(SIGTRAP)
71+ #include <signal.h>
72+ #define SDL_TriggerBreakpoint () raise(SIGTRAP)
6973#else
70- /* How do we trigger breakpoints on this platform? */
71- #define SDL_TriggerBreakpoint ()
74+ /* How do we trigger breakpoints on this platform? */
75+ #define SDL_TriggerBreakpoint ()
7276#endif
7377
74- #if defined(__STDC_VERSION__ ) && (__STDC_VERSION__ >= 199901L ) /* C99 supports __func__ as a standard. */
75- # define SDL_FUNCTION __func__
76- #elif ((defined(__GNUC__ ) && (__GNUC__ >= 2 )) || defined(_MSC_VER ) || defined (__WATCOMC__ ))
77- # define SDL_FUNCTION __FUNCTION__
78+ #if defined(__STDC_VERSION__ ) && \
79+ (__STDC_VERSION__ >= 199901L ) /* C99 supports __func__ as a standard. */
80+ #define SDL_FUNCTION __func__
81+ #elif ((defined(__GNUC__ ) && (__GNUC__ >= 2 )) || defined(_MSC_VER ) || defined(__WATCOMC__ ))
82+ #define SDL_FUNCTION __FUNCTION__
7883#else
79- # define SDL_FUNCTION "???"
84+ #define SDL_FUNCTION "???"
8085#endif
81- #define SDL_FILE __FILE__
82- #define SDL_LINE __LINE__
86+ #define SDL_FILE __FILE__
87+ #define SDL_LINE __LINE__
8388
8489/*
8590sizeof (x) makes the compiler still parse the expression even without
@@ -98,26 +103,26 @@ disable assertions.
98103
99104/* "while (0,0)" fools Microsoft's compiler's /W4 warning level into thinking
100105 this condition isn't constant. And looks like an owl's face! */
101- #ifdef _MSC_VER /* stupid /W4 warnings. */
102- #define SDL_NULL_WHILE_LOOP_CONDITION (0,0)
106+ #ifdef _MSC_VER /* stupid /W4 warnings. */
107+ #define SDL_NULL_WHILE_LOOP_CONDITION (0, 0)
103108#else
104109#define SDL_NULL_WHILE_LOOP_CONDITION (0)
105110#endif
106111
107112#define SDL_disabled_assert (condition ) \
108- do { (void) sizeof ((condition)); } while (SDL_NULL_WHILE_LOOP_CONDITION)
113+ do { \
114+ (void)sizeof((condition)); \
115+ } while (SDL_NULL_WHILE_LOOP_CONDITION)
109116
110- typedef enum
111- {
112- SDL_ASSERTION_RETRY , /**< Retry the assert immediately. */
113- SDL_ASSERTION_BREAK , /**< Make the debugger trigger a breakpoint. */
114- SDL_ASSERTION_ABORT , /**< Terminate the program. */
115- SDL_ASSERTION_IGNORE , /**< Ignore the assert. */
116- SDL_ASSERTION_ALWAYS_IGNORE /**< Ignore the assert from now on. */
117+ typedef enum {
118+ SDL_ASSERTION_RETRY , /**< Retry the assert immediately. */
119+ SDL_ASSERTION_BREAK , /**< Make the debugger trigger a breakpoint. */
120+ SDL_ASSERTION_ABORT , /**< Terminate the program. */
121+ SDL_ASSERTION_IGNORE , /**< Ignore the assert. */
122+ SDL_ASSERTION_ALWAYS_IGNORE /**< Ignore the assert from now on. */
117123} SDL_AssertState ;
118124
119- typedef struct SDL_AssertData
120- {
125+ typedef struct SDL_AssertData {
121126 int always_ignore ;
122127 unsigned int trigger_count ;
123128 const char * condition ;
@@ -128,18 +133,17 @@ typedef struct SDL_AssertData
128133} SDL_AssertData ;
129134
130135/* Never call this directly. Use the SDL_assert* macros. */
131- extern DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion (SDL_AssertData * ,
132- const char * ,
136+ extern DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion (SDL_AssertData * , const char * ,
133137 const char * , int )
134138#if defined(__clang__ )
135139#if __has_feature (attribute_analyzer_noreturn )
136- /* this tells Clang's static analysis that we're a custom assert function,
137- and that the analyzer should assume the condition was always true past this
138- SDL_assert test. */
139- __attribute__((analyzer_noreturn ))
140+ /* this tells Clang's static analysis that we're a custom assert function,
141+ and that the analyzer should assume the condition was always true past this
142+ SDL_assert test. */
143+ __attribute__((analyzer_noreturn ))
140144#endif
141145#endif
142- ;
146+ ;
143147
144148/* the do {} while(0) avoids dangling else problems:
145149 if (x) SDL_assert(y); else blah();
@@ -148,45 +152,45 @@ extern DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *,
148152 the static vars, and break points. The heavy lifting is handled in
149153 SDL_ReportAssertion(), in SDL_assert.c.
150154*/
151- #define SDL_enabled_assert (condition ) \
152- do { \
153- while ( !(condition) ) { \
154- static struct SDL_AssertData sdl_assert_data = { 0, 0, #condition, 0, 0, 0, 0 }; \
155- const SDL_AssertState sdl_assert_state = SDL_ReportAssertion(&sdl_assert_data, SDL_FUNCTION, SDL_FILE, SDL_LINE); \
156- if (sdl_assert_state == SDL_ASSERTION_RETRY) { \
157- continue; /* go again. */ \
158- } else if (sdl_assert_state == SDL_ASSERTION_BREAK ) { \
159- SDL_TriggerBreakpoint (); \
160- } \
161- break ; /* not retrying. */ \
162- } \
155+ #define SDL_enabled_assert (condition ) \
156+ do { \
157+ while (!(condition)) { \
158+ static struct SDL_AssertData sdl_assert_data = {0, 0, #condition, 0, 0, 0, 0}; \
159+ const SDL_AssertState sdl_assert_state = \
160+ SDL_ReportAssertion(&sdl_assert_data, SDL_FUNCTION, SDL_FILE, SDL_LINE); \
161+ if (sdl_assert_state == SDL_ASSERTION_RETRY) { \
162+ continue; /* go again. */ \
163+ } else if (sdl_assert_state == SDL_ASSERTION_BREAK ) { \
164+ SDL_TriggerBreakpoint (); \
165+ } \
166+ break ; /* not retrying. */ \
167+ } \
163168 } while (SDL_NULL_WHILE_LOOP_CONDITION )
164169
165170/* Enable various levels of assertions. */
166- #if SDL_ASSERT_LEVEL == 0 /* assertions disabled */
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 /* release settings. */
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 /* normal settings. */
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 /* paranoid settings. */
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)
171+ #if SDL_ASSERT_LEVEL == 0 /* assertions disabled */
172+ #define SDL_assert (condition ) SDL_disabled_assert(condition)
173+ #define SDL_assert_release (condition ) SDL_disabled_assert(condition)
174+ #define SDL_assert_paranoid (condition ) SDL_disabled_assert(condition)
175+ #elif SDL_ASSERT_LEVEL == 1 /* release settings. */
176+ #define SDL_assert (condition ) SDL_disabled_assert(condition)
177+ #define SDL_assert_release (condition ) SDL_enabled_assert(condition)
178+ #define SDL_assert_paranoid (condition ) SDL_disabled_assert(condition)
179+ #elif SDL_ASSERT_LEVEL == 2 /* normal settings. */
180+ #define SDL_assert (condition ) SDL_enabled_assert(condition)
181+ #define SDL_assert_release (condition ) SDL_enabled_assert(condition)
182+ #define SDL_assert_paranoid (condition ) SDL_disabled_assert(condition)
183+ #elif SDL_ASSERT_LEVEL == 3 /* paranoid settings. */
184+ #define SDL_assert (condition ) SDL_enabled_assert(condition)
185+ #define SDL_assert_release (condition ) SDL_enabled_assert(condition)
186+ #define SDL_assert_paranoid (condition ) SDL_enabled_assert(condition)
182187#else
183- # error Unknown assertion level.
188+ #error Unknown assertion level.
184189#endif
185190
186191/* this assertion is never disabled at any level. */
187192#define SDL_assert_always (condition ) SDL_enabled_assert(condition)
188193
189-
190194/**
191195 * A callback that fires when an SDL assertion fails.
192196 *
@@ -195,8 +199,7 @@ extern DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *,
195199 * \param userdata what was passed as `userdata` to SDL_SetAssertionHandler()
196200 * \returns an SDL_AssertState value indicating how to handle the failure.
197201 */
198- typedef SDL_AssertState (SDLCALL * SDL_AssertionHandler )(
199- const SDL_AssertData * data , void * userdata );
202+ typedef SDL_AssertState (SDLCALL * SDL_AssertionHandler )(const SDL_AssertData * data , void * userdata );
200203
201204/**
202205 * Set an application-defined assertion handler.
@@ -219,9 +222,7 @@ typedef SDL_AssertState (SDLCALL *SDL_AssertionHandler)(
219222 *
220223 * \sa SDL_GetAssertionHandler
221224 */
222- extern DECLSPEC void SDLCALL SDL_SetAssertionHandler (
223- SDL_AssertionHandler handler ,
224- void * userdata );
225+ extern DECLSPEC void SDLCALL SDL_SetAssertionHandler (SDL_AssertionHandler handler , void * userdata );
225226
226227/**
227228 * Get the default assertion handler.
@@ -289,7 +290,7 @@ extern DECLSPEC SDL_AssertionHandler SDLCALL SDL_GetAssertionHandler(void **puse
289290 *
290291 * \sa SDL_ResetAssertionReport
291292 */
292- extern DECLSPEC const SDL_AssertData * SDLCALL SDL_GetAssertionReport (void );
293+ extern DECLSPEC const SDL_AssertData * SDLCALL SDL_GetAssertionReport (void );
293294
294295/**
295296 * Clear the list of all assertion failures.
@@ -305,12 +306,10 @@ extern DECLSPEC const SDL_AssertData * SDLCALL SDL_GetAssertionReport(void);
305306 */
306307extern DECLSPEC void SDLCALL SDL_ResetAssertionReport (void );
307308
308-
309309/* these had wrong naming conventions until 2.0.4. Please update your app! */
310310#define SDL_assert_state SDL_AssertState
311311#define SDL_assert_data SDL_AssertData
312312
313-
314313/* Ends C function definitions when using C++ */
315314#ifdef __cplusplus
316315}
0 commit comments