include/SDL_assert.h
changeset 3655 1cc7f0143c12
parent 3654 336f3df1578d
child 3665 97114af2f8dc
     1.1 --- a/include/SDL_assert.h	Wed Jan 13 08:06:32 2010 +0000
     1.2 +++ b/include/SDL_assert.h	Wed Jan 13 08:25:16 2010 +0000
     1.3 @@ -19,11 +19,20 @@
     1.4      Sam Lantinga
     1.5      slouken@libsdl.org
     1.6  */
     1.7 -#include "SDL_config.h"
     1.8  
     1.9  #ifndef _SDL_assert_h
    1.10  #define _SDL_assert_h
    1.11  
    1.12 +#include "SDL_config.h"
    1.13 +
    1.14 +#include "begin_code.h"
    1.15 +/* Set up for C function definitions, even when using C++ */
    1.16 +#ifdef __cplusplus
    1.17 +/* *INDENT-OFF* */
    1.18 +extern "C" {
    1.19 +/* *INDENT-ON* */
    1.20 +#endif
    1.21 +
    1.22  #ifndef SDL_ASSERT_LEVEL
    1.23  #ifdef SDL_DEFAULT_ASSERT_LEVEL
    1.24  #define SDL_ASSERT_LEVEL SDL_DEFAULT_ASSERT_LEVEL
    1.25 @@ -36,6 +45,34 @@
    1.26  #endif /* SDL_ASSERT_LEVEL */
    1.27  
    1.28  /*
    1.29 +These are macros and not first class functions so that the debugger breaks
    1.30 +on the assertion line and not in some random guts of SDL, and so each
    1.31 +macro can have unique static variables associated with it.
    1.32 +*/
    1.33 +
    1.34 +#if (defined(_MSC_VER) && ((_M_IX86) || (_M_X64)))
    1.35 +    #define SDL_TriggerBreakpoint() __asm { int 3 }
    1.36 +#elif (defined(__GNUC__) && ((__i386__) || (__x86_64__)))
    1.37 +    #define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "int $3\n\t" )
    1.38 +#elif defined(HAVE_SIGNAL_H)
    1.39 +    #include <signal.h>
    1.40 +    #define SDL_TriggerBreakpoint() raise(SIGTRAP)
    1.41 +#else
    1.42 +    /* How do we trigger breakpoints on this platform? */
    1.43 +    #define SDL_TriggerBreakpoint()
    1.44 +#endif
    1.45 +
    1.46 +#if (__STDC_VERSION__ >= 199901L) /* C99 supports __func__ as a standard. */
    1.47 +#   define SDL_FUNCTION __func__
    1.48 +#elif ((__GNUC__ >= 2) || defined(_MSC_VER))
    1.49 +#   define SDL_FUNCTION __FUNCTION__
    1.50 +#else
    1.51 +#   define SDL_FUNCTION "???"
    1.52 +#endif
    1.53 +#define SDL_FILE    __FILE__
    1.54 +#define SDL_LINE    __LINE__
    1.55 +
    1.56 +/*
    1.57  sizeof (x) makes the compiler still parse the expression even without
    1.58  assertions enabled, so the code is always checked at compile time, but
    1.59  doesn't actually generate code for it, so there are no side effects or
    1.60 @@ -55,30 +92,6 @@
    1.61  
    1.62  #if (SDL_ASSERT_LEVEL > 0)
    1.63  
    1.64 -/*
    1.65 -These are macros and not first class functions so that the debugger breaks
    1.66 -on the assertion line and not in some random guts of SDL, and so each
    1.67 -macro can have unique static variables associated with it.
    1.68 -*/
    1.69 -
    1.70 -#if (defined(_MSC_VER) && ((_M_IX86) || (_M_X64)))
    1.71 -    #define SDL_TriggerBreakpoint() __asm { int 3 }
    1.72 -#elif (defined(__GNUC__) && ((__i386__) || (__x86_64__)))
    1.73 -    #define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "int $3\n\t" )
    1.74 -#elif defined(HAVE_SIGNAL_H)
    1.75 -    #include <signal.h>
    1.76 -    #define SDL_TriggerBreakpoint() raise(SIGTRAP)
    1.77 -#else
    1.78 -    #error Please define your platform or set SDL_ASSERT_LEVEL to 0.
    1.79 -#endif
    1.80 -
    1.81 -#if (__STDC_VERSION__ >= 199901L) /* C99 supports __func__ as a standard. */
    1.82 -#   define SDL_FUNCTION __func__
    1.83 -#elif ((__GNUC__ >= 2) || defined(_MSC_VER))
    1.84 -#   define SDL_FUNCTION __FUNCTION__
    1.85 -#else
    1.86 -#   define SDL_FUNCTION "???"
    1.87 -#endif
    1.88  
    1.89  typedef enum
    1.90  {
    1.91 @@ -100,7 +113,9 @@
    1.92      struct SDL_assert_data *next;
    1.93  } SDL_assert_data;
    1.94  
    1.95 -SDL_assert_state SDL_ReportAssertion(SDL_assert_data *, const char *, int);
    1.96 +extern DECLSPEC SDL_assert_state SDLCALL SDL_ReportAssertion(SDL_assert_data *,
    1.97 +                                                             const char *,
    1.98 +                                                             const char *, int);
    1.99  
   1.100  /* the do {} while(0) avoids dangling else problems:
   1.101      if (x) SDL_assert(y); else blah();
   1.102 @@ -113,11 +128,12 @@
   1.103      do { \
   1.104          while ( !(condition) ) { \
   1.105              static struct SDL_assert_data assert_data = { \
   1.106 -                0, 0, #condition, __FILE__, 0, 0, 0 \
   1.107 +                0, 0, #condition, 0, 0, 0, 0 \
   1.108              }; \
   1.109              const SDL_assert_state state = SDL_ReportAssertion(&assert_data, \
   1.110                                                                 SDL_FUNCTION, \
   1.111 -                                                               __LINE__); \
   1.112 +                                                               SDL_FILE, \
   1.113 +                                                               SDL_LINE); \
   1.114              if (state == SDL_ASSERTION_RETRY) { \
   1.115                  continue; /* go again. */ \
   1.116              } else if (state == SDL_ASSERTION_BREAK) { \
   1.117 @@ -147,9 +163,17 @@
   1.118  #   define SDL_assert_release(condition) SDL_enabled_assert(condition)
   1.119  #   define SDL_assert_paranoid(condition) SDL_enabled_assert(condition)
   1.120  #else
   1.121 -#   error Unknown assertion level. Please fix your SDL_config.h.
   1.122 +#   error Unknown assertion level.
   1.123  #endif
   1.124  
   1.125 +/* Ends C function definitions when using C++ */
   1.126 +#ifdef __cplusplus
   1.127 +/* *INDENT-OFF* */
   1.128 +}
   1.129 +/* *INDENT-ON* */
   1.130 +#endif
   1.131 +#include "close_code.h"
   1.132 +
   1.133  #endif /* _SDL_assert_h */
   1.134  
   1.135  /* vi: set ts=4 sw=4 expandtab: */