diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-03-20 13:49:33 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-03-20 13:56:11 +0300 |
commit | 1782abf6e2c6fb13d04b206d2c36567a28619a59 (patch) | |
tree | bc4ecfcb1b80716183a5914cd210e6d9490ac8b1 /source/blender/blenlib/BLI_assert.h | |
parent | 60ff803998360c8a83c3f740342c44124ec277ff (diff) |
Fix BLI_assert for MSVC
Also use `_BLI_ASSERT` prefix for internal defines.
Diffstat (limited to 'source/blender/blenlib/BLI_assert.h')
-rw-r--r-- | source/blender/blenlib/BLI_assert.h | 47 |
1 files changed, 21 insertions, 26 deletions
diff --git a/source/blender/blenlib/BLI_assert.h b/source/blender/blenlib/BLI_assert.h index 9fb0954e77f..b66b95b21fe 100644 --- a/source/blender/blenlib/BLI_assert.h +++ b/source/blender/blenlib/BLI_assert.h @@ -46,33 +46,28 @@ extern "C" { #ifndef NDEBUG # include "BLI_system.h" -# ifdef WITH_ASSERT_ABORT -# define _BLI_DUMMY_ABORT abort + /* _BLI_ASSERT_PRINT_POS */ +# if defined(__GNUC__) +# define _BLI_ASSERT_PRINT_POS(a) \ + fprintf(stderr, "BLI_assert failed: %s:%d, %s(), at \'%s\'\n", __FILE__, __LINE__, __func__, #a) +# elif defined(_MSC_VER) +# define _BLI_ASSERT_PRINT_POS(a) \ + fprintf(stderr, "BLI_assert failed: %s:%d, %s(), at \'%s\'\n", __FILE__, __LINE__, __FUNCTION__, #a) # else -# define _BLI_DUMMY_ABORT() (void)0 +# define _BLI_ASSERT_PRINT_POS(a) \ + fprintf(stderr, "BLI_assert failed: %s:%d, at \'%s\'\n", __FILE__, __LINE__, #a) # endif -# if defined(__GNUC__) || defined(_MSC_VER) /* check __func__ is available */ -# define BLI_assert(a) \ - (void)((!(a)) ? ( \ - ( \ - BLI_system_backtrace(stderr), \ - fprintf(stderr, \ - "BLI_assert failed: %s:%d, %s(), at \'%s\'\n", \ - __FILE__, __LINE__, __func__, "" #a), \ - _BLI_DUMMY_ABORT(), \ - NULL)) : NULL) + /* _BLI_ASSERT_ABORT */ +# ifdef WITH_ASSERT_ABORT +# define _BLI_ASSERT_ABORT abort # else -# define BLI_assert(a) \ - (void)((!(a)) ? ( \ - ( \ - fprintf(stderr, \ - "BLI_assert failed: %s:%d, at \'%s\'\n", \ - __FILE__, __LINE__, "" #a), \ - _BLI_DUMMY_ABORT(), \ - NULL)) : NULL) +# define _BLI_ASSERT_ABORT() (void)0 # endif + /* BLI_assert */ +# define BLI_assert(a) \ + (void)((!(a)) ? ((BLI_system_backtrace(stderr), _BLI_ASSERT_PRINT_POS(a), _BLI_ASSERT_ABORT(), NULL)) : NULL) #else -# define BLI_assert(a) (void)0 +# define BLI_assert(a) ((void)0) #endif /* C++ can't use _Static_assert, expects static_assert() but c++0x only, @@ -85,19 +80,19 @@ extern "C" { /* Code adapted from http://www.pixelbeat.org/programming/gcc/static_assert.html */ /* Note we need the two concats below because arguments to ## are not expanded, so we need to * expand __LINE__ with one indirection before doing the actual concatenation. */ -# define ASSERT_CONCAT_(a, b) a##b -# define ASSERT_CONCAT(a, b) ASSERT_CONCAT_(a, b) +# define _BLI_ASSERT_CONCAT_(a, b) a##b +# define _BLI_ASSERT_CONCAT(a, b) _BLI_ASSERT_CONCAT_(a, b) /* These can't be used after statements in c89. */ # if defined(__COUNTER__) /* MSVC */ # define BLI_STATIC_ASSERT(a, msg) \ - ; enum { ASSERT_CONCAT(static_assert_, __COUNTER__) = 1 / (int)(!!(a)) }; + ; enum { _BLI_ASSERT_CONCAT(static_assert_, __COUNTER__) = 1 / (int)(!!(a)) }; # else /* older gcc, clang... */ /* This can't be used twice on the same line so ensure if using in headers * that the headers are not included twice (by wrapping in #ifndef...#endif) * Note it doesn't cause an issue when used on same line of separate modules * compiled with gcc -combine -fwhole-program. */ # define BLI_STATIC_ASSERT(a, msg) \ - ; enum { ASSERT_CONCAT(assert_line_, __LINE__) = 1 / (int)(!!(a)) }; + ; enum { _BLI_ASSERT_CONCAT(assert_line_, __LINE__) = 1 / (int)(!!(a)) }; # endif #endif |