Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-03-15 22:03:29 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-03-15 22:03:29 +0300
commit995ccf816886cc0fdcfcde073581f44159e21b34 (patch)
tree17a765c46569308aa795d96da07c017a1bc4711f /source
parent71139cedcb03001d746338b31e08da6854769832 (diff)
BLI_assert: extract from BLI_utildefines
BLI_utildefines is quite large, defining many unrelated things. Add BLI_assert to include in inline headers, so math defines don't pull in too much.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenlib/BLI_assert.h111
-rw-r--r--source/blender/blenlib/BLI_math_base.h1
-rw-r--r--source/blender/blenlib/BLI_utildefines.h73
-rw-r--r--source/blender/blenlib/intern/math_base_inline.c2
-rw-r--r--source/blender/blenlib/intern/math_bits_inline.c8
5 files changed, 116 insertions, 79 deletions
diff --git a/source/blender/blenlib/BLI_assert.h b/source/blender/blenlib/BLI_assert.h
new file mode 100644
index 00000000000..9fb0954e77f
--- /dev/null
+++ b/source/blender/blenlib/BLI_assert.h
@@ -0,0 +1,111 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BLI_ASSERT_H__
+#define __BLI_ASSERT_H__
+
+/** \file BLI_assert.h
+ * \ingroup bli
+ *
+ * Defines:
+ * - #BLI_assert
+ * - #BLI_STATIC_ASSERT
+ * - #BLI_STATIC_ASSERT_ALIGN
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef NDEBUG /* for BLI_assert */
+#include <stdio.h>
+#endif
+
+/* BLI_assert(), default only to print
+ * for aborting need to define WITH_ASSERT_ABORT
+ */
+/* For 'abort' only. */
+#include <stdlib.h>
+
+#ifndef NDEBUG
+# include "BLI_system.h"
+# ifdef WITH_ASSERT_ABORT
+# define _BLI_DUMMY_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)
+# endif
+#else
+# define BLI_assert(a) (void)0
+#endif
+
+/* C++ can't use _Static_assert, expects static_assert() but c++0x only,
+ * Coverity also errors out. */
+#if (!defined(__cplusplus)) && \
+ (!defined(__COVERITY__)) && \
+ (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 406)) /* gcc4.6+ only */
+# define BLI_STATIC_ASSERT(a, msg) __extension__ _Static_assert(a, msg);
+#else
+/* 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)
+ /* 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)) };
+# 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)) };
+# endif
+#endif
+
+#define BLI_STATIC_ASSERT_ALIGN(st, align) \
+ BLI_STATIC_ASSERT((sizeof(st) % (align) == 0), "Structure must be strictly aligned")
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BLI_ASSERT_H__ */
diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h
index 3b24cae018d..6f8e48d83b2 100644
--- a/source/blender/blenlib/BLI_math_base.h
+++ b/source/blender/blenlib/BLI_math_base.h
@@ -35,6 +35,7 @@
#endif
#include <math.h>
+#include "BLI_assert.h"
#include "BLI_math_inline.h"
#ifndef M_PI
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h
index ee1acc5afdd..11c8a586784 100644
--- a/source/blender/blenlib/BLI_utildefines.h
+++ b/source/blender/blenlib/BLI_utildefines.h
@@ -41,9 +41,8 @@ extern "C" {
#include "BLI_compiler_compat.h"
#include "BLI_utildefines_variadic.h"
-#ifndef NDEBUG /* for BLI_assert */
-#include <stdio.h>
-#endif
+/* We could remove in future. */
+#include "BLI_assert.h"
/* useful for finding bad use of min/max */
#if 0
@@ -615,74 +614,6 @@ extern bool BLI_memory_is_zero(const void *arr, const size_t arr_size);
# define UNUSED_VARS_NDEBUG UNUSED_VARS
#endif
-
-/* BLI_assert(), default only to print
- * for aborting need to define WITH_ASSERT_ABORT
- */
-/* For 'abort' only. */
-#include <stdlib.h>
-
-#ifndef NDEBUG
-# include "BLI_system.h"
-# ifdef WITH_ASSERT_ABORT
-# define _BLI_DUMMY_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__, STRINGIFY(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__, STRINGIFY(a)), \
- _BLI_DUMMY_ABORT(), \
- NULL)) : NULL)
-# endif
-#else
-# define BLI_assert(a) (void)0
-#endif
-
-/* C++ can't use _Static_assert, expects static_assert() but c++0x only,
- * Coverity also errors out. */
-#if (!defined(__cplusplus)) && \
- (!defined(__COVERITY__)) && \
- (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 406)) /* gcc4.6+ only */
-# define BLI_STATIC_ASSERT(a, msg) __extension__ _Static_assert(a, msg);
-#else
-/* 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)
- /* 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)) };
-# 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)) };
-# endif
-#endif
-
-
-#define BLI_STATIC_ASSERT_ALIGN(st, align) \
- BLI_STATIC_ASSERT((sizeof(st) % (align) == 0), "Structure must be strictly aligned")
-
/* hints for branch prediction, only use in code that runs a _lot_ where */
#ifdef __GNUC__
# define LIKELY(x) __builtin_expect(!!(x), 1)
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;
diff --git a/source/blender/blenlib/intern/math_bits_inline.c b/source/blender/blenlib/intern/math_bits_inline.c
index 933ded55d53..9b16756134e 100644
--- a/source/blender/blenlib/intern/math_bits_inline.c
+++ b/source/blender/blenlib/intern/math_bits_inline.c
@@ -33,10 +33,8 @@
MINLINE int bitscan_forward_i(int a)
{
-#if 0 /* No BLI_assert in INLINE :/ */
BLI_assert(a != 0);
-#endif
-# ifdef _MSC_VER
+#ifdef _MSC_VER
unsigned long ctz;
_BitScanForward(&ctz, a);
return ctz;
@@ -64,10 +62,8 @@ MINLINE unsigned int bitscan_forward_clear_uint(unsigned int *a)
MINLINE int bitscan_reverse_i(int a)
{
-#if 0 /* No BLI_assert in INLINE :/ */
BLI_assert(a != 0);
-#endif
-# ifdef _MSC_VER
+#ifdef _MSC_VER
unsigned long clz;
_BitScanReverse(&clz, a);
return clz;