This is the mail archive of the glibc-cvs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[glibc/zack/no-nested-includes] Don’t include sys/types.h or stdint.h n/n: bits headers


https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=bdd7907a7f11844fa4c3d1ea38f8d0c5c4f9cede

commit bdd7907a7f11844fa4c3d1ea38f8d0c5c4f9cede
Author: Zack Weinberg <zackw@panix.com>
Date:   Wed Jun 5 08:24:27 2019 -0400

    Donâ??t include sys/types.h or stdint.h n/n: bits headers
    
    Itâ??s especially troublesome for bits headers to include headers that
    define unrelated public symbols, because it means whether or not
    youâ??re getting e.g. sys/types.h when you include fcntl.h is
    architecture- and/or OS-specific.
    
    I suspect we do not need as many copies of bits/fcntl.h and bits/sem.h
    as we have, but thatâ??s complicated enough that it deserves its own patchset.
    
    	* bits/fcntl.h: Add multiple include guard.  Hoist inclusion of
    	bits/types.h to top of file.
    	* sysdeps/mach/hurd/bits/fcntl.h: Add multiple include guard.
    	Include bits/types.h, not sys/types.h; remove redundant inclusion
    	of bits/types.h in middle of file.
    
    	* bits/sem.h: Add multiple include guard.  Include bits/types.h,
    	not sys/types.h.
    	* sysdeps/gnu/bits/sem.h: Likewise.
    	* sysdeps/unix/sysv/linux/bits/sem.h: Likewise.
    	* sysdeps/unix/sysv/linux/ia64/bits/ipc.h: Likewise.
    	* sysvipc/sys/sem.h: Include bits/types/pid_t.h and
    	bits/types/time_t.h.
    
    	* resolv/bits/types/res_state.h: Include bits/types.h, not
    	sys/types.h.  Use __uint32_t and __uint16_t, not uint32_t and
    	uint16_t.
    
    	* sysdeps/mach/hurd/bits/socket.h: Include bits/types.h, not
    	sys/types.h.
    	* sysdeps/unix/sysv/linux/bits/socket.h: Likewise.  Use __pid_t,
    	__uid_t, and __gid_t, not pid_t, uid_t, and gid_t.
    	* socket/sys/socket.h: Include bits/types.h, bits/types/ssize_t.h,
    	and bits/types/socklen_t.h.
    	* inet/htonl.c, include/htons.c: Include endian.h.
    	* include/netinet/ether.h: Include bits/types/size_t.h.
    
    	* scripts/check-obsolete-constructs.py (HEADER_ALLOWED_INCLUDES):
    	Update.

Diff:
---
 bits/fcntl.h                            |  9 ++++++---
 bits/sem.h                              |  7 ++++++-
 include/netinet/ether.h                 |  1 +
 inet/htonl.c                            |  3 ++-
 inet/htons.c                            |  2 ++
 resolv/bits/types/res_state.h           | 12 ++++++------
 scripts/check-obsolete-constructs.py    |  6 +-----
 socket/sys/socket.h                     |  3 +++
 sysdeps/gnu/bits/sem.h                  |  7 ++++++-
 sysdeps/mach/hurd/bits/fcntl.h          | 11 ++++++-----
 sysdeps/mach/hurd/bits/socket.h         |  2 +-
 sysdeps/unix/sysv/linux/bits/sem.h      |  7 ++++++-
 sysdeps/unix/sysv/linux/bits/socket.h   |  8 ++++----
 sysdeps/unix/sysv/linux/ia64/bits/ipc.h |  2 +-
 sysvipc/sys/sem.h                       |  2 ++
 15 files changed, 53 insertions(+), 29 deletions(-)

diff --git a/bits/fcntl.h b/bits/fcntl.h
index 8bb1357..c69869f 100644
--- a/bits/fcntl.h
+++ b/bits/fcntl.h
@@ -16,10 +16,14 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_FCNTL_H
+#define _BITS_FCNTL_H 1
+
 #ifndef	_FCNTL_H
 #error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
 #endif
 
+#include <bits/types.h>
 
 /* File access modes for `open' and `fcntl'.  */
 #define	O_RDONLY	0	/* Open read-only.  */
@@ -104,9 +108,6 @@
 /* File descriptor flags used with F_GETFD and F_SETFD.  */
 #define	FD_CLOEXEC	1	/* Close on exec.  */
 
-
-#include <bits/types.h>
-
 /* The structure describing an advisory lock.  This is the type of the third
    argument to `fcntl' for the F_GETLK, F_SETLK, and F_SETLKW requests.  */
 struct flock
@@ -144,3 +145,5 @@ struct flock64
 # define POSIX_FADV_DONTNEED	4 /* Don't need these pages.  */
 # define POSIX_FADV_NOREUSE	5 /* Data will be accessed once.  */
 #endif
+
+#endif
diff --git a/bits/sem.h b/bits/sem.h
index 02754c7..6eed74c 100644
--- a/bits/sem.h
+++ b/bits/sem.h
@@ -15,11 +15,14 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_SEM_H
+#define _BITS_SEM_H 1
+
 #ifndef _SYS_SEM_H
 # error "Never include <bits/sem.h> directly; use <sys/sem.h> instead."
 #endif
 
-#include <sys/types.h>
+#include <bits/types.h>
 
 /* Flags for `semop'.  */
 #define SEM_UNDO	0x1000		/* undo the operation on exit */
@@ -58,3 +61,5 @@ struct semid_ds
    incorrect.  One can test the macro _SEM_SEMUN_UNDEFINED to see whether
    one must define the union or not.  */
 #define _SEM_SEMUN_UNDEFINED	1
+
+#endif /* bits/sem.h */
diff --git a/include/netinet/ether.h b/include/netinet/ether.h
index 8bfe7e0..a60aa27 100644
--- a/include/netinet/ether.h
+++ b/include/netinet/ether.h
@@ -2,6 +2,7 @@
 #include <inet/netinet/ether.h>
 
 # ifndef _ISOMAC
+#  include <bits/types/size_t.h>
 
 libc_hidden_proto (ether_aton_r)
 libc_hidden_proto (ether_ntoa_r)
diff --git a/inet/htonl.c b/inet/htonl.c
index 39acfa6..bb6b4f5 100644
--- a/inet/htonl.c
+++ b/inet/htonl.c
@@ -15,8 +15,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <stdint.h>
 #include <netinet/in.h>
+#include <endian.h>
+#include <stdint.h>
 
 #undef	htonl
 #undef	ntohl
diff --git a/inet/htons.c b/inet/htons.c
index 500ca50..2b22ca1 100644
--- a/inet/htons.c
+++ b/inet/htons.c
@@ -16,6 +16,8 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <netinet/in.h>
+#include <endian.h>
+#include <stdint.h>
 
 #undef	htons
 #undef	ntohs
diff --git a/resolv/bits/types/res_state.h b/resolv/bits/types/res_state.h
index 2544a62..81febe1 100644
--- a/resolv/bits/types/res_state.h
+++ b/resolv/bits/types/res_state.h
@@ -1,7 +1,7 @@
 #ifndef __res_state_defined
 #define __res_state_defined 1
 
-#include <sys/types.h>
+#include <bits/types.h>
 #include <netinet/in.h>
 
 /* res_state: the global state used by the resolver stub.  */
@@ -28,7 +28,7 @@ struct __res_state {
 	unsigned unused:23;
 	struct {
 		struct in_addr	addr;
-		uint32_t	mask;
+		__uint32_t	mask;
 	} sort_list[MAXRESOLVSORT];
 	/* 4 byte hole here on 64-bit architectures.  */
 	void * __glibc_unused_qhook;
@@ -40,11 +40,11 @@ struct __res_state {
 	union {
 		char	pad[52];	/* On an i386 this means 512b total. */
 		struct {
-			uint16_t		nscount;
-			uint16_t		nsmap[MAXNS];
+			__uint16_t		nscount;
+			__uint16_t		nsmap[MAXNS];
 			int			nssocks[MAXNS];
-			uint16_t		nscount6;
-			uint16_t		nsinit;
+			__uint16_t		nscount6;
+			__uint16_t		nsinit;
 			struct sockaddr_in6	*nsaddrs[MAXNS];
 #ifdef _LIBC
 			unsigned long long int __glibc_extension_index
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index dcb1175..32ca04f 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -638,12 +638,8 @@ HEADER_ALLOWED_INCLUDES = {
     "features.h":                  [ "gnu/stubs.h", "stdc-predef.h",
                                      "sys/cdefs.h" ],
 
-    "bits/fcntl.h":                [ "sys/types.h" ],
-    "bits/ipc.h":                  [ "sys/types.h" ],
     "bits/procfs.h":               [ "signal.h", "sys/ucontext.h" ],
-    "bits/sem.h":                  [ "sys/types.h" ],
-    "bits/socket.h":               [ "sys/types.h" ],
-    "bits/types/res_state.h":      [ "netinet/in.h", "sys/types.h" ],
+    "bits/types/res_state.h":      [ "netinet/in.h" ],
 
     "bits/types/__va_list.h":      [ "stdarg.h" ],
     "bits/types/ptrdiff_t.h":      [ "stddef.h" ],
diff --git a/socket/sys/socket.h b/socket/sys/socket.h
index ce793dc..9770d90 100644
--- a/socket/sys/socket.h
+++ b/socket/sys/socket.h
@@ -23,7 +23,10 @@
 
 __BEGIN_DECLS
 
+#include <bits/types.h>
 #include <bits/types/size_t.h>
+#include <bits/types/ssize_t.h>
+#include <bits/types/socklen_t.h>
 #include <bits/types/struct_iovec.h>
 
 /* This operating system-specific header file defines the SOCK_*, PF_*,
diff --git a/sysdeps/gnu/bits/sem.h b/sysdeps/gnu/bits/sem.h
index 12ec4e6..2eeb12a 100644
--- a/sysdeps/gnu/bits/sem.h
+++ b/sysdeps/gnu/bits/sem.h
@@ -15,11 +15,14 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_SEM_H
+#define _BITS_SEM_H 1
+
 #ifndef _SYS_SEM_H
 # error "Never include <bits/sem.h> directly; use <sys/sem.h> instead."
 #endif
 
-#include <sys/types.h>
+#include <bits/types.h>
 
 /* Flags for `semop'.  */
 #define SEM_UNDO	0x1000		/* undo the operation on exit */
@@ -85,3 +88,5 @@ struct  seminfo
 };
 
 #endif /* __USE_MISC */
+
+#endif /* bits/sem.h */
diff --git a/sysdeps/mach/hurd/bits/fcntl.h b/sysdeps/mach/hurd/bits/fcntl.h
index 9da4f8a..b666a71 100644
--- a/sysdeps/mach/hurd/bits/fcntl.h
+++ b/sysdeps/mach/hurd/bits/fcntl.h
@@ -16,11 +16,14 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_FCNTL_H
+#define _BITS_FCNTL_H 1
+
 #ifndef _FCNTL_H
 # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
 #endif
 
-#include <sys/types.h>
+#include <bits/types.h>
 
 /* File access modes.  These are understood by io servers; they can be
    passed in `dir_lookup', and are returned by `io_get_openmodes'.
@@ -180,13 +183,9 @@
 # define F_DUPFD_CLOEXEC 1030	/* Duplicate, set FD_CLOEXEC on new one.  */
 #endif
 
-
 /* File descriptor flags used with F_GETFD and F_SETFD.  */
 #define	FD_CLOEXEC	1	/* Close on exec.  */
 
-
-#include <bits/types.h>
-
 /* The structure describing an advisory lock.  This is the type of the third
    argument to `fcntl' for the F_GETLK, F_SETLK, and F_SETLKW requests.  */
 struct flock
@@ -228,3 +227,5 @@ struct flock64
 # define POSIX_FADV_DONTNEED	4 /* Don't need these pages.  */
 # define POSIX_FADV_NOREUSE	5 /* Data will be accessed once.  */
 #endif
+
+#endif /* bits/fcntl.h */
diff --git a/sysdeps/mach/hurd/bits/socket.h b/sysdeps/mach/hurd/bits/socket.h
index ad590af..77498ca 100644
--- a/sysdeps/mach/hurd/bits/socket.h
+++ b/sysdeps/mach/hurd/bits/socket.h
@@ -25,7 +25,7 @@
 #endif
 
 
-#include <sys/types.h>
+#include <bits/types.h>
 #include <bits/types/size_t.h>
 #include <bits/types/socklen_t.h>
 #include <bits/wordsize.h>
diff --git a/sysdeps/unix/sysv/linux/bits/sem.h b/sysdeps/unix/sysv/linux/bits/sem.h
index a216459..68600e3 100644
--- a/sysdeps/unix/sysv/linux/bits/sem.h
+++ b/sysdeps/unix/sysv/linux/bits/sem.h
@@ -15,11 +15,14 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef _BITS_SEM_H
+#define _BITS_SEM_H 1
+
 #ifndef _SYS_SEM_H
 # error "Never include <bits/sem.h> directly; use <sys/sem.h> instead."
 #endif
 
-#include <sys/types.h>
+#include <bits/types.h>
 #include <bits/sem-pad.h>
 
 /* Flags for `semop'.  */
@@ -95,3 +98,5 @@ struct  seminfo
 };
 
 #endif /* __USE_MISC */
+
+#endif /* bits/sem.h */
diff --git a/sysdeps/unix/sysv/linux/bits/socket.h b/sysdeps/unix/sysv/linux/bits/socket.h
index 19e6648..ef3d6f9 100644
--- a/sysdeps/unix/sysv/linux/bits/socket.h
+++ b/sysdeps/unix/sysv/linux/bits/socket.h
@@ -24,7 +24,7 @@
 #endif
 
 
-#include <sys/types.h>
+#include <bits/types.h>
 #include <bits/types/size_t.h>
 #include <bits/types/socklen_t.h>
 
@@ -337,9 +337,9 @@ enum
 /* User visible structure for SCM_CREDENTIALS message */
 struct ucred
 {
-  pid_t pid;			/* PID of sending process.  */
-  uid_t uid;			/* UID of sending process.  */
-  gid_t gid;			/* GID of sending process.  */
+  __pid_t pid;			/* PID of sending process.  */
+  __uid_t uid;			/* UID of sending process.  */
+  __gid_t gid;			/* GID of sending process.  */
 };
 #endif
 
diff --git a/sysdeps/unix/sysv/linux/ia64/bits/ipc.h b/sysdeps/unix/sysv/linux/ia64/bits/ipc.h
index 6f9705e..a6fbabe 100644
--- a/sysdeps/unix/sysv/linux/ia64/bits/ipc.h
+++ b/sysdeps/unix/sysv/linux/ia64/bits/ipc.h
@@ -20,7 +20,7 @@
 # error "Never use <bits/ipc.h> directly; include <sys/ipc.h> instead."
 #endif
 
-#include <sys/types.h>
+#include <bits/types.h>
 
 /* Mode bits for `msgget', `semget', and `shmget'.  */
 #define IPC_CREAT	01000		/* Create key if key does not exist. */
diff --git a/sysvipc/sys/sem.h b/sysvipc/sys/sem.h
index 6b5d43d..09e6335 100644
--- a/sysvipc/sys/sem.h
+++ b/sysvipc/sys/sem.h
@@ -25,6 +25,8 @@
 
 /* Define types required by the standard.  */
 #include <bits/types/size_t.h>
+#include <bits/types/pid_t.h>
+#include <bits/types/time_t.h>
 #ifdef __USE_GNU
 # include <bits/types/struct_timespec.h>
 #endif


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]