Fix BLI_assert for MSVC
Also use `_BLI_ASSERT` prefix for internal defines.
This commit is contained in:
@@ -46,33 +46,28 @@ extern "C" {
|
||||
|
||||
#ifndef NDEBUG
|
||||
# include "BLI_system.h"
|
||||
/* _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_ASSERT_PRINT_POS(a) \
|
||||
fprintf(stderr, "BLI_assert failed: %s:%d, at \'%s\'\n", __FILE__, __LINE__, #a)
|
||||
# endif
|
||||
/* _BLI_ASSERT_ABORT */
|
||||
# ifdef WITH_ASSERT_ABORT
|
||||
# define _BLI_DUMMY_ABORT abort
|
||||
# define _BLI_ASSERT_ABORT abort
|
||||
# else
|
||||
# define _BLI_DUMMY_ABORT() (void)0
|
||||
# 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)
|
||||
# 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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user