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
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-10-25 08:44:46 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-10-25 08:44:46 +0400
commit9e6d27bbf0afed29f3b31800d75c17ee68472a9c (patch)
tree84082a76c5c017b1c678d4af50f808ee1d277189
parent69fa77d279f602641c965919a3071713cb4addb7 (diff)
add BLI_STATIC_ASSERT macro.
-rw-r--r--source/blender/blenkernel/intern/customdata.c9
-rw-r--r--source/blender/blenlib/BLI_utildefines.h7
-rw-r--r--source/blender/blenlib/intern/BLI_kdopbvh.c9
3 files changed, 16 insertions, 9 deletions
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index 0eacd78a72f..d8082902a44 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -65,6 +65,12 @@
/* number of layers to add when growing a CustomData object */
#define CUSTOMDATA_GROW 5
+/* ensure typemap size is ok */
+BLI_STATIC_ASSERT(sizeof(((CustomData *)NULL)->typemap) /
+ sizeof(((CustomData *)NULL)->typemap[0]) == CD_NUMTYPES,
+ "size mismatch");
+
+
/********************* Layer type information **********************/
typedef struct LayerTypeInfo {
int size; /* the memory size of one element of this layer's data */
@@ -1221,9 +1227,6 @@ void CustomData_update_typemap(CustomData *data)
{
int i, lasttype = -1;
- /* since we cant do in a pre-processor do here as an assert */
- BLI_assert(sizeof(data->typemap) / sizeof(int) >= CD_NUMTYPES);
-
for (i = 0; i < CD_NUMTYPES; i++) {
data->typemap[i] = -1;
}
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h
index 801cff089d7..22312a52e87 100644
--- a/source/blender/blenlib/BLI_utildefines.h
+++ b/source/blender/blenlib/BLI_utildefines.h
@@ -348,6 +348,13 @@
# define BLI_assert(a) (void)0
#endif
+#if (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 406)) /* gcc4.6+ only */
+# define BLI_STATIC_ASSERT(a, msg) _Static_assert(a, msg);
+#else
+ /* TODO msvc, clang */
+# define BLI_STATIC_ASSERT(a, msg) (void)0
+#endif
+
/* hints for branch pradiction, 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/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c
index dbd614bb1a4..fe91f91320a 100644
--- a/source/blender/blenlib/intern/BLI_kdopbvh.c
+++ b/source/blender/blenlib/intern/BLI_kdopbvh.c
@@ -70,12 +70,9 @@ struct BVHTree {
};
/* optimization, ensure we stay small */
-#if (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 406)) /* gcc4.6 only */
- _Static_assert(
- (sizeof(void *) == 8 && sizeof(BVHTree) <= 48) ||
- (sizeof(void *) == 4 && sizeof(BVHTree) <= 32),
- "over sized");
-#endif
+BLI_STATIC_ASSERT((sizeof(void *) == 8 && sizeof(BVHTree) <= 48) ||
+ (sizeof(void *) == 4 && sizeof(BVHTree) <= 32),
+ "over sized");
typedef struct BVHOverlapData {
BVHTree *tree1, *tree2;