> > I created the patches.
> > It become a little bit more complicated than I expected, to
> > avoid duplicated inclusion independently in each of namespace
> > polluted part and non polluted part.
>
> Now I don't like this for a quick fix :-). It is more complicated than
> a correct fix.
>
> I think it would be OK without any anti-redefinition ifdefs. Redefinition
> is only a micro-pessimization since there are only #define's (no
> typedefs, etc.) and won't occur often since <machine/param.h> should only
> be included by <sys/param.h>, <sys/pipe.h> and <sys/socket.h>. Reinclusion
> can be optimized in the including file using e.g. #ifndef _ALIGN in
> <sys/socket.h>.
I once tried more simpler patches, but then I had a build
problem at sbin/ipfw/ipfw.c. It includes <sys/socket.h> before
<sys/param.h>, so <machine/param.h> is once included via
<sys/socket.h> but namespace non-polluted part only.
Then it is re-included via <sys/param.h>, but nothing actually
included due to anti-redefiition ifdefs. And build failed
because the file needs namespace polluted definitions in
<machie/param.h>.
This seems to be difficult issue, and some considration in
<machine/param.h> seems to be inevitable.
This time I created less complicated patches, which define
namespace non-polluted macros outside of anti-redefiition
ifdefs for the file. But each such namespace non-polluted
macros have each anti-redefinition ifdef itself.
Yoshinobu Inoue
Index: sys/socket.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/socket.h,v
retrieving revision 1.39
diff -u -r1.39 socket.h
--- sys/socket.h 2000/03/11 19:51:04 1.39
+++ sys/socket.h 2000/04/01 20:40:30
@@ -37,6 +37,14 @@
#ifndef _SYS_SOCKET_H_
#define _SYS_SOCKET_H_
+#ifdef _NO_NAMESPACE_POLLUTION
+#include <machine/param.h>
+#else
+#define _NO_NAMESPACE_POLLUTION
+#include <machine/param.h>
+#undef _NO_NAMESPACE_POLLUTION
+#endif
+
/*
* Definitions related to sockets: types, address families, options.
*/
@@ -352,20 +360,20 @@
/* given pointer to struct cmsghdr, return pointer to data */
#define CMSG_DATA(cmsg) ((u_char *)(cmsg) + \
- ALIGN(sizeof(struct cmsghdr)))
+ _ALIGN(sizeof(struct cmsghdr)))
/* given pointer to struct cmsghdr, return pointer to next cmsghdr */
#define CMSG_NXTHDR(mhdr, cmsg) \
- (((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len) + \
- ALIGN(sizeof(struct cmsghdr)) > \
+ (((caddr_t)(cmsg) + _ALIGN((cmsg)->cmsg_len) + \
+ _ALIGN(sizeof(struct cmsghdr)) > \
(caddr_t)(mhdr)->msg_control + (mhdr)->msg_controllen) ? \
(struct cmsghdr *)NULL : \
- (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len)))
+ (struct cmsghdr *)((caddr_t)(cmsg) + _ALIGN((cmsg)->cmsg_len)))
#define CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control)
-#define CMSG_SPACE(l) (ALIGN(sizeof(struct cmsghdr)) + ALIGN(l))
-#define CMSG_LEN(l) (ALIGN(sizeof(struct cmsghdr)) + (l))
+#define CMSG_SPACE(l) (_ALIGN(sizeof(struct cmsghdr)) + _ALIGN(l))
+#define CMSG_LEN(l) (_ALIGN(sizeof(struct cmsghdr)) + (l))
/* "Socket"-level control message types: */
#define SCM_RIGHTS 0x01 /* access rights (array of int) */
Index: i386/include/param.h
===================================================================
RCS file: /home/ncvs/src/sys/i386/include/param.h,v
retrieving revision 1.55
diff -u -r1.55 param.h
--- i386/include/param.h 2000/03/29 05:39:04 1.55
+++ i386/include/param.h 2000/04/01 20:40:31
@@ -37,8 +37,17 @@
* $FreeBSD: src/sys/i386/include/param.h,v 1.55 2000/03/29 05:39:04 jlemon Exp $
*/
-#ifndef _MACHINE_PARAM_H_
-#define _MACHINE_PARAM_H_
+/*
+ * Round p (pointer or byte index) up to a correctly-aligned value
+ * for all data types (int, long, ...). The result is unsigned int
+ * and must be cast to any desired pointer type.
+ */
+#ifndef _ALIGNBYTES
+#define _ALIGNBYTES (sizeof(int) - 1)
+#endif
+#ifndef _ALIGN
+#define _ALIGN(p) (((unsigned)(p) + _ALIGNBYTES) & ~_ALIGNBYTES)
+#endif
/*
* Machine dependent constants for Intel 386.
@@ -46,12 +55,21 @@
#ifndef _MACHINE
#define _MACHINE i386
#endif
-#ifndef MACHINE
-#define MACHINE "i386"
-#endif
#ifndef _MACHINE_ARCH
#define _MACHINE_ARCH i386
#endif
+
+#ifndef _NO_NAMESPACE_POLLUTION
+
+#ifndef _MACHINE_PARAM_H_
+#define _MACHINE_PARAM_H_
+
+/*
+ * Machine dependent constants for Intel 386.
+ */
+#ifndef MACHINE
+#define MACHINE "i386"
+#endif
#ifndef MACHINE_ARCH
#define MACHINE_ARCH "i386"
#endif
@@ -70,13 +88,8 @@
#define NCPUS 1
#endif
-/*
- * Round p (pointer or byte index) up to a correctly-aligned value
- * for all data types (int, long, ...). The result is unsigned int
- * and must be cast to any desired pointer type.
- */
-#define ALIGNBYTES (sizeof(int) - 1)
-#define ALIGN(p) (((unsigned)(p) + ALIGNBYTES) & ~ALIGNBYTES)
+#define ALIGNBYTES _ALIGNBYTES
+#define ALIGN(p) _ALIGN(p)
#define PAGE_SHIFT 12 /* LOG2(PAGE_SIZE) */
#define PAGE_SIZE (1<<PAGE_SHIFT) /* bytes/page */
@@ -158,3 +171,4 @@
#define pgtok(x) ((x) * (PAGE_SIZE / 1024))
#endif /* !_MACHINE_PARAM_H_ */
+#endif /* !_NO_NAMESPACE_POLLUTION */
Index: alpha/include/param.h
===================================================================
RCS file: /home/ncvs/src/sys/alpha/include/param.h,v
retrieving revision 1.17
diff -u -r1.17 param.h
--- alpha/include/param.h 2000/02/29 08:48:10 1.17
+++ alpha/include/param.h 2000/04/01 20:40:31
@@ -44,17 +44,47 @@
*/
/*
+ * Round p (pointer or byte index) up to a correctly-aligned value for all
+ * data types (int, long, ...). The result is u_long and must be cast to
+ * any desired pointer type.
+ *
+ * ALIGNED_POINTER is a boolean macro that checks whether an address
+ * is valid to fetch data elements of type t from on this architecture.
+ * This does not reflect the optimal alignment, just the possibility
+ * (within reasonable limits).
+ *
+ */
+#ifndef _ALIGNBYTES
+#define _ALIGNBYTES 7
+#endif
+#ifndef _ALIGN
+#define _ALIGN(p) (((u_long)(p) + _ALIGNBYTES) &~ _ALIGNBYTES)
+#endif
+#ifndef _ALIGNED_POINTER
+#define _ALIGNED_POINTER(p,t) ((((u_long)(p)) & (sizeof(t)-1)) == 0)
+#endif
+
+/*
* Machine dependent constants for the Alpha.
*/
#ifndef _MACHINE
#define _MACHINE alpha
#endif
-#ifndef MACHINE
-#define MACHINE "alpha"
-#endif
#ifndef _MACHINE_ARCH
#define _MACHINE_ARCH alpha
#endif
+
+#ifndef _NO_NAMESPACE_POLLUTION
+
+#ifndef _MACHINE_PARAM_H_
+#define _MACHINE_PARAM_H_
+
+/*
+ * Machine dependent constants for the Alpha.
+ */
+#ifndef MACHINE
+#define MACHINE "alpha"
+#endif
#ifndef MACHINE_ARCH
#define MACHINE_ARCH "alpha"
#endif
@@ -72,20 +102,9 @@
#define NCPUS 1
-/*
- * Round p (pointer or byte index) up to a correctly-aligned value for all
- * data types (int, long, ...). The result is u_long and must be cast to
- * any desired pointer type.
- *
- * ALIGNED_POINTER is a boolean macro that checks whether an address
- * is valid to fetch data elements of type t from on this architecture.
- * This does not reflect the optimal alignment, just the possibility
- * (within reasonable limits).
- *
- */
-#define ALIGNBYTES 7
-#define ALIGN(p) (((u_long)(p) + ALIGNBYTES) &~ ALIGNBYTES)
-#define ALIGNED_POINTER(p,t) ((((u_long)(p)) & (sizeof(t)-1)) == 0)
+#define ALIGNBYTES _ALIGNBYTES
+#define ALIGN(p) _ALIGN(p)
+#define ALIGNED_POINTER(p,t) _ALIGNED_POINTER(p,t)
#define PAGE_SIZE (1 << ALPHA_PGSHIFT) /* bytes/page */
#define PAGE_SHIFT ALPHA_PGSHIFT
@@ -161,3 +180,6 @@
#define alpha_ptob(x) ((unsigned long)(x) << PAGE_SHIFT)
#define pgtok(x) ((x) * (PAGE_SIZE / 1024))
+
+#endif /* !_MACHINE_PARAM_H_ */
+#endif /* !_NO_NAMESPACE_POLLUTION */