[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [51608] trunk/blender/source/blender: add BLI_STATIC_ASSERT macro.
Campbell Barton
ideasman42 at gmail.com
Thu Oct 25 06:44:53 CEST 2012
Revision: 51608
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51608
Author: campbellbarton
Date: 2012-10-25 04:44:46 +0000 (Thu, 25 Oct 2012)
Log Message:
-----------
add BLI_STATIC_ASSERT macro.
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/intern/customdata.c
trunk/blender/source/blender/blenlib/BLI_utildefines.h
trunk/blender/source/blender/blenlib/intern/BLI_kdopbvh.c
Modified: trunk/blender/source/blender/blenkernel/intern/customdata.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/customdata.c 2012-10-25 04:08:51 UTC (rev 51607)
+++ trunk/blender/source/blender/blenkernel/intern/customdata.c 2012-10-25 04:44:46 UTC (rev 51608)
@@ -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 @@
{
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;
}
Modified: trunk/blender/source/blender/blenlib/BLI_utildefines.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_utildefines.h 2012-10-25 04:08:51 UTC (rev 51607)
+++ trunk/blender/source/blender/blenlib/BLI_utildefines.h 2012-10-25 04:44:46 UTC (rev 51608)
@@ -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)
Modified: trunk/blender/source/blender/blenlib/intern/BLI_kdopbvh.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_kdopbvh.c 2012-10-25 04:08:51 UTC (rev 51607)
+++ trunk/blender/source/blender/blenlib/intern/BLI_kdopbvh.c 2012-10-25 04:44:46 UTC (rev 51608)
@@ -70,12 +70,9 @@
};
/* 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;
More information about the Bf-blender-cvs
mailing list