[PATCH] Use anonymous unions and structs to organize shared space instead of preprocessor macros.

Tiwei Bie btw at mail.ustc.edu.cn
Wed Feb 18 08:32:15 UTC 2015


Hi all,

Similar to r278920 [1], the preprocessor macros are converted into
anonymous unions and structs in buf, devreq, file, sigio, vnode, xvnode
and uma_slab.

[1] http://svnweb.freebsd.org/base?view=revision&revision=278920

---
 sys/sys/buf.h    |  8 +++-----
 sys/sys/bus.h    |  8 +++-----
 sys/sys/file.h   |  9 +++------
 sys/sys/sigio.h  |  8 +++-----
 sys/sys/vnode.h  | 34 ++++++++++++----------------------
 sys/vm/uma_int.h |  9 +++------
 6 files changed, 27 insertions(+), 49 deletions(-)

diff --git a/sys/sys/buf.h b/sys/sys/buf.h
index 71ef74f..7324f90 100644
--- a/sys/sys/buf.h
+++ b/sys/sys/buf.h
@@ -124,14 +124,12 @@ struct buf {
 	struct	ucred *b_wcred;		/* Write credentials reference. */
 	void	*b_saveaddr;		/* Original b_addr for physio. */
 	union {
-		TAILQ_ENTRY(buf) bu_freelist; /* (Q) */
+		TAILQ_ENTRY(buf) b_freelist; /* (Q) */
 		struct {
 			void	(*pg_iodone)(void *, vm_page_t *, int, int);
 			int	pg_reqpage;
-		} bu_pager;
-	} b_union;
-#define	b_freelist	b_union.bu_freelist
-#define	b_pager         b_union.bu_pager
+		} b_pager;
+	};
 	union	cluster_info {
 		TAILQ_HEAD(cluster_list_head, buf) cluster_head;
 		TAILQ_ENTRY(buf) cluster_entry;
diff --git a/sys/sys/bus.h b/sys/sys/bus.h
index d6dc535..e76b2ca 100644
--- a/sys/sys/bus.h
+++ b/sys/sys/bus.h
@@ -102,11 +102,9 @@ struct devreq {
 	char		dr_name[128];
 	int		dr_flags;		/* request-specific flags */
 	union {
-		struct devreq_buffer dru_buffer;
-		void	*dru_data;
-	} dr_dru;
-#define	dr_buffer	dr_dru.dru_buffer	/* variable-sized buffer */
-#define	dr_data		dr_dru.dru_data		/* fixed-size buffer */
+		struct devreq_buffer dr_buffer;	/* variable-sized buffer */
+		void	*dr_data;		/* fixed-size buffer */
+	};
 };
 
 #define	DEV_ATTACH	_IOW('D', 1, struct devreq)
diff --git a/sys/sys/file.h b/sys/sys/file.h
index 1538851..4ac62b9 100644
--- a/sys/sys/file.h
+++ b/sys/sys/file.h
@@ -173,10 +173,10 @@ struct file {
 	int		f_seqcount;	/* (a) Count of sequential accesses. */
 	off_t		f_nextoff;	/* next expected read/write offset. */
 	union {
-		struct cdev_privdata *fvn_cdevpriv;
+		struct cdev_privdata *f_cdevpriv;
 					/* (d) Private data for the cdev. */
-		struct fadvise_info *fvn_advice;
-	} f_vnun;
+		struct fadvise_info *f_advice;
+	};
 	/*
 	 *  DFLAG_SEEKABLE specific fields
 	 */
@@ -187,9 +187,6 @@ struct file {
 	void		*f_label;	/* Place-holder for MAC label. */
 };
 
-#define	f_cdevpriv	f_vnun.fvn_cdevpriv
-#define	f_advice	f_vnun.fvn_advice
-
 #define	FOFFSET_LOCKED       0x1
 #define	FOFFSET_LOCK_WAITING 0x2
 #define	FDEVFS_VNODE	     0x4
diff --git a/sys/sys/sigio.h b/sys/sys/sigio.h
index 62ece6d..fc84154 100644
--- a/sys/sys/sigio.h
+++ b/sys/sys/sigio.h
@@ -45,17 +45,15 @@
  */
 struct sigio {
 	union {
-		struct	proc *siu_proc; /* (c)	process to receive SIGIO/SIGURG */
-		struct	pgrp *siu_pgrp; /* (c)	process group to receive ... */
-	} sio_u;
+		struct	proc *sio_proc; /* (c)	process to receive SIGIO/SIGURG */
+		struct	pgrp *sio_pgrp; /* (c)	process group to receive ... */
+	};
 	SLIST_ENTRY(sigio) sio_pgsigio;	/* (pg)	sigio's for process or group */
 	struct	sigio **sio_myref;	/* (c)	location of the pointer that holds
 					 * 	the reference to this structure */
 	struct	ucred *sio_ucred;	/* (c)	current credentials */
 	pid_t	sio_pgid;		/* (c)	pgid for signals */
 };
-#define	sio_proc	sio_u.siu_proc
-#define	sio_pgrp	sio_u.siu_pgrp
 
 SLIST_HEAD(sigiolst, sigio);
 
diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h
index 8a14f69..ff7f13f 100644
--- a/sys/sys/vnode.h
+++ b/sys/sys/vnode.h
@@ -114,11 +114,11 @@ struct vnode {
 	 * See #defines below for renaming to v_* namespace.
 	 */
 	union {
-		struct mount	*vu_mount;	/* v ptr to mountpoint (VDIR) */
-		struct socket	*vu_socket;	/* v unix domain net (VSOCK) */
-		struct cdev	*vu_cdev; 	/* v device (VCHR, VBLK) */
-		struct fifoinfo	*vu_fifoinfo;	/* v fifo (VFIFO) */
-	} v_un;
+		struct mount	*v_mountedhere;	/* v ptr to mountpoint (VDIR) */
+		struct socket	*v_socket;	/* v unix domain net (VSOCK) */
+		struct cdev	*v_rdev; 	/* v device (VCHR, VBLK) */
+		struct fifoinfo	*v_fifoinfo;	/* v fifo (VFIFO) */
+	};
 
 	/*
 	 * vfs_hash: (mount + inode) -> vnode hash.  The hash value
@@ -173,11 +173,6 @@ struct vnode {
 
 #endif /* defined(_KERNEL) || defined(_KVM_VNODE) */
 
-#define	v_mountedhere	v_un.vu_mount
-#define	v_socket	v_un.vu_socket
-#define	v_rdev		v_un.vu_cdev
-#define	v_fifoinfo	v_un.vu_fifoinfo
-
 /* XXX: These are temporary to avoid a source sweep at this time */
 #define v_object	v_bufobj.bo_object
 
@@ -196,20 +191,15 @@ struct xvnode {
 	long	xv_numoutput;			/* num of writes in progress */
 	enum	vtype xv_type;			/* vnode type */
 	union {
-		void	*xvu_socket;		/* socket, if VSOCK */
-		void	*xvu_fifo;		/* fifo, if VFIFO */
-		dev_t	xvu_rdev;		/* maj/min, if VBLK/VCHR */
+		void	*xv_socket;		/* socket, if VSOCK */
+		void	*xv_fifo;		/* fifo, if VFIFO */
+		dev_t	xv_rdev;		/* maj/min, if VBLK/VCHR */
 		struct {
-			dev_t	xvu_dev;	/* device, if VDIR/VREG/VLNK */
-			ino_t	xvu_ino;	/* id, if VDIR/VREG/VLNK */
-		} xv_uns;
-	} xv_un;
+			dev_t	xv_dev;		/* device, if VDIR/VREG/VLNK */
+			ino_t	xv_ino;		/* id, if VDIR/VREG/VLNK */
+		};
+	};
 };
-#define xv_socket	xv_un.xvu_socket
-#define xv_fifo		xv_un.xvu_fifo
-#define xv_rdev		xv_un.xvu_rdev
-#define xv_dev		xv_un.xv_uns.xvu_dev
-#define xv_ino		xv_un.xv_uns.xvu_ino
 
 /* We don't need to lock the knlist */
 #define	VN_KNLIST_EMPTY(vp) ((vp)->v_pollinfo == NULL ||	\
diff --git a/sys/vm/uma_int.h b/sys/vm/uma_int.h
index 1ffc7d5..dff24be 100644
--- a/sys/vm/uma_int.h
+++ b/sys/vm/uma_int.h
@@ -231,9 +231,9 @@ BITSET_DEFINE(slabbits, SLAB_SETSIZE);
 struct uma_slab {
 	uma_keg_t	us_keg;			/* Keg we live in */
 	union {
-		LIST_ENTRY(uma_slab)	_us_link;	/* slabs in zone */
-		unsigned long	_us_size;	/* Size of allocation */
-	} us_type;
+		LIST_ENTRY(uma_slab)	us_link;	/* slabs in zone */
+		unsigned long	us_size;	/* Size of allocation */
+	};
 	SLIST_ENTRY(uma_slab)	us_hlink;	/* Link for hash table */
 	uint8_t		*us_data;		/* First item */
 	struct slabbits	us_free;		/* Free bitmask. */
@@ -245,9 +245,6 @@ struct uma_slab {
 	uint8_t		us_pad;			/* Pad to 32bits, unused. */
 };
 
-#define	us_link	us_type._us_link
-#define	us_size	us_type._us_size
-
 /*
  * The slab structure for UMA_ZONE_REFCNT zones for whose items we
  * maintain reference counters in the slab for.
-- 
2.1.2

Tiwei Bie



More information about the freebsd-hackers mailing list