changeset 3655:1cc7f0143c12

Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
author Sam Lantinga <slouken@libsdl.org>
date Wed, 13 Jan 2010 08:25:16 +0000
parents 336f3df1578d
children f17ea6f49745
files include/SDL_assert.h src/SDL_assert.c
diffstat 2 files changed, 58 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/include/SDL_assert.h	Wed Jan 13 08:06:32 2010 +0000
+++ b/include/SDL_assert.h	Wed Jan 13 08:25:16 2010 +0000
@@ -19,11 +19,20 @@
     Sam Lantinga
     slouken@libsdl.org
 */
-#include "SDL_config.h"
 
 #ifndef _SDL_assert_h
 #define _SDL_assert_h
 
+#include "SDL_config.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+/* *INDENT-OFF* */
+extern "C" {
+/* *INDENT-ON* */
+#endif
+
 #ifndef SDL_ASSERT_LEVEL
 #ifdef SDL_DEFAULT_ASSERT_LEVEL
 #define SDL_ASSERT_LEVEL SDL_DEFAULT_ASSERT_LEVEL
@@ -36,6 +45,34 @@
 #endif /* SDL_ASSERT_LEVEL */
 
 /*
+These are macros and not first class functions so that the debugger breaks
+on the assertion line and not in some random guts of SDL, and so each
+macro can have unique static variables associated with it.
+*/
+
+#if (defined(_MSC_VER) && ((_M_IX86) || (_M_X64)))
+    #define SDL_TriggerBreakpoint() __asm { int 3 }
+#elif (defined(__GNUC__) && ((__i386__) || (__x86_64__)))
+    #define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "int $3\n\t" )
+#elif defined(HAVE_SIGNAL_H)
+    #include <signal.h>
+    #define SDL_TriggerBreakpoint() raise(SIGTRAP)
+#else
+    /* How do we trigger breakpoints on this platform? */
+    #define SDL_TriggerBreakpoint()
+#endif
+
+#if (__STDC_VERSION__ >= 199901L) /* C99 supports __func__ as a standard. */
+#   define SDL_FUNCTION __func__
+#elif ((__GNUC__ >= 2) || defined(_MSC_VER))
+#   define SDL_FUNCTION __FUNCTION__
+#else
+#   define SDL_FUNCTION "???"
+#endif
+#define SDL_FILE    __FILE__
+#define SDL_LINE    __LINE__
+
+/*
 sizeof (x) makes the compiler still parse the expression even without
 assertions enabled, so the code is always checked at compile time, but
 doesn't actually generate code for it, so there are no side effects or
@@ -55,30 +92,6 @@
 
 #if (SDL_ASSERT_LEVEL > 0)
 
-/*
-These are macros and not first class functions so that the debugger breaks
-on the assertion line and not in some random guts of SDL, and so each
-macro can have unique static variables associated with it.
-*/
-
-#if (defined(_MSC_VER) && ((_M_IX86) || (_M_X64)))
-    #define SDL_TriggerBreakpoint() __asm { int 3 }
-#elif (defined(__GNUC__) && ((__i386__) || (__x86_64__)))
-    #define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "int $3\n\t" )
-#elif defined(HAVE_SIGNAL_H)
-    #include <signal.h>
-    #define SDL_TriggerBreakpoint() raise(SIGTRAP)
-#else
-    #error Please define your platform or set SDL_ASSERT_LEVEL to 0.
-#endif
-
-#if (__STDC_VERSION__ >= 199901L) /* C99 supports __func__ as a standard. */
-#   define SDL_FUNCTION __func__
-#elif ((__GNUC__ >= 2) || defined(_MSC_VER))
-#   define SDL_FUNCTION __FUNCTION__
-#else
-#   define SDL_FUNCTION "???"
-#endif
 
 typedef enum
 {
@@ -100,7 +113,9 @@
     struct SDL_assert_data *next;
 } SDL_assert_data;
 
-SDL_assert_state SDL_ReportAssertion(SDL_assert_data *, const char *, int);
+extern DECLSPEC SDL_assert_state SDLCALL SDL_ReportAssertion(SDL_assert_data *,
+                                                             const char *,
+                                                             const char *, int);
 
 /* the do {} while(0) avoids dangling else problems:
     if (x) SDL_assert(y); else blah();
@@ -113,11 +128,12 @@
     do { \
         while ( !(condition) ) { \
             static struct SDL_assert_data assert_data = { \
-                0, 0, #condition, __FILE__, 0, 0, 0 \
+                0, 0, #condition, 0, 0, 0, 0 \
             }; \
             const SDL_assert_state state = SDL_ReportAssertion(&assert_data, \
                                                                SDL_FUNCTION, \
-                                                               __LINE__); \
+                                                               SDL_FILE, \
+                                                               SDL_LINE); \
             if (state == SDL_ASSERTION_RETRY) { \
                 continue; /* go again. */ \
             } else if (state == SDL_ASSERTION_BREAK) { \
@@ -147,9 +163,17 @@
 #   define SDL_assert_release(condition) SDL_enabled_assert(condition)
 #   define SDL_assert_paranoid(condition) SDL_enabled_assert(condition)
 #else
-#   error Unknown assertion level. Please fix your SDL_config.h.
+#   error Unknown assertion level.
 #endif
 
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+/* *INDENT-OFF* */
+}
+/* *INDENT-ON* */
+#endif
+#include "close_code.h"
+
 #endif /* _SDL_assert_h */
 
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/SDL_assert.c	Wed Jan 13 08:06:32 2010 +0000
+++ b/src/SDL_assert.c	Wed Jan 13 08:25:16 2010 +0000
@@ -265,7 +265,7 @@
                 data->trigger_count, (data->trigger_count == 1) ? "" : "s",
                 data->condition);
 
-	/* let env. variable override, so unit tests won't block in a GUI. */
+    /* let env. variable override, so unit tests won't block in a GUI. */
     envr = SDL_getenv("SDL_ASSERT");
     if (envr != NULL) {
         if (SDL_strcmp(envr, "abort") == 0) {
@@ -327,7 +327,8 @@
 static SDL_mutex *assertion_mutex = NULL;
 
 SDL_assert_state
-SDL_ReportAssertion(SDL_assert_data *data, const char *func, int line)
+SDL_ReportAssertion(SDL_assert_data *data, const char *func, const char *file,
+                    int line)
 {
     SDL_assert_state state;
 
@@ -338,7 +339,8 @@
     /* doing this because Visual C is upset over assigning in the macro. */
     if (data->trigger_count == 0) {
         data->function = func;
-		data->linenum = line;
+        data->filename = file;
+        data->linenum = line;
     }
 
     SDL_AddAssertionToReport(data);