From 1782abf6e2c6fb13d04b206d2c36567a28619a59 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 20 Mar 2018 11:49:33 +0100 Subject: Fix BLI_assert for MSVC Also use `_BLI_ASSERT` prefix for internal defines. --- source/blender/blenlib/BLI_assert.h | 47 +++++++++++------------- source/blender/blenlib/intern/math_base_inline.c | 2 - 2 files changed, 21 insertions(+), 28 deletions(-) (limited to 'source/blender/blenlib') 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 diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index 1f517471407..eed06c7841b 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -368,10 +368,8 @@ MINLINE int compare_ff_relative(float a, float b, const float max_diff, const in { union {float f; int i;} ua, ub; -#if 0 /* No BLI_assert in INLINE :/ */ BLI_assert(sizeof(float) == sizeof(int)); BLI_assert(max_ulps < (1 << 22)); -#endif if (fabsf(a - b) <= max_diff) { return 1; -- cgit v1.2.3