[Pixman] [PATCH] Make the combiner macros less likely to cause name collisions.

Søren Sandmann sandmann at daimi.au.dk
Tue Jul 6 16:18:34 PDT 2010


From: Søren Sandmann Pedersen <ssp at redhat.com>

Protect the arguments to the combiner macros with parentheses, and
prefix their temporary variables with underscores to avoid name space
collisions with the surrounding code.
---
 pixman/pixman-combine.h.template |  152 +++++++++++++++++++-------------------
 1 files changed, 76 insertions(+), 76 deletions(-)

diff --git a/pixman/pixman-combine.h.template b/pixman/pixman-combine.h.template
index 2f6392f..012ada7 100644
--- a/pixman/pixman-combine.h.template
+++ b/pixman/pixman-combine.h.template
@@ -31,7 +31,7 @@
     (((comp2_t) (a) * MASK) / (b))
 
 #define ADD_UNc(x, y, t)				     \
-    ((t) = x + y,					     \
+    ((t) = (x) + (y),					     \
      (comp4_t) (comp1_t) ((t) | (0 - ((t) >> G_SHIFT))))
 
 #define DIV_ONE_UNc(x)							\
@@ -84,15 +84,15 @@
 #define UNcx4_MUL_UNc(x, a)						\
     do									\
     {									\
-	comp4_t r1, r2, t;						\
+	comp4_t __r1, __r2, __t;					\
 									\
-	r1 = (x);							\
-	UNc_rb_MUL_UNc (r1, a, t);					\
+	__r1 = (x);							\
+	UNc_rb_MUL_UNc (__r1, (a), __t);				\
 									\
-	r2 = (x) >> G_SHIFT;						\
-	UNc_rb_MUL_UNc (r2, a, t);					\
+	__r2 = (x) >> G_SHIFT;						\
+	UNc_rb_MUL_UNc (__r2, (a), __t);				\
 									\
-	x = r1 | (r2 << G_SHIFT);					\
+	(x) = __r1 | (__r2 << G_SHIFT);					\
     } while (0)
 
 /*
@@ -101,19 +101,19 @@
 #define UNcx4_MUL_UNc_ADD_UNcx4(x, a, y)				\
     do									\
     {									\
-	comp4_t r1, r2, r3, t;						\
+	comp4_t __r1, __r2, __r3, __t;					\
 									\
-	r1 = (x);							\
-	r2 = (y) & RB_MASK;						\
-	UNc_rb_MUL_UNc (r1, a, t);					\
-	UNc_rb_ADD_UNc_rb (r1, r2, t);					\
+	__r1 = (x);							\
+	__r2 = (y) & RB_MASK;						\
+	UNc_rb_MUL_UNc (__r1, (a), __t);				\
+	UNc_rb_ADD_UNc_rb (__r1, __r2, __t);				\
 									\
-	r2 = (x) >> G_SHIFT;						\
-	r3 = ((y) >> G_SHIFT) & RB_MASK;				\
-	UNc_rb_MUL_UNc (r2, a, t);					\
-	UNc_rb_ADD_UNc_rb (r2, r3, t);					\
+	__r2 = (x) >> G_SHIFT;						\
+	__r3 = ((y) >> G_SHIFT) & RB_MASK;				\
+	UNc_rb_MUL_UNc (__r2, (a), __t);				\
+	UNc_rb_ADD_UNc_rb (__r2, __r3, __t);				\
 									\
-	x = r1 | (r2 << G_SHIFT);					\
+	(x) = __r1 | (__r2 << G_SHIFT);					\
     } while (0)
 
 /*
@@ -122,21 +122,21 @@
 #define UNcx4_MUL_UNc_ADD_UNcx4_MUL_UNc(x, a, y, b)			\
     do									\
     {									\
-	comp4_t r1, r2, r3, t;						\
+	comp4_t __r1, __r2, __r3, __t;					\
 									\
-	r1 = x;								\
-	r2 = y;								\
-	UNc_rb_MUL_UNc (r1, a, t);					\
-	UNc_rb_MUL_UNc (r2, b, t);					\
-	UNc_rb_ADD_UNc_rb (r1, r2, t);					\
+	__r1 = (x);							\
+	__r2 = (y);							\
+	UNc_rb_MUL_UNc (__r1, (a), __t);				\
+	UNc_rb_MUL_UNc (__r2, (b), __t);				\
+	UNc_rb_ADD_UNc_rb (__r1, __r2, __t);				\
 									\
-	r2 = (x >> G_SHIFT);						\
-	r3 = (y >> G_SHIFT);						\
-	UNc_rb_MUL_UNc (r2, a, t);					\
-	UNc_rb_MUL_UNc (r3, b, t);					\
-	UNc_rb_ADD_UNc_rb (r2, r3, t);					\
+	__r2 = ((x) >> G_SHIFT);					\
+	__r3 = ((y) >> G_SHIFT);					\
+	UNc_rb_MUL_UNc (__r2, (a), __t);				\
+	UNc_rb_MUL_UNc (__r3, (b), __t);				\
+	UNc_rb_ADD_UNc_rb (__r2, __r3, __t);				\
 									\
-	x = r1 | (r2 << G_SHIFT);					\
+	(x) = __r1 | (__r2 << G_SHIFT);					\
     } while (0)
 
 /*
@@ -145,17 +145,17 @@
 #define UNcx4_MUL_UNcx4(x, a)						\
     do									\
     {									\
-	comp4_t r1, r2, r3, t;						\
+	comp4_t __r1, __r2, __r3, __t;					\
 									\
-	r1 = x;								\
-	r2 = a;								\
-	UNc_rb_MUL_UNc_rb (r1, r2, t);					\
+	__r1 = (x);							\
+	__r2 = (a);							\
+	UNc_rb_MUL_UNc_rb (__r1, __r2, __t);				\
 									\
-	r2 = x >> G_SHIFT;						\
-	r3 = a >> G_SHIFT;						\
-	UNc_rb_MUL_UNc_rb (r2, r3, t);					\
+	__r2 = (x) >> G_SHIFT;						\
+	__r3 = (a) >> G_SHIFT;						\
+	UNc_rb_MUL_UNc_rb (__r2, __r3, __t);				\
 									\
-	x = r1 | (r2 << G_SHIFT);					\
+	(x) = __r1 | (__r2 << G_SHIFT);					\
     } while (0)
 
 /*
@@ -164,21 +164,21 @@
 #define UNcx4_MUL_UNcx4_ADD_UNcx4(x, a, y)				\
     do									\
     {									\
-	comp4_t r1, r2, r3, t;						\
+	comp4_t __r1, __r2, __r3, __t;					\
 									\
-	r1 = x;								\
-	r2 = a;								\
-	UNc_rb_MUL_UNc_rb (r1, r2, t);					\
-	r2 = y & RB_MASK;						\
-	UNc_rb_ADD_UNc_rb (r1, r2, t);					\
+	__r1 = (x);							\
+	__r2 = (a);							\
+	UNc_rb_MUL_UNc_rb (__r1, __r2, __t);				\
+	__r2 = (y) & RB_MASK;						\
+	UNc_rb_ADD_UNc_rb (__r1, __r2, __t);				\
 									\
-	r2 = (x >> G_SHIFT);						\
-	r3 = (a >> G_SHIFT);						\
-	UNc_rb_MUL_UNc_rb (r2, r3, t);					\
-	r3 = (y >> G_SHIFT) & RB_MASK;					\
-	UNc_rb_ADD_UNc_rb (r2, r3, t);					\
+	__r2 = ((x) >> G_SHIFT);					\
+	__r3 = ((a) >> G_SHIFT);					\
+	UNc_rb_MUL_UNc_rb (__r2, __r3, __t);				\
+	__r3 = ((y) >> G_SHIFT) & RB_MASK;				\
+	UNc_rb_ADD_UNc_rb (__r2, __r3, __t);				\
 									\
-	x = r1 | (r2 << G_SHIFT);					\
+	(x) = __r1 | (__r2 << G_SHIFT);					\
     } while (0)
 
 /*
@@ -187,40 +187,40 @@
 #define UNcx4_MUL_UNcx4_ADD_UNcx4_MUL_UNc(x, a, y, b)			\
     do									\
     {									\
-	comp4_t r1, r2, r3, t;						\
-									\
-	r1 = x;								\
-	r2 = a;								\
-	UNc_rb_MUL_UNc_rb (r1, r2, t);					\
-	r2 = y;								\
-	UNc_rb_MUL_UNc (r2, b, t);					\
-	UNc_rb_ADD_UNc_rb (r1, r2, t);					\
-									\
-	r2 = x >> G_SHIFT;						\
-	r3 = a >> G_SHIFT;						\
-	UNc_rb_MUL_UNc_rb (r2, r3, t);					\
-	r3 = y >> G_SHIFT;						\
-	UNc_rb_MUL_UNc (r3, b, t);					\
-	UNc_rb_ADD_UNc_rb (r2, r3, t);					\
-									\
-	x = r1 | (r2 << G_SHIFT);					\
+	comp4_t __r1, __r2, __r3, __t;					\
+									\
+	__r1 = (x);							\
+	__r2 = (a);							\
+	UNc_rb_MUL_UNc_rb (__r1, __r2, __t);				\
+	__r2 = (y);							\
+	UNc_rb_MUL_UNc (__r2, (b), __t);				\
+	UNc_rb_ADD_UNc_rb (__r1, __r2, __t);				\
+									\
+	__r2 = (x) >> G_SHIFT;						\
+	__r3 = (a) >> G_SHIFT;						\
+	UNc_rb_MUL_UNc_rb (__r2, __r3, __t);				\
+	__r3 = (y) >> G_SHIFT;						\
+	UNc_rb_MUL_UNc (__r3, (b), __t);				\
+	UNc_rb_ADD_UNc_rb (__r2, __r3, __t);				\
+									\
+	x = __r1 | (__r2 << G_SHIFT);					\
     } while (0)
 
 /*
-   x_c = min(x_c + y_c, 255)
- */
+  x_c = min(x_c + y_c, 255)
+*/
 #define UNcx4_ADD_UNcx4(x, y)						\
     do									\
     {									\
-	comp4_t r1, r2, r3, t;						\
+	comp4_t __r1, __r2, __r3, __t;					\
 									\
-	r1 = x & RB_MASK;						\
-	r2 = y & RB_MASK;						\
-	UNc_rb_ADD_UNc_rb (r1, r2, t);					\
+	__r1 = (x) & RB_MASK;						\
+	__r2 = (y) & RB_MASK;						\
+	UNc_rb_ADD_UNc_rb (__r1, __r2, __t);				\
 									\
-	r2 = (x >> G_SHIFT) & RB_MASK;					\
-	r3 = (y >> G_SHIFT) & RB_MASK;					\
-	UNc_rb_ADD_UNc_rb (r2, r3, t);					\
+	__r2 = ((x) >> G_SHIFT) & RB_MASK;				\
+	__r3 = ((y) >> G_SHIFT) & RB_MASK;				\
+	UNc_rb_ADD_UNc_rb (__r2, __r3, __t);				\
 									\
-	x = r1 | (r2 << G_SHIFT);					\
+	x = __r1 | (__r2 << G_SHIFT);					\
     } while (0)
-- 
1.6.0.6



More information about the Pixman mailing list