[MPlayer-dev-eng] [PATCH] encapsulating #define arguments

Moritz Bunkus moritz at bunkus.org
Mon Jan 13 14:38:25 CET 2003


Hi.

This patch encapsulates arguments for #define in ( ) like

#define min(a,b) (a<b?a:b) 

-->

#define min(a,b) ((a)<(b)?(a):(b))

That way all #defines can be safely used just like functions can.
Fabian ran into such a problem yesterday because he was using

mp_msg(MSGT_.., force ? MSGL_ERR : MSGL_V, ...);

and it always resulted in MSGL_ERR being used.

-- 
 ==> Ciao, Mosu (Moritz Bunkus)
-------------- next part --------------
Index: asxparser.h
===================================================================
RCS file: /cvsroot/mplayer/main/asxparser.h,v
retrieving revision 1.4
diff -u -r1.4 asxparser.h
--- asxparser.h	12 Nov 2002 14:19:53 -0000	1.4
+++ asxparser.h	12 Jan 2003 11:20:35 -0000
@@ -39,7 +39,7 @@
 int
 asx_attrib_to_enum(char* val,char** valid_vals);
 
-#define asx_free_attribs(a) asx_list_free((void***)&a,free)
+#define asx_free_attribs(a) asx_list_free((void***)&(a),free)
 
 ////// List utils
 
Index: m_struct.h
===================================================================
RCS file: /cvsroot/mplayer/main/m_struct.h,v
retrieving revision 1.1
diff -u -r1.1 m_struct.h
--- m_struct.h	12 Nov 2002 14:16:30 -0000	1.1
+++ m_struct.h	12 Jan 2003 11:20:35 -0000
@@ -20,11 +20,11 @@
 
 // From glib.h (modified ;-)
 #define M_ST_OFF(struct_type, member)    \
-    ((void*) &((struct_type*) 0)->member)
+    ((void*) &(((struct_type)*) 0)->(member))
 #define M_ST_MB_P(struct_p, struct_offset)   \
     ((void*) (struct_p) + (unsigned long) (struct_offset))
 #define M_ST_MB(member_type, struct_p, struct_offset)   \
-    (*(member_type*) M_STRUCT_MEMBER_P ((struct_p), (struct_offset)))
+    (*((member_type)*) M_STRUCT_MEMBER_P ((struct_p), (struct_offset)))
 
 
 
Index: mp_msg.h
===================================================================
RCS file: /cvsroot/mplayer/main/mp_msg.h,v
retrieving revision 1.25
diff -u -r1.25 mp_msg.h
--- mp_msg.h	1 Oct 2002 06:45:08 -0000	1.25
+++ mp_msg.h	12 Jan 2003 11:20:38 -0000
@@ -93,7 +93,7 @@
 
 #ifdef TARGET_OS2
 // va_start/vsnprintf seems to be broken under OS2 :(
-#define mp_msg(mod,lev, fmt, args... ) do{if(lev<=mp_msg_levels[mod]) printf( fmt, ## args );}while(0)
+#define mp_msg(mod,lev, fmt, args... ) do{if((lev)<=mp_msg_levels[mod]) printf( fmt, ## args );}while(0)
 #define mp_dbg(mod,lev, args... ) 
 #else
 
@@ -108,19 +108,19 @@
 void mp_msg_c( int x, const char *format, ... );
 
 #ifdef __GNUC__
-#define mp_msg(mod,lev, args... ) mp_msg_c((mod<<8)|lev, ## args )
+#define mp_msg(mod,lev, args... ) mp_msg_c(((mod)<<8)|(lev), ## args )
 
 #ifdef MP_DEBUG
-#define mp_dbg(mod,lev, args... ) mp_msg_c((mod<<8)|lev, ## args )
+#define mp_dbg(mod,lev, args... ) mp_msg_c(((mod)<<8)|(lev), ## args )
 #else
 // these messages are only usefull for developers, disable them
 #define mp_dbg(mod,lev, args... ) 
 #endif
 #else // not GNU C
-#define mp_msg(mod,lev, ... ) mp_msg_c((mod<<8)|lev, __VA_ARGS__)
+#define mp_msg(mod,lev, ... ) mp_msg_c(((mod)<<8)|(lev), __VA_ARGS__)
 
 #ifdef MP_DEBUG
-#define mp_dbg(mod,lev, ... ) mp_msg_c((mod<<8)|lev, __VA_ARGS__)
+#define mp_dbg(mod,lev, ... ) mp_msg_c(((mod)<<8)|(lev), __VA_ARGS__)
 #else
 // these messages are only usefull for developers, disable them
 #define mp_dbg(mod,lev, ... ) 
Index: Gui/interface.h
===================================================================
RCS file: /cvsroot/mplayer/main/Gui/interface.h,v
retrieving revision 1.33
diff -u -r1.33 interface.h
--- Gui/interface.h	11 Dec 2002 01:21:08 -0000	1.33
+++ Gui/interface.h	12 Jan 2003 11:20:40 -0000
@@ -203,13 +203,13 @@
 extern void   gaddlist( char *** list,char * entry );
 extern char * gstrchr( char * str,int c );
 
-#define guiSetFilename( s,n ) { gfree( (void **)&s ); s=gstrdup( n ); }
+#define guiSetFilename( s,n ) { gfree( (void **)&(s) ); s=gstrdup( n ); }
 
 #define guiSetDF( s,d,n )                       \
  {                                              \
-  gfree( (void **)&s );                          \
+  gfree( (void **)&(s) );                       \
   s=malloc( strlen( d ) + strlen( n ) + 5 );    \
-  sprintf( s,"%s/%s",d,n );                     \
+  sprintf( (s),"%s/%s",(d),(n) );               \
  }
 
 #endif
Index: Gui/wm/ws.h
===================================================================
RCS file: /cvsroot/mplayer/main/Gui/wm/ws.h,v
retrieving revision 1.24
diff -u -r1.24 ws.h
--- Gui/wm/ws.h	9 Jan 2003 20:47:12 -0000	1.24
+++ Gui/wm/ws.h	12 Jan 2003 11:20:40 -0000
@@ -219,7 +219,7 @@
 extern void wsSetBackground( wsTWindow * win,int color );
 extern void wsSetForegroundRGB( wsTWindow * win,int r,int g,int b );
 extern void wsSetBackgroundRGB( wsTWindow * win,int r,int g,int b );
-#define wsClearWindow( win ) XClearWindow( wsDisplay,win.WindowID )
+#define wsClearWindow( win ) XClearWindow( wsDisplay,(win).WindowID )
 extern void wsSetTitle( wsTWindow * win,char * name );
 extern void wsVisibleWindow( wsTWindow * win,int show );
 extern void wsWindowDecoration( wsTWindow * win,long d );
@@ -254,7 +254,7 @@
 extern void wsScreenSaverOn( Display *mDisplay );
 extern void wsScreenSaverOff( Display * mDisplay );
 
-#define wgIsRect( X,Y,tX,tY,bX,bY ) ( ( X > tX )&&( Y > tY )&&( X < bX )&&( Y < bY ) )
+#define wgIsRect( X,Y,tX,tY,bX,bY ) ( ( (X) > (tX) )&&( (Y) > (tY) )&&( (X) < (bX) )&&( (Y) < (bY) ) )
 
 #endif
 
Index: Gui/wm/wsxdnd.h
===================================================================
RCS file: /cvsroot/mplayer/main/Gui/wm/wsxdnd.h,v
retrieving revision 1.1
diff -u -r1.1 wsxdnd.h
--- Gui/wm/wsxdnd.h	11 Aug 2002 13:12:38 -0000	1.1
+++ Gui/wm/wsxdnd.h	12 Jan 2003 11:20:42 -0000
@@ -17,7 +17,7 @@
 #define XDND_ENTER_THREE_TYPES_SET(e,b)	(e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~0x1UL) | (((b) == 0) ? 0 : 0x1UL)
 #define XDND_ENTER_VERSION(e)		((e)->xclient.data.l[1] >> 24)
 #define XDND_ENTER_VERSION_SET(e,v)	(e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~(0xFF << 24)) | ((v) << 24)
-#define XDND_ENTER_TYPE(e,i)		((e)->xclient.data.l[2 + i])	/* i => (0, 1, 2) */
+#define XDND_ENTER_TYPE(e,i)		((e)->xclient.data.l[2 + (i)])	/* i => (0, 1, 2) */
 
 /* XdndPosition */
 #define XDND_POSITION_SOURCE_WIN(e)	((e)->xclient.data.l[0])
Index: drivers/radeon/radeon_vid.h
===================================================================
RCS file: /cvsroot/mplayer/main/drivers/radeon/radeon_vid.h,v
retrieving revision 1.4
diff -u -r1.4 radeon_vid.h
--- drivers/radeon/radeon_vid.h	20 Jun 2002 14:37:09 -0000	1.4
+++ drivers/radeon/radeon_vid.h	12 Jan 2003 11:20:42 -0000
@@ -52,11 +52,11 @@
 #define IMGFMT_BGR24 (IMGFMT_BGR|24)
 #define IMGFMT_BGR32 (IMGFMT_BGR|32)
 
-#define IMGFMT_IS_RGB(fmt) ((fmt&IMGFMT_RGB_MASK)==IMGFMT_RGB)
-#define IMGFMT_IS_BGR(fmt) ((fmt&IMGFMT_BGR_MASK)==IMGFMT_BGR)
+#define IMGFMT_IS_RGB(fmt) (((fmt)&IMGFMT_RGB_MASK)==IMGFMT_RGB)
+#define IMGFMT_IS_BGR(fmt) (((fmt)&IMGFMT_BGR_MASK)==IMGFMT_BGR)
 
-#define IMGFMT_RGB_DEPTH(fmt) (fmt&~IMGFMT_RGB)
-#define IMGFMT_BGR_DEPTH(fmt) (fmt&~IMGFMT_BGR)
+#define IMGFMT_RGB_DEPTH(fmt) ((fmt)&~IMGFMT_RGB)
+#define IMGFMT_BGR_DEPTH(fmt) ((fmt)&~IMGFMT_BGR)
 
 
 /* Planar YUV Formats */
Index: libaf/af.h
===================================================================
RCS file: /cvsroot/mplayer/main/libaf/af.h,v
retrieving revision 1.16
diff -u -r1.16 af.h
--- libaf/af.h	10 Jan 2003 01:45:34 -0000	1.16
+++ libaf/af.h	12 Jan 2003 11:20:42 -0000
@@ -201,7 +201,7 @@
    filter doesn't operate on the incoming buffer this macro must be
    called to ensure the buffer is big enough. */
 #define RESIZE_LOCAL_BUFFER(a,d)\
-((a->data->len < af_lencalc(a->mul,d))?af_resize_local_buffer(a,d):AF_OK)
+(((a)->data->len < af_lencalc((a)->mul,d))?af_resize_local_buffer(a,d):AF_OK)
 
 /* Some other useful macro definitions*/
 #ifndef min
@@ -247,8 +247,8 @@
 /* Macro for printing error messages */
 #ifndef af_msg
 #define af_msg(lev, args... ) \
-((lev<AF_MSG_WARN)?(fprintf(af_msg_cfg.err?af_msg_cfg.err:stderr, ## args )): \
-((lev<=af_msg_cfg.level)?(fprintf(af_msg_cfg.msg?af_msg_cfg.msg:stdout, ## args )):0))
+(((lev)<AF_MSG_WARN)?(fprintf(af_msg_cfg.err?af_msg_cfg.err:stderr, ## args )): \
+(((lev)<=af_msg_cfg.level)?(fprintf(af_msg_cfg.msg?af_msg_cfg.msg:stdout, ## args )):0))
 #endif
 
 #endif /* __aop_h__ */
Index: libaf/af_mp.h
===================================================================
RCS file: /cvsroot/mplayer/main/libaf/af_mp.h,v
retrieving revision 1.2
diff -u -r1.2 af_mp.h
--- libaf/af_mp.h	3 Jan 2003 12:36:14 -0000	1.2
+++ libaf/af_mp.h	12 Jan 2003 11:20:42 -0000
@@ -18,7 +18,7 @@
 #undef af_msg
 #endif
 #define af_msg(lev, args... ) \
-  mp_msg(MSGT_AFILTER,((lev<0)?(lev+3):((lev==0)?MSGL_INFO:(lev+5))), ##args )
+  mp_msg(MSGT_AFILTER,(((lev)<0)?((lev)+3):(((lev)==0)?MSGL_INFO:((lev)+5))), ##args )
 
 /* Decodes the format from mplayer format to libaf format */
 extern int af_format_decode(int format);
Index: libaf/af_resample.h
===================================================================
RCS file: /cvsroot/mplayer/main/libaf/af_resample.h,v
retrieving revision 1.1
diff -u -r1.1 af_resample.h
--- libaf/af_resample.h	28 Dec 2002 13:59:53 -0000	1.1
+++ libaf/af_resample.h	12 Jan 2003 11:20:42 -0000
@@ -47,8 +47,8 @@
 #define L   	8	// Filter length
 // Unrolled loop to speed up execution 
 #define FIR(x,w,y) \
-  (y[0])  = ( w[0]*x[0]+w[1]*x[1]+w[2]*x[2]+w[3]*x[3] \
-            + w[4]*x[4]+w[5]*x[5]+w[6]*x[6]+w[7]*x[7] ) SHIFT
+  ((y)[0]) = ( (w)[0]*(x)[0]+(w)[1]*(x)[1]+(w)[2]*(x)[2]+(w)[3]*(x)[3] \
+             + (w)[4]*(x)[4]+(w)[5]*(x)[5]+(w)[6]*(x)[6]+(w)[7]*(x)[7] ) SHIFT
 
 
 
@@ -57,17 +57,17 @@
 #define L   	16
 // Unrolled loop to speed up execution 
 #define FIR(x,w,y) \
-  y[0] = ( w[0] *x[0] +w[1] *x[1] +w[2] *x[2] +w[3] *x[3] \
-         + w[4] *x[4] +w[5] *x[5] +w[6] *x[6] +w[7] *x[7] \
-         + w[8] *x[8] +w[9] *x[9] +w[10]*x[10]+w[11]*x[11] \
-         + w[12]*x[12]+w[13]*x[13]+w[14]*x[14]+w[15]*x[15] ) SHIFT
+ (y)[0] = ( (w)[0] *(x)[0] +(w)[1] *(x)[1] +(w)[2] *(x)[2] +(w)[3] *(x)[3] \
+          + (w)[4] *(x)[4] +(w)[5] *(x)[5] +(w)[6] *(x)[6] +(w)[7] *(x)[7] \
+          + (w)[8] *(x)[8] +(w)[9] *(x)[9] +(w)[10]*(x)[10]+(w)[11]*(x)[11] \
+          + (w)[12]*(x)[12]+(w)[13]*(x)[13]+(w)[14]*(x)[14]+(w)[15]*(x)[15] ) SHIFT
 
 #endif /* L8/L16 */
 
 // Macro to add data to circular que 
 #define ADDQUE(xi,xq,in)\
-  xq[xi]=xq[xi+L]=(*in);\
-  xi=(xi-1)&(L-1);
+  (xq)[xi]=xq[(xi)+L]=(*(in));\
+  (xi)=((xi)-1)&(L-1);
 
 #if defined(UP)
 
Index: libaf/filter.h
===================================================================
RCS file: /cvsroot/mplayer/main/libaf/filter.h,v
retrieving revision 1.2
diff -u -r1.2 filter.h
--- libaf/filter.h	7 Jan 2003 10:33:30 -0000	1.2
+++ libaf/filter.h	12 Jan 2003 11:20:43 -0000
@@ -63,7 +63,7 @@
    long. 
 */
 #define updateq(n,xi,xq,in)\
-  xq[xi]=xq[xi+n]=*in;\
-  xi=(++xi)&(n-1);
+  (xq)[xi]=(xq)[(xi)+(n)]=*(in);\
+  (xi)=(++(xi))&((n)-1);
 
 #endif
Index: libmpcodecs/img_format.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/img_format.h,v
retrieving revision 1.8
diff -u -r1.8 img_format.h
--- libmpcodecs/img_format.h	1 Aug 2002 12:39:07 -0000	1.8
+++ libmpcodecs/img_format.h	12 Jan 2003 11:20:43 -0000
@@ -24,11 +24,11 @@
 #define IMGFMT_BGR24 (IMGFMT_BGR|24)
 #define IMGFMT_BGR32 (IMGFMT_BGR|32)
 
-#define IMGFMT_IS_RGB(fmt) ((fmt&IMGFMT_RGB_MASK)==IMGFMT_RGB)
-#define IMGFMT_IS_BGR(fmt) ((fmt&IMGFMT_BGR_MASK)==IMGFMT_BGR)
+#define IMGFMT_IS_RGB(fmt) (((fmt)&IMGFMT_RGB_MASK)==IMGFMT_RGB)
+#define IMGFMT_IS_BGR(fmt) (((fmt)&IMGFMT_BGR_MASK)==IMGFMT_BGR)
 
-#define IMGFMT_RGB_DEPTH(fmt) (fmt&~IMGFMT_RGB)
-#define IMGFMT_BGR_DEPTH(fmt) (fmt&~IMGFMT_BGR)
+#define IMGFMT_RGB_DEPTH(fmt) ((fmt)&~IMGFMT_RGB)
+#define IMGFMT_BGR_DEPTH(fmt) ((fmt)&~IMGFMT_BGR)
 
 
 /* Planar YUV Formats */
Index: libmpdemux/asf.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/asf.h,v
retrieving revision 1.17
diff -u -r1.17 asf.h
--- libmpdemux/asf.h	9 Jul 2002 08:23:47 -0000	1.17
+++ libmpdemux/asf.h	12 Jan 2003 11:20:43 -0000
@@ -6,7 +6,7 @@
 #include "bswap.h"
 
 #ifndef MIN
-#define MIN(a,b) ((a<b)?a:b)
+#define MIN(a,b) (((a)<(b))?(a):(b))
 #endif
 
 ///////////////////////
Index: libmpdemux/demuxer.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demuxer.h,v
retrieving revision 1.52
diff -u -r1.52 demuxer.h
--- libmpdemux/demuxer.h	22 Dec 2002 21:01:01 -0000	1.52
+++ libmpdemux/demuxer.h	12 Jan 2003 11:20:43 -0000
@@ -196,8 +196,8 @@
 
 #if 1
 #define demux_getc(ds) (\
-     (ds->buffer_pos<ds->buffer_size) ? ds->buffer[ds->buffer_pos++] \
-     :((!ds_fill_buffer(ds))? (-1) : ds->buffer[ds->buffer_pos++] ) )
+     ((ds)->buffer_pos<(ds)->buffer_size) ? (ds)->buffer[(ds)->buffer_pos++] \
+     :((!ds_fill_buffer(ds))? (-1) : (ds)->buffer[(ds)->buffer_pos++] ) )
 #else
 inline static int demux_getc(demux_stream_t *ds){
   if(ds->buffer_pos>=ds->buffer_size){
Index: libmpeg2/attributes.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpeg2/attributes.h,v
retrieving revision 1.2
diff -u -r1.2 attributes.h
--- libmpeg2/attributes.h	4 Mar 2001 21:01:53 -0000	1.2
+++ libmpeg2/attributes.h	12 Jan 2003 11:20:45 -0000
@@ -21,7 +21,7 @@
 
 /* use gcc attribs to align critical data structures */
 #ifdef ATTRIBUTE_ALIGNED_MAX
-#define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
+#define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < (align)) ? ATTRIBUTE_ALIGNED_MAX : (align))))
 #else
 #define ATTR_ALIGN(align)
 #endif
Index: vidix/drivers/cyberblade_regs.h
===================================================================
RCS file: /cvsroot/mplayer/main/vidix/drivers/cyberblade_regs.h,v
retrieving revision 1.2
diff -u -r1.2 cyberblade_regs.h
--- vidix/drivers/cyberblade_regs.h	3 Jan 2003 12:26:17 -0000	1.2
+++ vidix/drivers/cyberblade_regs.h	12 Jan 2003 11:20:45 -0000
@@ -129,10 +129,10 @@
 
 int HACKBUCKET12345678;  /* Horrible hack to work around cache/speed issue */
 
-#define INB(addr) (HACKBUCKET12345678=*(cyberblade_reg_base+addr))
-#define INW(addr) (HACKBUCKET12345678=*(unsigned short *)(cyberblade_reg_base+addr))
-#define OUTB(addr,val) (*(cyberblade_reg_base+addr)=(val))
-#define OUTW(addr,val) (*(unsigned short *)(cyberblade_reg_base+addr)=(val))
+#define INB(addr) (HACKBUCKET12345678=*(cyberblade_reg_base+(addr)))
+#define INW(addr) (HACKBUCKET12345678=*(unsigned short *)(cyberblade_reg_base+(addr)))
+#define OUTB(addr,val) (*(cyberblade_reg_base+(addr))=(val))
+#define OUTW(addr,val) (*(unsigned short *)(cyberblade_reg_base+(addr))=(val))
 
 #define SRINB(reg) (OUTB(0x3c4,reg), INB(0x3c5))
 #define SROUTB(reg,val) (OUTW(0x3c4,((val)<<8)|(reg)))
Index: vidix/drivers/pm3_regs.h
===================================================================
RCS file: /cvsroot/mplayer/main/vidix/drivers/pm3_regs.h,v
retrieving revision 1.1
diff -u -r1.1 pm3_regs.h
--- vidix/drivers/pm3_regs.h	31 May 2002 23:17:43 -0000	1.1
+++ vidix/drivers/pm3_regs.h	12 Jan 2003 11:20:46 -0000
@@ -1060,10 +1060,10 @@
 extern void *pm3_reg_base;
 
 #define WRITE_REG(offset,val)				\
-    *(volatile unsigned long *)(((unsigned char *)(pm3_reg_base)) + offset) = (val)
+    *(volatile unsigned long *)(((unsigned char *)(pm3_reg_base)) + (offset)) = (val)
 	
 #define READ_REG(offset)					\
-    *(volatile unsigned long *)(((unsigned char *)(pm3_reg_base)) + offset)
+    *(volatile unsigned long *)(((unsigned char *)(pm3_reg_base)) + (offset))
 
 #define UPDATE_SET_REG(offset,val)				\
     {								\
@@ -1094,8 +1094,8 @@
 
 #define RAMDAC_SET_INDEX(index)					\
 {								\
-    SLOW_WRITE_REG (PM3RD_IndexHigh,(index>>8)&0xff);		\
-    SLOW_WRITE_REG (PM3RD_IndexLow,index&0xff);			\
+    SLOW_WRITE_REG (PM3RD_IndexHigh,((index)>>8)&0xff);		\
+    SLOW_WRITE_REG (PM3RD_IndexLow,(index)&0xff);			\
 }
 
 #define RAMDAC_SET_REG(index, data)				\


More information about the MPlayer-dev-eng mailing list