[Bf-blender-cvs] [88a0d5e] master: Make CHECK_TYPE_NONCONST macro portable

Campbell Barton noreply at git.blender.org
Sat Aug 2 10:09:16 CEST 2014


Commit: 88a0d5ebe821d3ccd2261e99e8a9d47cceed57dc
Author: Campbell Barton
Date:   Sat Aug 2 18:03:50 2014 +1000
Branches: master
https://developer.blender.org/rB88a0d5ebe821d3ccd2261e99e8a9d47cceed57dc

Make CHECK_TYPE_NONCONST macro portable

also replace __typeof -> typeof

===================================================================

M	intern/cycles/util/util_types.h
M	source/blender/blenlib/BLI_math_base.h
M	source/blender/blenlib/BLI_utildefines.h

===================================================================

diff --git a/intern/cycles/util/util_types.h b/intern/cycles/util/util_types.h
index 98d7078..d7d80e2 100644
--- a/intern/cycles/util/util_types.h
+++ b/intern/cycles/util/util_types.h
@@ -474,14 +474,14 @@ enum InterpolationType {
  * ... the compiler optimizes away the temp var */
 #ifdef __GNUC__
 #define CHECK_TYPE(var, type)  {  \
-	__typeof(var) *__tmp;         \
+	typeof(var) *__tmp;         \
 	__tmp = (type *)NULL;         \
 	(void)__tmp;                  \
 } (void)0
 
 #define CHECK_TYPE_PAIR(var_a, var_b)  {  \
-	__typeof(var_a) *__tmp;               \
-	__tmp = (__typeof(var_b) *)NULL;      \
+	typeof(var_a) *__tmp;                 \
+	__tmp = (typeof(var_b) *)NULL;        \
 	(void)__tmp;                          \
 } (void)0
 #else
diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h
index 54e9349..b3fc1b1 100644
--- a/source/blender/blenlib/BLI_math_base.h
+++ b/source/blender/blenlib/BLI_math_base.h
@@ -163,7 +163,7 @@ static const int NAN_INT = 0x7FC00000;
 #ifndef CHECK_TYPE
 #ifdef __GNUC__
 #define CHECK_TYPE(var, type)  {  \
-	__typeof(var) *__tmp;         \
+	typeof(var) *__tmp;           \
 	__tmp = (type *)NULL;         \
 	(void)__tmp;                  \
 } (void)0
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h
index 5937880..fcc7ac3 100644
--- a/source/blender/blenlib/BLI_utildefines.h
+++ b/source/blender/blenlib/BLI_utildefines.h
@@ -157,39 +157,38 @@
  * ... the compiler optimizes away the temp var */
 #ifdef __GNUC__
 #define CHECK_TYPE(var, type)  {  \
-	__typeof(var) *__tmp;         \
+	typeof(var) *__tmp;         \
 	__tmp = (type *)NULL;         \
 	(void)__tmp;                  \
 } (void)0
 
 #define CHECK_TYPE_PAIR(var_a, var_b)  {  \
-	__typeof(var_a) *__tmp;               \
-	__tmp = (__typeof(var_b) *)NULL;      \
+	typeof(var_a) *__tmp;                 \
+	__tmp = (typeof(var_b) *)NULL;        \
 	(void)__tmp;                          \
 } (void)0
 
 #define CHECK_TYPE_PAIR_INLINE(var_a, var_b)  ((void)({  \
-	__typeof(var_a) *__tmp;                              \
-	__tmp = (__typeof(var_b) *)NULL;                     \
+	typeof(var_a) *__tmp;                                \
+	__tmp = (typeof(var_b) *)NULL;                       \
 	(void)__tmp;                                         \
 }))
 
-#define CHECK_TYPE_NONCONST(var)  {           \
-	void *non_const = ((__typeof(var))NULL);  \
-	(void)non_const;                          \
-} (void)0
-
 #else
 #  define CHECK_TYPE(var, type)
 #  define CHECK_TYPE_PAIR(var_a, var_b)
 #  define CHECK_TYPE_PAIR_INLINE(var_a, var_b) (void)0
-#  define CHECK_TYPE_NONCONST(var) (void)0
 #endif
 
 /* can be used in simple macros */
 #define CHECK_TYPE_INLINE(val, type) \
 	((void)(((type)0) != (val)))
 
+#define CHECK_TYPE_NONCONST(var)  {      \
+	void *non_const = 0 ? (var) : NULL;  \
+	(void)non_const;                     \
+} (void)0
+
 #define SWAP(type, a, b)  {    \
 	type sw_ap;                \
 	CHECK_TYPE(a, type);       \
@@ -414,8 +413,7 @@
 /* memcpy, skipping the first part of a struct,
  * ensures 'struct_dst' isn't const and that the offset can be computed at compile time */
 #define MEMCPY_STRUCT_OFS(struct_dst, struct_src, member)  { \
-	void *_not_const = struct_dst; \
-	(void)_not_const; \
+	CHECK_TYPE_NONCONST(struct_dst); \
 	((void)(struct_dst == struct_src), \
 	 memcpy((char *)(struct_dst)  + OFFSETOF_STRUCT(struct_dst, member), \
 	        (char *)(struct_src)  + OFFSETOF_STRUCT(struct_dst, member), \




More information about the Bf-blender-cvs mailing list