public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/zack/no-nested-includes] Don’t include sys/cdefs.h directly from public headers.
@ 2019-05-26 16:36 Zack Weinberg
0 siblings, 0 replies; 7+ messages in thread
From: Zack Weinberg @ 2019-05-26 16:36 UTC (permalink / raw)
To: glibc-cvs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 13864 bytes --]
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=f8b98ee3faf2763aa3ad4df9b50e3d199c45b5a5
commit f8b98ee3faf2763aa3ad4df9b50e3d199c45b5a5
Author: Zack Weinberg <zackw@panix.com>
Date: Sat Mar 16 14:31:08 2019 -0400
Donât include sys/cdefs.h directly from public headers.
The convention throughout glibc is that every public header includes
features.h directly, as its first action, and relies on features.h to
include sys/cdefs.h. In a few places, though, itâs been done the
other way around, usually in headers that were copied from a BSD
source (where the convention is exactly the opposite). This patch
makes all installed headers match the glibc convention.
This patch also corrects a bug in glob.h: it may declare size_t
without notifying stddef.h that it has done this, so e.g.
#define _XOPEN_SOURCE 700
#include <glob.h>
#include <stddef.h>
int dummy;
declares size_t twice, which is invalid prior to C2011. I wasnât able
to persuade gcc 8 to issue an error, even with -std=c89 -Wsystem-headers,
but clang is not so lenient.
* posix/glob.h: Include features.h, not sys/cdefs.h.
When __USE_XOPEN || USE_XOPEN2K8, include stddef.h for size_t;
otherwise, issue an immediate #error if __SIZE_TYPE__ is not
available. Use __gsize_t, not __size_t, as an impl-namespace
alternative name for size_t.
* conform/data/glob.h-data: Adjust to match.
* inet/netinet/igmp.h, mach/lock-intern.h, misc/ar.h
* misc/sys/auxv.h, resolv/resolv.h, socket/sys/un.h
* sunrpc/rpc/auth_des.h, sunrpc/rpc/rpc_msg.h
* sysdeps/generic/memcopy.h, sysdeps/generic/netinet/tcp.h
* sysdeps/htl/pthread.h, sysdeps/mach/hurd/net/ethernet.h
* sysdeps/mach/hurd/net/if_arp.h: Include features.h, not sys/cdefs.h.
* scripts/check-obsolete-constructs.py: Remove most whitelist
entries for sys/cdefs.h.
Diff:
---
conform/data/glob.h-data | 2 +-
inet/netinet/igmp.h | 3 ++-
mach/lock-intern.h | 3 ++-
misc/ar.h | 2 +-
misc/sys/auxv.h | 3 ++-
posix/glob.h | 33 ++++++++++++++++++---------------
resolv/resolv.h | 3 ++-
scripts/check-obsolete-constructs.py | 18 +++++++-----------
socket/sys/un.h | 2 +-
sunrpc/rpc/auth_des.h | 3 ++-
sunrpc/rpc/rpc_msg.h | 2 +-
sysdeps/generic/memcopy.h | 3 ++-
sysdeps/generic/netinet/tcp.h | 3 +--
sysdeps/htl/pthread.h | 1 -
sysdeps/mach/hurd/net/ethernet.h | 3 ++-
sysdeps/mach/hurd/net/if_arp.h | 4 ++--
16 files changed, 46 insertions(+), 42 deletions(-)
diff --git a/conform/data/glob.h-data b/conform/data/glob.h-data
index eca8393..6268134 100644
--- a/conform/data/glob.h-data
+++ b/conform/data/glob.h-data
@@ -1,6 +1,6 @@
#if !defined ISO && !defined ISO99 && !defined ISO11
#ifdef POSIX
-# define size_t __size_t
+# define size_t __gsize_t
#endif
type glob_t
diff --git a/inet/netinet/igmp.h b/inet/netinet/igmp.h
index dccdb11..2f5be95 100644
--- a/inet/netinet/igmp.h
+++ b/inet/netinet/igmp.h
@@ -18,7 +18,8 @@
#ifndef _NETINET_IGMP_H
#define _NETINET_IGMP_H 1
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <sys/types.h>
#ifdef __USE_MISC
diff --git a/mach/lock-intern.h b/mach/lock-intern.h
index 1988c89..a409abb 100644
--- a/mach/lock-intern.h
+++ b/mach/lock-intern.h
@@ -18,7 +18,8 @@
#ifndef _LOCK_INTERN_H
#define _LOCK_INTERN_H
-#include <sys/cdefs.h>
+#include <features.h>
+
#if defined __USE_EXTERN_INLINES && defined _LIBC
# include <lowlevellock.h>
#endif
diff --git a/misc/ar.h b/misc/ar.h
index ef2303e..adcfda4 100644
--- a/misc/ar.h
+++ b/misc/ar.h
@@ -19,7 +19,7 @@
#ifndef _AR_H
#define _AR_H 1
-#include <sys/cdefs.h>
+#include <features.h>
/* Archive files start with the ARMAG identifying string. Then follows a
`struct ar_hdr', and as many bytes of member file data as its `ar_size'
diff --git a/misc/sys/auxv.h b/misc/sys/auxv.h
index 68363b3..404da6f 100644
--- a/misc/sys/auxv.h
+++ b/misc/sys/auxv.h
@@ -19,8 +19,9 @@
#ifndef _SYS_AUXV_H
#define _SYS_AUXV_H 1
+#include <features.h>
+
#include <elf.h>
-#include <sys/cdefs.h>
#include <bits/hwcap.h>
__BEGIN_DECLS
diff --git a/posix/glob.h b/posix/glob.h
index 378b80a..e49e6c0 100644
--- a/posix/glob.h
+++ b/posix/glob.h
@@ -18,21 +18,24 @@
#ifndef _GLOB_H
#define _GLOB_H 1
-#include <sys/cdefs.h>
+#include <features.h>
__BEGIN_DECLS
-/* We need `size_t' for the following definitions. */
-#ifndef __size_t
-typedef __SIZE_TYPE__ __size_t;
-# if defined __USE_XOPEN || defined __USE_XOPEN2K8
-typedef __SIZE_TYPE__ size_t;
-# endif
+/* Structures below have size_t fields, but this header is not supposed to
+ define size_t itself, unless XSI or POSIX.1-2008 features are active.
+ We can't use __size_t as an alternative name, as we do for most types
+ with this kind of constraint, because GCC's stddef.h uses __size_t for
+ a different purpose. */
+
+#if defined __USE_XOPEN || defined __USE_XOPEN2K8
+# define __need_size_t
+# include <stddef.h>
+typedef size_t __gsize_t;
+#elif defined __SIZE_TYPE__
+typedef __SIZE_TYPE__ __gsize_t;
#else
-/* The GNU CC stddef.h version defines __size_t as empty. We need a real
- definition. */
-# undef __size_t
-# define __size_t size_t
+# error "Don't know how to define __gsize_t"
#endif
/* Bits set in the FLAGS argument to `glob'. */
@@ -81,9 +84,9 @@ struct stat;
#endif
typedef struct
{
- __size_t gl_pathc; /* Count of paths matched by the pattern. */
+ __gsize_t gl_pathc; /* Count of paths matched by the pattern. */
char **gl_pathv; /* List of matched pathnames. */
- __size_t gl_offs; /* Slots to reserve in `gl_pathv'. */
+ __gsize_t gl_offs; /* Slots to reserve in `gl_pathv'. */
int gl_flags; /* Set to FLAGS, maybe | GLOB_MAGCHAR. */
/* If the GLOB_ALTDIRFUNC flag is set, the following functions
@@ -110,9 +113,9 @@ struct stat64;
# endif
typedef struct
{
- __size_t gl_pathc;
+ __gsize_t gl_pathc;
char **gl_pathv;
- __size_t gl_offs;
+ __gsize_t gl_offs;
int gl_flags;
/* If the GLOB_ALTDIRFUNC flag is set, the following functions
diff --git a/resolv/resolv.h b/resolv/resolv.h
index 7a8023a..b4ef66f 100644
--- a/resolv/resolv.h
+++ b/resolv/resolv.h
@@ -52,7 +52,8 @@
#ifndef _RESOLV_H_
#define _RESOLV_H_
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <sys/param.h>
#include <sys/types.h>
#include <stdio.h>
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index a6ee700..5c1bb50 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -527,11 +527,9 @@ HEADER_ALLOWED_INCLUDES = {
# spawn.h -> sched.h
"aio.h": [ "sys/types.h" ],
"ftw.h": [ "sys/stat.h", "sys/types.h" ],
- "glob.h": [ "sys/cdefs.h" ],
"langinfo.h": [ "nl_types.h" ],
"mqueue.h": [ "fcntl.h", "sys/types.h" ],
- "pthread.h": [ "endian.h", "sched.h", "time.h",
- "sys/cdefs.h" ],
+ "pthread.h": [ "sched.h", "time.h" ],
"regex.h": [ "limits.h", "sys/types.h" ],
"sched.h": [ "time.h" ],
"semaphore.h": [ "sys/types.h" ],
@@ -550,7 +548,7 @@ HEADER_ALLOWED_INCLUDES = {
"sys/time.h": [ "sys/select.h" ],
"sys/types.h": [ "endian.h", "sys/select.h" ],
"sys/uio.h": [ "sys/types.h" ],
- "sys/un.h": [ "string.h", "sys/cdefs.h" ],
+ "sys/un.h": [ "string.h" ],
"sys/wait.h": [ "signal.h" ],
# POSIX networking headers
@@ -565,7 +563,6 @@ HEADER_ALLOWED_INCLUDES = {
# Nonstandardized top-level headers
"aliases.h": [ "sys/types.h" ],
- "ar.h": [ "sys/cdefs.h" ],
"argp.h": [ "ctype.h", "errno.h", "getopt.h",
"limits.h", "stdio.h" ],
"argz.h": [ "errno.h", "string.h" ],
@@ -602,7 +599,7 @@ HEADER_ALLOWED_INCLUDES = {
# Nonstandardized sys/ headers
"sys/acct.h": [ "endian.h", "stdint.h", "sys/types.h" ],
- "sys/auxv.h": [ "elf.h", "sys/cdefs.h" ],
+ "sys/auxv.h": [ "elf.h" ],
"sys/bitypes.h": [ "sys/types.h" ],
"sys/dir.h": [ "dirent.h" ],
"sys/elf.h": [ "sys/procfs.h" ],
@@ -651,16 +648,16 @@ HEADER_ALLOWED_INCLUDES = {
# Nonstandardized networking headers
"ifaddrs.h": [ "sys/socket.h" ],
"resolv.h": [ "arpa/nameser.h", "netinet/in.h",
- "stdio.h", "sys/cdefs.h", "sys/param.h",\
+ "stdio.h", "sys/param.h",
"sys/types.h" ],
"arpa/nameser.h": [ "arpa/nameser_compat.h", "stdint.h",
"sys/param.h", "sys/types.h" ],
"arpa/nameser_compat.h": [ "endian.h" ],
- "net/ethernet.h": [ "stdint.h", "sys/types.h", "sys/cdefs.h",
+ "net/ethernet.h": [ "stdint.h", "sys/types.h",
"net/if_ether.h" ],
"net/if_arp.h": [ "stdint.h", "sys/socket.h",
- "sys/types.h", "sys/cdefs.h" ],
+ "sys/types.h" ],
"net/if_ppp.h": [ "net/if.h", "net/ppp_defs.h", "stdint.h",
"sys/ioctl.h", "sys/types.h" ],
"net/if_shaper.h": [ "net/if.h", "stdint.h", "sys/ioctl.h",
@@ -675,8 +672,7 @@ HEADER_ALLOWED_INCLUDES = {
"sys/types.h", "stdint.h" ],
"netinet/if_fddi.h": [ "stdint.h", "sys/types.h" ],
"netinet/if_tr.h": [ "stdint.h", "sys/types.h" ],
- "netinet/igmp.h": [ "netinet/in.h", "sys/cdefs.h",
- "sys/types.h" ],
+ "netinet/igmp.h": [ "netinet/in.h", "sys/types.h" ],
"netinet/in_systm.h": [ "stdint.h", "sys/types.h" ],
"netinet/ip.h": [ "netinet/in.h", "sys/types.h" ],
"netinet/ip6.h": [ "inttypes.h", "netinet/in.h" ],
diff --git a/socket/sys/un.h b/socket/sys/un.h
index 1268360..8c7433a 100644
--- a/socket/sys/un.h
+++ b/socket/sys/un.h
@@ -18,7 +18,7 @@
#ifndef _SYS_UN_H
#define _SYS_UN_H 1
-#include <sys/cdefs.h>
+#include <features.h>
/* Get the definition of the macro to define the common sockaddr members. */
#include <bits/sockaddr.h>
diff --git a/sunrpc/rpc/auth_des.h b/sunrpc/rpc/auth_des.h
index 245675f..e60e795 100644
--- a/sunrpc/rpc/auth_des.h
+++ b/sunrpc/rpc/auth_des.h
@@ -18,7 +18,8 @@
#ifndef _RPC_AUTH_DES_H
#define _RPC_AUTH_DES_H 1
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <rpc/auth.h>
__BEGIN_DECLS
diff --git a/sunrpc/rpc/rpc_msg.h b/sunrpc/rpc/rpc_msg.h
index a2cc516..efd9ee4 100644
--- a/sunrpc/rpc/rpc_msg.h
+++ b/sunrpc/rpc/rpc_msg.h
@@ -35,7 +35,7 @@
#ifndef _RPC_MSG_H
#define _RPC_MSG_H 1
-#include <sys/cdefs.h>
+#include <features.h>
#include <rpc/xdr.h>
#include <rpc/clnt.h>
diff --git a/sysdeps/generic/memcopy.h b/sysdeps/generic/memcopy.h
index e10d01e..de32e56 100644
--- a/sysdeps/generic/memcopy.h
+++ b/sysdeps/generic/memcopy.h
@@ -20,6 +20,8 @@
#ifndef _MEMCOPY_H
#define _MEMCOPY_H 1
+#include <features.h>
+
/* The strategy of the memory functions is:
1. Copy bytes until the destination pointer is aligned.
@@ -38,7 +40,6 @@
exhaustive in the sense that I tried all alignment and length
combinations, with and without overlap. */
-#include <sys/cdefs.h>
#include <endian.h>
#include <pagecopy.h>
diff --git a/sysdeps/generic/netinet/tcp.h b/sysdeps/generic/netinet/tcp.h
index 49f1bfb..3b59e94 100644
--- a/sysdeps/generic/netinet/tcp.h
+++ b/sysdeps/generic/netinet/tcp.h
@@ -30,10 +30,9 @@
*/
#ifndef _NETINET_TCP_H
-
#define _NETINET_TCP_H 1
-#include <sys/cdefs.h>
+#include <features.h>
__BEGIN_DECLS
diff --git a/sysdeps/htl/pthread.h b/sysdeps/htl/pthread.h
index a820551..158a095 100644
--- a/sysdeps/htl/pthread.h
+++ b/sysdeps/htl/pthread.h
@@ -25,7 +25,6 @@
#include <features.h>
-#include <sys/cdefs.h>
#ifndef __extern_inline
/* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
inline semantics, unless -fgnu89-inline is used. */
diff --git a/sysdeps/mach/hurd/net/ethernet.h b/sysdeps/mach/hurd/net/ethernet.h
index 4aa67ea..8956694 100644
--- a/sysdeps/mach/hurd/net/ethernet.h
+++ b/sysdeps/mach/hurd/net/ethernet.h
@@ -21,7 +21,8 @@
#ifndef __NET_ETHERNET_H
#define __NET_ETHERNET_H 1
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <sys/types.h>
#include <stdint.h>
#include <net/if_ether.h> /* IEEE 802.3 Ethernet constants */
diff --git a/sysdeps/mach/hurd/net/if_arp.h b/sysdeps/mach/hurd/net/if_arp.h
index 6ef93c9..9e1b223 100644
--- a/sysdeps/mach/hurd/net/if_arp.h
+++ b/sysdeps/mach/hurd/net/if_arp.h
@@ -20,9 +20,9 @@
/* Based on the 4.4BSD and Linux version of this file. */
#ifndef _NET_IF_ARP_H
-
#define _NET_IF_ARP_H 1
-#include <sys/cdefs.h>
+
+#include <features.h>
#include <sys/types.h>
#include <sys/socket.h>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [glibc/zack/no-nested-includes] Don’t include sys/cdefs.h directly from public headers.
@ 2020-01-08 19:19 Zack Weinberg
0 siblings, 0 replies; 7+ messages in thread
From: Zack Weinberg @ 2020-01-08 19:19 UTC (permalink / raw)
To: glibc-cvs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 13870 bytes --]
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=afaa4fe717db9f4106570665f5db0cd45684b96a
commit afaa4fe717db9f4106570665f5db0cd45684b96a
Author: Zack Weinberg <zackw@panix.com>
Date: Tue Jun 18 11:47:49 2019 -0400
Donât include sys/cdefs.h directly from public headers.
The convention throughout glibc is that every public header includes
features.h directly, as its first action, and relies on features.h to
include sys/cdefs.h. In a few places, though, itâs been done the
other way around, usually in headers that were copied from a BSD
source (where the convention is exactly the opposite). This patch
makes all installed headers match the glibc convention.
This patch also corrects a bug in glob.h: it may declare size_t
without notifying stddef.h that it has done this, so e.g.
#define _XOPEN_SOURCE 700
#include <glob.h>
#include <stddef.h>
int dummy;
declares size_t twice, which is invalid prior to C2011. I wasnât able
to persuade gcc 8 to issue an error, even with -std=c89 -Wsystem-headers,
but clang is not so lenient.
* posix/glob.h: Include features.h, not sys/cdefs.h.
When __USE_XOPEN || USE_XOPEN2K8, include stddef.h for size_t;
otherwise, issue an immediate #error if __SIZE_TYPE__ is not
available. Use __gsize_t, not __size_t, as an impl-namespace
alternative name for size_t.
* conform/data/glob.h-data: Adjust to match.
* inet/netinet/igmp.h, mach/lock-intern.h, misc/ar.h
* misc/sys/auxv.h, resolv/resolv.h, socket/sys/un.h
* sunrpc/rpc/auth_des.h, sunrpc/rpc/rpc_msg.h
* sysdeps/generic/memcopy.h, sysdeps/generic/netinet/tcp.h
* sysdeps/htl/pthread.h, sysdeps/mach/hurd/net/ethernet.h
* sysdeps/mach/hurd/net/if_arp.h: Include features.h, not sys/cdefs.h.
* scripts/check-obsolete-constructs.py (HEADER_ALLOWED_INCLUDES):
Update.
Diff:
---
conform/data/glob.h-data | 2 +-
inet/netinet/igmp.h | 3 ++-
mach/lock-intern.h | 3 ++-
misc/ar.h | 2 +-
misc/sys/auxv.h | 3 ++-
posix/glob.h | 33 ++++++++++++++++++---------------
resolv/resolv.h | 3 ++-
scripts/check-obsolete-constructs.py | 18 +++++++-----------
socket/sys/un.h | 2 +-
sunrpc/rpc/auth_des.h | 3 ++-
sunrpc/rpc/rpc_msg.h | 2 +-
sysdeps/generic/memcopy.h | 3 ++-
sysdeps/generic/netinet/tcp.h | 3 +--
sysdeps/htl/pthread.h | 1 -
sysdeps/mach/hurd/net/ethernet.h | 3 ++-
sysdeps/mach/hurd/net/if_arp.h | 4 ++--
16 files changed, 46 insertions(+), 42 deletions(-)
diff --git a/conform/data/glob.h-data b/conform/data/glob.h-data
index eca8393..6268134 100644
--- a/conform/data/glob.h-data
+++ b/conform/data/glob.h-data
@@ -1,6 +1,6 @@
#if !defined ISO && !defined ISO99 && !defined ISO11
#ifdef POSIX
-# define size_t __size_t
+# define size_t __gsize_t
#endif
type glob_t
diff --git a/inet/netinet/igmp.h b/inet/netinet/igmp.h
index 2c3f167..3a5b157 100644
--- a/inet/netinet/igmp.h
+++ b/inet/netinet/igmp.h
@@ -18,7 +18,8 @@
#ifndef _NETINET_IGMP_H
#define _NETINET_IGMP_H 1
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <sys/types.h>
#ifdef __USE_MISC
diff --git a/mach/lock-intern.h b/mach/lock-intern.h
index b6a075b..357860c 100644
--- a/mach/lock-intern.h
+++ b/mach/lock-intern.h
@@ -18,7 +18,8 @@
#ifndef _LOCK_INTERN_H
#define _LOCK_INTERN_H
-#include <sys/cdefs.h>
+#include <features.h>
+
#if defined __USE_EXTERN_INLINES && defined _LIBC
# include <lowlevellock.h>
#endif
diff --git a/misc/ar.h b/misc/ar.h
index 85ecba6..8dcef44 100644
--- a/misc/ar.h
+++ b/misc/ar.h
@@ -19,7 +19,7 @@
#ifndef _AR_H
#define _AR_H 1
-#include <sys/cdefs.h>
+#include <features.h>
/* Archive files start with the ARMAG identifying string. Then follows a
`struct ar_hdr', and as many bytes of member file data as its `ar_size'
diff --git a/misc/sys/auxv.h b/misc/sys/auxv.h
index 1a563e1..038bbbe 100644
--- a/misc/sys/auxv.h
+++ b/misc/sys/auxv.h
@@ -19,8 +19,9 @@
#ifndef _SYS_AUXV_H
#define _SYS_AUXV_H 1
+#include <features.h>
+
#include <elf.h>
-#include <sys/cdefs.h>
#include <bits/hwcap.h>
__BEGIN_DECLS
diff --git a/posix/glob.h b/posix/glob.h
index b82a282..e647ba8 100644
--- a/posix/glob.h
+++ b/posix/glob.h
@@ -18,21 +18,24 @@
#ifndef _GLOB_H
#define _GLOB_H 1
-#include <sys/cdefs.h>
+#include <features.h>
__BEGIN_DECLS
-/* We need `size_t' for the following definitions. */
-#ifndef __size_t
-typedef __SIZE_TYPE__ __size_t;
-# if defined __USE_XOPEN || defined __USE_XOPEN2K8
-typedef __SIZE_TYPE__ size_t;
-# endif
+/* Structures below have size_t fields, but this header is not supposed to
+ define size_t itself, unless XSI or POSIX.1-2008 features are active.
+ We can't use __size_t as an alternative name, as we do for most types
+ with this kind of constraint, because GCC's stddef.h uses __size_t for
+ a different purpose. */
+
+#if defined __USE_XOPEN || defined __USE_XOPEN2K8
+# define __need_size_t
+# include <stddef.h>
+typedef size_t __gsize_t;
+#elif defined __SIZE_TYPE__
+typedef __SIZE_TYPE__ __gsize_t;
#else
-/* The GNU CC stddef.h version defines __size_t as empty. We need a real
- definition. */
-# undef __size_t
-# define __size_t size_t
+# error "Don't know how to define __gsize_t"
#endif
/* Bits set in the FLAGS argument to `glob'. */
@@ -81,9 +84,9 @@ struct stat;
#endif
typedef struct
{
- __size_t gl_pathc; /* Count of paths matched by the pattern. */
+ __gsize_t gl_pathc; /* Count of paths matched by the pattern. */
char **gl_pathv; /* List of matched pathnames. */
- __size_t gl_offs; /* Slots to reserve in `gl_pathv'. */
+ __gsize_t gl_offs; /* Slots to reserve in `gl_pathv'. */
int gl_flags; /* Set to FLAGS, maybe | GLOB_MAGCHAR. */
/* If the GLOB_ALTDIRFUNC flag is set, the following functions
@@ -110,9 +113,9 @@ struct stat64;
# endif
typedef struct
{
- __size_t gl_pathc;
+ __gsize_t gl_pathc;
char **gl_pathv;
- __size_t gl_offs;
+ __gsize_t gl_offs;
int gl_flags;
/* If the GLOB_ALTDIRFUNC flag is set, the following functions
diff --git a/resolv/resolv.h b/resolv/resolv.h
index a039a9e..ce3922c 100644
--- a/resolv/resolv.h
+++ b/resolv/resolv.h
@@ -52,7 +52,8 @@
#ifndef _RESOLV_H_
#define _RESOLV_H_
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <sys/param.h>
#include <sys/types.h>
#include <stdio.h>
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index 1d9eec5..25c0d68 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -527,11 +527,9 @@ HEADER_ALLOWED_INCLUDES = {
# spawn.h -> sched.h
"aio.h": [ "sys/types.h" ],
"ftw.h": [ "sys/stat.h", "sys/types.h" ],
- "glob.h": [ "sys/cdefs.h" ],
"langinfo.h": [ "nl_types.h" ],
"mqueue.h": [ "fcntl.h", "sys/types.h" ],
- "pthread.h": [ "endian.h", "sched.h", "time.h",
- "sys/cdefs.h" ],
+ "pthread.h": [ "sched.h", "time.h" ],
"regex.h": [ "limits.h", "sys/types.h" ],
"sched.h": [ "time.h" ],
"semaphore.h": [ "sys/types.h" ],
@@ -550,7 +548,7 @@ HEADER_ALLOWED_INCLUDES = {
"sys/time.h": [ "sys/select.h" ],
"sys/types.h": [ "endian.h", "sys/select.h" ],
"sys/uio.h": [ "sys/types.h" ],
- "sys/un.h": [ "string.h", "sys/cdefs.h" ],
+ "sys/un.h": [ "string.h" ],
"sys/wait.h": [ "signal.h" ],
# POSIX networking headers
@@ -565,7 +563,6 @@ HEADER_ALLOWED_INCLUDES = {
# Nonstandardized top-level headers
"aliases.h": [ "sys/types.h" ],
- "ar.h": [ "sys/cdefs.h" ],
"argp.h": [ "ctype.h", "errno.h", "getopt.h",
"limits.h", "stdio.h" ],
"argz.h": [ "errno.h", "string.h" ],
@@ -594,7 +591,7 @@ HEADER_ALLOWED_INCLUDES = {
# Nonstandardized sys/ headers
"sys/acct.h": [ "endian.h", "stdint.h", "sys/types.h" ],
- "sys/auxv.h": [ "elf.h", "sys/cdefs.h" ],
+ "sys/auxv.h": [ "elf.h" ],
"sys/elf.h": [ "sys/procfs.h" ],
"sys/epoll.h": [ "stdint.h", "sys/types.h" ],
"sys/eventfd.h": [ "stdint.h" ],
@@ -649,16 +646,16 @@ HEADER_ALLOWED_INCLUDES = {
# Nonstandardized networking headers
"ifaddrs.h": [ "sys/socket.h" ],
"resolv.h": [ "arpa/nameser.h", "netinet/in.h",
- "stdio.h", "sys/cdefs.h", "sys/param.h",\
+ "stdio.h", "sys/param.h",
"sys/types.h" ],
"arpa/nameser.h": [ "arpa/nameser_compat.h", "stdint.h",
"sys/param.h", "sys/types.h" ],
"arpa/nameser_compat.h": [ "endian.h" ],
- "net/ethernet.h": [ "stdint.h", "sys/types.h", "sys/cdefs.h",
+ "net/ethernet.h": [ "stdint.h", "sys/types.h",
"net/if_ether.h" ],
"net/if_arp.h": [ "stdint.h", "sys/socket.h",
- "sys/types.h", "sys/cdefs.h" ],
+ "sys/types.h" ],
"net/if_ppp.h": [ "net/if.h", "net/ppp_defs.h", "stdint.h",
"sys/ioctl.h", "sys/types.h" ],
"net/if_shaper.h": [ "net/if.h", "stdint.h", "sys/ioctl.h",
@@ -673,8 +670,7 @@ HEADER_ALLOWED_INCLUDES = {
"sys/types.h", "stdint.h" ],
"netinet/if_fddi.h": [ "stdint.h", "sys/types.h" ],
"netinet/if_tr.h": [ "stdint.h", "sys/types.h" ],
- "netinet/igmp.h": [ "netinet/in.h", "sys/cdefs.h",
- "sys/types.h" ],
+ "netinet/igmp.h": [ "netinet/in.h", "sys/types.h" ],
"netinet/in_systm.h": [ "stdint.h", "sys/types.h" ],
"netinet/ip.h": [ "netinet/in.h", "sys/types.h" ],
"netinet/ip6.h": [ "inttypes.h", "netinet/in.h" ],
diff --git a/socket/sys/un.h b/socket/sys/un.h
index 95400f7..8bc9c3a 100644
--- a/socket/sys/un.h
+++ b/socket/sys/un.h
@@ -18,7 +18,7 @@
#ifndef _SYS_UN_H
#define _SYS_UN_H 1
-#include <sys/cdefs.h>
+#include <features.h>
/* Get the definition of the macro to define the common sockaddr members. */
#include <bits/sockaddr.h>
diff --git a/sunrpc/rpc/auth_des.h b/sunrpc/rpc/auth_des.h
index 79b49ad..f7437bb 100644
--- a/sunrpc/rpc/auth_des.h
+++ b/sunrpc/rpc/auth_des.h
@@ -18,7 +18,8 @@
#ifndef _RPC_AUTH_DES_H
#define _RPC_AUTH_DES_H 1
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <rpc/auth.h>
__BEGIN_DECLS
diff --git a/sunrpc/rpc/rpc_msg.h b/sunrpc/rpc/rpc_msg.h
index a2cc516..efd9ee4 100644
--- a/sunrpc/rpc/rpc_msg.h
+++ b/sunrpc/rpc/rpc_msg.h
@@ -35,7 +35,7 @@
#ifndef _RPC_MSG_H
#define _RPC_MSG_H 1
-#include <sys/cdefs.h>
+#include <features.h>
#include <rpc/xdr.h>
#include <rpc/clnt.h>
diff --git a/sysdeps/generic/memcopy.h b/sysdeps/generic/memcopy.h
index 0b09ca3..a2d37a1 100644
--- a/sysdeps/generic/memcopy.h
+++ b/sysdeps/generic/memcopy.h
@@ -20,6 +20,8 @@
#ifndef _MEMCOPY_H
#define _MEMCOPY_H 1
+#include <features.h>
+
/* The strategy of the memory functions is:
1. Copy bytes until the destination pointer is aligned.
@@ -38,7 +40,6 @@
exhaustive in the sense that I tried all alignment and length
combinations, with and without overlap. */
-#include <sys/cdefs.h>
#include <endian.h>
#include <pagecopy.h>
diff --git a/sysdeps/generic/netinet/tcp.h b/sysdeps/generic/netinet/tcp.h
index 49f1bfb..3b59e94 100644
--- a/sysdeps/generic/netinet/tcp.h
+++ b/sysdeps/generic/netinet/tcp.h
@@ -30,10 +30,9 @@
*/
#ifndef _NETINET_TCP_H
-
#define _NETINET_TCP_H 1
-#include <sys/cdefs.h>
+#include <features.h>
__BEGIN_DECLS
diff --git a/sysdeps/htl/pthread.h b/sysdeps/htl/pthread.h
index 3216860..2f9d377 100644
--- a/sysdeps/htl/pthread.h
+++ b/sysdeps/htl/pthread.h
@@ -25,7 +25,6 @@
#include <features.h>
-#include <sys/cdefs.h>
#ifndef __extern_inline
/* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
inline semantics, unless -fgnu89-inline is used. */
diff --git a/sysdeps/mach/hurd/net/ethernet.h b/sysdeps/mach/hurd/net/ethernet.h
index 06beb6c..53b2e39 100644
--- a/sysdeps/mach/hurd/net/ethernet.h
+++ b/sysdeps/mach/hurd/net/ethernet.h
@@ -21,7 +21,8 @@
#ifndef __NET_ETHERNET_H
#define __NET_ETHERNET_H 1
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <sys/types.h>
#include <stdint.h>
#include <net/if_ether.h> /* IEEE 802.3 Ethernet constants */
diff --git a/sysdeps/mach/hurd/net/if_arp.h b/sysdeps/mach/hurd/net/if_arp.h
index 0fa9bce..ffb6ef1 100644
--- a/sysdeps/mach/hurd/net/if_arp.h
+++ b/sysdeps/mach/hurd/net/if_arp.h
@@ -20,9 +20,9 @@
/* Based on the 4.4BSD and Linux version of this file. */
#ifndef _NET_IF_ARP_H
-
#define _NET_IF_ARP_H 1
-#include <sys/cdefs.h>
+
+#include <features.h>
#include <sys/types.h>
#include <sys/socket.h>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [glibc/zack/no-nested-includes] Don’t include sys/cdefs.h directly from public headers.
@ 2019-06-26 15:50 Zack Weinberg
0 siblings, 0 replies; 7+ messages in thread
From: Zack Weinberg @ 2019-06-26 15:50 UTC (permalink / raw)
To: glibc-cvs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 13870 bytes --]
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=1ac61f017f6d181c583b640a26c15643617ebdb7
commit 1ac61f017f6d181c583b640a26c15643617ebdb7
Author: Zack Weinberg <zackw@panix.com>
Date: Tue Jun 18 11:47:49 2019 -0400
Donât include sys/cdefs.h directly from public headers.
The convention throughout glibc is that every public header includes
features.h directly, as its first action, and relies on features.h to
include sys/cdefs.h. In a few places, though, itâs been done the
other way around, usually in headers that were copied from a BSD
source (where the convention is exactly the opposite). This patch
makes all installed headers match the glibc convention.
This patch also corrects a bug in glob.h: it may declare size_t
without notifying stddef.h that it has done this, so e.g.
#define _XOPEN_SOURCE 700
#include <glob.h>
#include <stddef.h>
int dummy;
declares size_t twice, which is invalid prior to C2011. I wasnât able
to persuade gcc 8 to issue an error, even with -std=c89 -Wsystem-headers,
but clang is not so lenient.
* posix/glob.h: Include features.h, not sys/cdefs.h.
When __USE_XOPEN || USE_XOPEN2K8, include stddef.h for size_t;
otherwise, issue an immediate #error if __SIZE_TYPE__ is not
available. Use __gsize_t, not __size_t, as an impl-namespace
alternative name for size_t.
* conform/data/glob.h-data: Adjust to match.
* inet/netinet/igmp.h, mach/lock-intern.h, misc/ar.h
* misc/sys/auxv.h, resolv/resolv.h, socket/sys/un.h
* sunrpc/rpc/auth_des.h, sunrpc/rpc/rpc_msg.h
* sysdeps/generic/memcopy.h, sysdeps/generic/netinet/tcp.h
* sysdeps/htl/pthread.h, sysdeps/mach/hurd/net/ethernet.h
* sysdeps/mach/hurd/net/if_arp.h: Include features.h, not sys/cdefs.h.
* scripts/check-obsolete-constructs.py (HEADER_ALLOWED_INCLUDES):
Update.
Diff:
---
conform/data/glob.h-data | 2 +-
inet/netinet/igmp.h | 3 ++-
mach/lock-intern.h | 3 ++-
misc/ar.h | 2 +-
misc/sys/auxv.h | 3 ++-
posix/glob.h | 33 ++++++++++++++++++---------------
resolv/resolv.h | 3 ++-
scripts/check-obsolete-constructs.py | 18 +++++++-----------
socket/sys/un.h | 2 +-
sunrpc/rpc/auth_des.h | 3 ++-
sunrpc/rpc/rpc_msg.h | 2 +-
sysdeps/generic/memcopy.h | 3 ++-
sysdeps/generic/netinet/tcp.h | 3 +--
sysdeps/htl/pthread.h | 1 -
sysdeps/mach/hurd/net/ethernet.h | 3 ++-
sysdeps/mach/hurd/net/if_arp.h | 4 ++--
16 files changed, 46 insertions(+), 42 deletions(-)
diff --git a/conform/data/glob.h-data b/conform/data/glob.h-data
index eca8393..6268134 100644
--- a/conform/data/glob.h-data
+++ b/conform/data/glob.h-data
@@ -1,6 +1,6 @@
#if !defined ISO && !defined ISO99 && !defined ISO11
#ifdef POSIX
-# define size_t __size_t
+# define size_t __gsize_t
#endif
type glob_t
diff --git a/inet/netinet/igmp.h b/inet/netinet/igmp.h
index 451b1ab..2884db5 100644
--- a/inet/netinet/igmp.h
+++ b/inet/netinet/igmp.h
@@ -18,7 +18,8 @@
#ifndef _NETINET_IGMP_H
#define _NETINET_IGMP_H 1
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <sys/types.h>
#ifdef __USE_MISC
diff --git a/mach/lock-intern.h b/mach/lock-intern.h
index 1988c89..a409abb 100644
--- a/mach/lock-intern.h
+++ b/mach/lock-intern.h
@@ -18,7 +18,8 @@
#ifndef _LOCK_INTERN_H
#define _LOCK_INTERN_H
-#include <sys/cdefs.h>
+#include <features.h>
+
#if defined __USE_EXTERN_INLINES && defined _LIBC
# include <lowlevellock.h>
#endif
diff --git a/misc/ar.h b/misc/ar.h
index ef2303e..adcfda4 100644
--- a/misc/ar.h
+++ b/misc/ar.h
@@ -19,7 +19,7 @@
#ifndef _AR_H
#define _AR_H 1
-#include <sys/cdefs.h>
+#include <features.h>
/* Archive files start with the ARMAG identifying string. Then follows a
`struct ar_hdr', and as many bytes of member file data as its `ar_size'
diff --git a/misc/sys/auxv.h b/misc/sys/auxv.h
index 68363b3..404da6f 100644
--- a/misc/sys/auxv.h
+++ b/misc/sys/auxv.h
@@ -19,8 +19,9 @@
#ifndef _SYS_AUXV_H
#define _SYS_AUXV_H 1
+#include <features.h>
+
#include <elf.h>
-#include <sys/cdefs.h>
#include <bits/hwcap.h>
__BEGIN_DECLS
diff --git a/posix/glob.h b/posix/glob.h
index 378b80a..e49e6c0 100644
--- a/posix/glob.h
+++ b/posix/glob.h
@@ -18,21 +18,24 @@
#ifndef _GLOB_H
#define _GLOB_H 1
-#include <sys/cdefs.h>
+#include <features.h>
__BEGIN_DECLS
-/* We need `size_t' for the following definitions. */
-#ifndef __size_t
-typedef __SIZE_TYPE__ __size_t;
-# if defined __USE_XOPEN || defined __USE_XOPEN2K8
-typedef __SIZE_TYPE__ size_t;
-# endif
+/* Structures below have size_t fields, but this header is not supposed to
+ define size_t itself, unless XSI or POSIX.1-2008 features are active.
+ We can't use __size_t as an alternative name, as we do for most types
+ with this kind of constraint, because GCC's stddef.h uses __size_t for
+ a different purpose. */
+
+#if defined __USE_XOPEN || defined __USE_XOPEN2K8
+# define __need_size_t
+# include <stddef.h>
+typedef size_t __gsize_t;
+#elif defined __SIZE_TYPE__
+typedef __SIZE_TYPE__ __gsize_t;
#else
-/* The GNU CC stddef.h version defines __size_t as empty. We need a real
- definition. */
-# undef __size_t
-# define __size_t size_t
+# error "Don't know how to define __gsize_t"
#endif
/* Bits set in the FLAGS argument to `glob'. */
@@ -81,9 +84,9 @@ struct stat;
#endif
typedef struct
{
- __size_t gl_pathc; /* Count of paths matched by the pattern. */
+ __gsize_t gl_pathc; /* Count of paths matched by the pattern. */
char **gl_pathv; /* List of matched pathnames. */
- __size_t gl_offs; /* Slots to reserve in `gl_pathv'. */
+ __gsize_t gl_offs; /* Slots to reserve in `gl_pathv'. */
int gl_flags; /* Set to FLAGS, maybe | GLOB_MAGCHAR. */
/* If the GLOB_ALTDIRFUNC flag is set, the following functions
@@ -110,9 +113,9 @@ struct stat64;
# endif
typedef struct
{
- __size_t gl_pathc;
+ __gsize_t gl_pathc;
char **gl_pathv;
- __size_t gl_offs;
+ __gsize_t gl_offs;
int gl_flags;
/* If the GLOB_ALTDIRFUNC flag is set, the following functions
diff --git a/resolv/resolv.h b/resolv/resolv.h
index 7a8023a..b4ef66f 100644
--- a/resolv/resolv.h
+++ b/resolv/resolv.h
@@ -52,7 +52,8 @@
#ifndef _RESOLV_H_
#define _RESOLV_H_
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <sys/param.h>
#include <sys/types.h>
#include <stdio.h>
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index 0853434..e383a30 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -527,11 +527,9 @@ HEADER_ALLOWED_INCLUDES = {
# spawn.h -> sched.h
"aio.h": [ "sys/types.h" ],
"ftw.h": [ "sys/stat.h", "sys/types.h" ],
- "glob.h": [ "sys/cdefs.h" ],
"langinfo.h": [ "nl_types.h" ],
"mqueue.h": [ "fcntl.h", "sys/types.h" ],
- "pthread.h": [ "endian.h", "sched.h", "time.h",
- "sys/cdefs.h" ],
+ "pthread.h": [ "sched.h", "time.h" ],
"regex.h": [ "limits.h", "sys/types.h" ],
"sched.h": [ "time.h" ],
"semaphore.h": [ "sys/types.h" ],
@@ -550,7 +548,7 @@ HEADER_ALLOWED_INCLUDES = {
"sys/time.h": [ "sys/select.h" ],
"sys/types.h": [ "endian.h", "sys/select.h" ],
"sys/uio.h": [ "sys/types.h" ],
- "sys/un.h": [ "string.h", "sys/cdefs.h" ],
+ "sys/un.h": [ "string.h" ],
"sys/wait.h": [ "signal.h" ],
# POSIX networking headers
@@ -565,7 +563,6 @@ HEADER_ALLOWED_INCLUDES = {
# Nonstandardized top-level headers
"aliases.h": [ "sys/types.h" ],
- "ar.h": [ "sys/cdefs.h" ],
"argp.h": [ "ctype.h", "errno.h", "getopt.h",
"limits.h", "stdio.h" ],
"argz.h": [ "errno.h", "string.h" ],
@@ -594,7 +591,7 @@ HEADER_ALLOWED_INCLUDES = {
# Nonstandardized sys/ headers
"sys/acct.h": [ "endian.h", "stdint.h", "sys/types.h" ],
- "sys/auxv.h": [ "elf.h", "sys/cdefs.h" ],
+ "sys/auxv.h": [ "elf.h" ],
"sys/elf.h": [ "sys/procfs.h" ],
"sys/epoll.h": [ "stdint.h", "sys/types.h" ],
"sys/eventfd.h": [ "stdint.h" ],
@@ -649,16 +646,16 @@ HEADER_ALLOWED_INCLUDES = {
# Nonstandardized networking headers
"ifaddrs.h": [ "sys/socket.h" ],
"resolv.h": [ "arpa/nameser.h", "netinet/in.h",
- "stdio.h", "sys/cdefs.h", "sys/param.h",\
+ "stdio.h", "sys/param.h",
"sys/types.h" ],
"arpa/nameser.h": [ "arpa/nameser_compat.h", "stdint.h",
"sys/param.h", "sys/types.h" ],
"arpa/nameser_compat.h": [ "endian.h" ],
- "net/ethernet.h": [ "stdint.h", "sys/types.h", "sys/cdefs.h",
+ "net/ethernet.h": [ "stdint.h", "sys/types.h",
"net/if_ether.h" ],
"net/if_arp.h": [ "stdint.h", "sys/socket.h",
- "sys/types.h", "sys/cdefs.h" ],
+ "sys/types.h" ],
"net/if_ppp.h": [ "net/if.h", "net/ppp_defs.h", "stdint.h",
"sys/ioctl.h", "sys/types.h" ],
"net/if_shaper.h": [ "net/if.h", "stdint.h", "sys/ioctl.h",
@@ -673,8 +670,7 @@ HEADER_ALLOWED_INCLUDES = {
"sys/types.h", "stdint.h" ],
"netinet/if_fddi.h": [ "stdint.h", "sys/types.h" ],
"netinet/if_tr.h": [ "stdint.h", "sys/types.h" ],
- "netinet/igmp.h": [ "netinet/in.h", "sys/cdefs.h",
- "sys/types.h" ],
+ "netinet/igmp.h": [ "netinet/in.h", "sys/types.h" ],
"netinet/in_systm.h": [ "stdint.h", "sys/types.h" ],
"netinet/ip.h": [ "netinet/in.h", "sys/types.h" ],
"netinet/ip6.h": [ "inttypes.h", "netinet/in.h" ],
diff --git a/socket/sys/un.h b/socket/sys/un.h
index 1268360..8c7433a 100644
--- a/socket/sys/un.h
+++ b/socket/sys/un.h
@@ -18,7 +18,7 @@
#ifndef _SYS_UN_H
#define _SYS_UN_H 1
-#include <sys/cdefs.h>
+#include <features.h>
/* Get the definition of the macro to define the common sockaddr members. */
#include <bits/sockaddr.h>
diff --git a/sunrpc/rpc/auth_des.h b/sunrpc/rpc/auth_des.h
index 245675f..e60e795 100644
--- a/sunrpc/rpc/auth_des.h
+++ b/sunrpc/rpc/auth_des.h
@@ -18,7 +18,8 @@
#ifndef _RPC_AUTH_DES_H
#define _RPC_AUTH_DES_H 1
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <rpc/auth.h>
__BEGIN_DECLS
diff --git a/sunrpc/rpc/rpc_msg.h b/sunrpc/rpc/rpc_msg.h
index a2cc516..efd9ee4 100644
--- a/sunrpc/rpc/rpc_msg.h
+++ b/sunrpc/rpc/rpc_msg.h
@@ -35,7 +35,7 @@
#ifndef _RPC_MSG_H
#define _RPC_MSG_H 1
-#include <sys/cdefs.h>
+#include <features.h>
#include <rpc/xdr.h>
#include <rpc/clnt.h>
diff --git a/sysdeps/generic/memcopy.h b/sysdeps/generic/memcopy.h
index e10d01e..de32e56 100644
--- a/sysdeps/generic/memcopy.h
+++ b/sysdeps/generic/memcopy.h
@@ -20,6 +20,8 @@
#ifndef _MEMCOPY_H
#define _MEMCOPY_H 1
+#include <features.h>
+
/* The strategy of the memory functions is:
1. Copy bytes until the destination pointer is aligned.
@@ -38,7 +40,6 @@
exhaustive in the sense that I tried all alignment and length
combinations, with and without overlap. */
-#include <sys/cdefs.h>
#include <endian.h>
#include <pagecopy.h>
diff --git a/sysdeps/generic/netinet/tcp.h b/sysdeps/generic/netinet/tcp.h
index 49f1bfb..3b59e94 100644
--- a/sysdeps/generic/netinet/tcp.h
+++ b/sysdeps/generic/netinet/tcp.h
@@ -30,10 +30,9 @@
*/
#ifndef _NETINET_TCP_H
-
#define _NETINET_TCP_H 1
-#include <sys/cdefs.h>
+#include <features.h>
__BEGIN_DECLS
diff --git a/sysdeps/htl/pthread.h b/sysdeps/htl/pthread.h
index a820551..158a095 100644
--- a/sysdeps/htl/pthread.h
+++ b/sysdeps/htl/pthread.h
@@ -25,7 +25,6 @@
#include <features.h>
-#include <sys/cdefs.h>
#ifndef __extern_inline
/* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
inline semantics, unless -fgnu89-inline is used. */
diff --git a/sysdeps/mach/hurd/net/ethernet.h b/sysdeps/mach/hurd/net/ethernet.h
index 4aa67ea..8956694 100644
--- a/sysdeps/mach/hurd/net/ethernet.h
+++ b/sysdeps/mach/hurd/net/ethernet.h
@@ -21,7 +21,8 @@
#ifndef __NET_ETHERNET_H
#define __NET_ETHERNET_H 1
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <sys/types.h>
#include <stdint.h>
#include <net/if_ether.h> /* IEEE 802.3 Ethernet constants */
diff --git a/sysdeps/mach/hurd/net/if_arp.h b/sysdeps/mach/hurd/net/if_arp.h
index 6ef93c9..9e1b223 100644
--- a/sysdeps/mach/hurd/net/if_arp.h
+++ b/sysdeps/mach/hurd/net/if_arp.h
@@ -20,9 +20,9 @@
/* Based on the 4.4BSD and Linux version of this file. */
#ifndef _NET_IF_ARP_H
-
#define _NET_IF_ARP_H 1
-#include <sys/cdefs.h>
+
+#include <features.h>
#include <sys/types.h>
#include <sys/socket.h>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [glibc/zack/no-nested-includes] Don’t include sys/cdefs.h directly from public headers.
@ 2019-06-20 16:06 Zack Weinberg
0 siblings, 0 replies; 7+ messages in thread
From: Zack Weinberg @ 2019-06-20 16:06 UTC (permalink / raw)
To: glibc-cvs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 13870 bytes --]
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c93470c99bb2eb032d4892d8de2d388b9d632d62
commit c93470c99bb2eb032d4892d8de2d388b9d632d62
Author: Zack Weinberg <zackw@panix.com>
Date: Tue Jun 18 11:47:49 2019 -0400
Donât include sys/cdefs.h directly from public headers.
The convention throughout glibc is that every public header includes
features.h directly, as its first action, and relies on features.h to
include sys/cdefs.h. In a few places, though, itâs been done the
other way around, usually in headers that were copied from a BSD
source (where the convention is exactly the opposite). This patch
makes all installed headers match the glibc convention.
This patch also corrects a bug in glob.h: it may declare size_t
without notifying stddef.h that it has done this, so e.g.
#define _XOPEN_SOURCE 700
#include <glob.h>
#include <stddef.h>
int dummy;
declares size_t twice, which is invalid prior to C2011. I wasnât able
to persuade gcc 8 to issue an error, even with -std=c89 -Wsystem-headers,
but clang is not so lenient.
* posix/glob.h: Include features.h, not sys/cdefs.h.
When __USE_XOPEN || USE_XOPEN2K8, include stddef.h for size_t;
otherwise, issue an immediate #error if __SIZE_TYPE__ is not
available. Use __gsize_t, not __size_t, as an impl-namespace
alternative name for size_t.
* conform/data/glob.h-data: Adjust to match.
* inet/netinet/igmp.h, mach/lock-intern.h, misc/ar.h
* misc/sys/auxv.h, resolv/resolv.h, socket/sys/un.h
* sunrpc/rpc/auth_des.h, sunrpc/rpc/rpc_msg.h
* sysdeps/generic/memcopy.h, sysdeps/generic/netinet/tcp.h
* sysdeps/htl/pthread.h, sysdeps/mach/hurd/net/ethernet.h
* sysdeps/mach/hurd/net/if_arp.h: Include features.h, not sys/cdefs.h.
* scripts/check-obsolete-constructs.py (HEADER_ALLOWED_INCLUDES):
Update.
Diff:
---
conform/data/glob.h-data | 2 +-
inet/netinet/igmp.h | 3 ++-
mach/lock-intern.h | 3 ++-
misc/ar.h | 2 +-
misc/sys/auxv.h | 3 ++-
posix/glob.h | 33 ++++++++++++++++++---------------
resolv/resolv.h | 3 ++-
scripts/check-obsolete-constructs.py | 18 +++++++-----------
socket/sys/un.h | 2 +-
sunrpc/rpc/auth_des.h | 3 ++-
sunrpc/rpc/rpc_msg.h | 2 +-
sysdeps/generic/memcopy.h | 3 ++-
sysdeps/generic/netinet/tcp.h | 3 +--
sysdeps/htl/pthread.h | 1 -
sysdeps/mach/hurd/net/ethernet.h | 3 ++-
sysdeps/mach/hurd/net/if_arp.h | 4 ++--
16 files changed, 46 insertions(+), 42 deletions(-)
diff --git a/conform/data/glob.h-data b/conform/data/glob.h-data
index eca8393..6268134 100644
--- a/conform/data/glob.h-data
+++ b/conform/data/glob.h-data
@@ -1,6 +1,6 @@
#if !defined ISO && !defined ISO99 && !defined ISO11
#ifdef POSIX
-# define size_t __size_t
+# define size_t __gsize_t
#endif
type glob_t
diff --git a/inet/netinet/igmp.h b/inet/netinet/igmp.h
index 451b1ab..2884db5 100644
--- a/inet/netinet/igmp.h
+++ b/inet/netinet/igmp.h
@@ -18,7 +18,8 @@
#ifndef _NETINET_IGMP_H
#define _NETINET_IGMP_H 1
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <sys/types.h>
#ifdef __USE_MISC
diff --git a/mach/lock-intern.h b/mach/lock-intern.h
index 1988c89..a409abb 100644
--- a/mach/lock-intern.h
+++ b/mach/lock-intern.h
@@ -18,7 +18,8 @@
#ifndef _LOCK_INTERN_H
#define _LOCK_INTERN_H
-#include <sys/cdefs.h>
+#include <features.h>
+
#if defined __USE_EXTERN_INLINES && defined _LIBC
# include <lowlevellock.h>
#endif
diff --git a/misc/ar.h b/misc/ar.h
index ef2303e..adcfda4 100644
--- a/misc/ar.h
+++ b/misc/ar.h
@@ -19,7 +19,7 @@
#ifndef _AR_H
#define _AR_H 1
-#include <sys/cdefs.h>
+#include <features.h>
/* Archive files start with the ARMAG identifying string. Then follows a
`struct ar_hdr', and as many bytes of member file data as its `ar_size'
diff --git a/misc/sys/auxv.h b/misc/sys/auxv.h
index 68363b3..404da6f 100644
--- a/misc/sys/auxv.h
+++ b/misc/sys/auxv.h
@@ -19,8 +19,9 @@
#ifndef _SYS_AUXV_H
#define _SYS_AUXV_H 1
+#include <features.h>
+
#include <elf.h>
-#include <sys/cdefs.h>
#include <bits/hwcap.h>
__BEGIN_DECLS
diff --git a/posix/glob.h b/posix/glob.h
index 378b80a..e49e6c0 100644
--- a/posix/glob.h
+++ b/posix/glob.h
@@ -18,21 +18,24 @@
#ifndef _GLOB_H
#define _GLOB_H 1
-#include <sys/cdefs.h>
+#include <features.h>
__BEGIN_DECLS
-/* We need `size_t' for the following definitions. */
-#ifndef __size_t
-typedef __SIZE_TYPE__ __size_t;
-# if defined __USE_XOPEN || defined __USE_XOPEN2K8
-typedef __SIZE_TYPE__ size_t;
-# endif
+/* Structures below have size_t fields, but this header is not supposed to
+ define size_t itself, unless XSI or POSIX.1-2008 features are active.
+ We can't use __size_t as an alternative name, as we do for most types
+ with this kind of constraint, because GCC's stddef.h uses __size_t for
+ a different purpose. */
+
+#if defined __USE_XOPEN || defined __USE_XOPEN2K8
+# define __need_size_t
+# include <stddef.h>
+typedef size_t __gsize_t;
+#elif defined __SIZE_TYPE__
+typedef __SIZE_TYPE__ __gsize_t;
#else
-/* The GNU CC stddef.h version defines __size_t as empty. We need a real
- definition. */
-# undef __size_t
-# define __size_t size_t
+# error "Don't know how to define __gsize_t"
#endif
/* Bits set in the FLAGS argument to `glob'. */
@@ -81,9 +84,9 @@ struct stat;
#endif
typedef struct
{
- __size_t gl_pathc; /* Count of paths matched by the pattern. */
+ __gsize_t gl_pathc; /* Count of paths matched by the pattern. */
char **gl_pathv; /* List of matched pathnames. */
- __size_t gl_offs; /* Slots to reserve in `gl_pathv'. */
+ __gsize_t gl_offs; /* Slots to reserve in `gl_pathv'. */
int gl_flags; /* Set to FLAGS, maybe | GLOB_MAGCHAR. */
/* If the GLOB_ALTDIRFUNC flag is set, the following functions
@@ -110,9 +113,9 @@ struct stat64;
# endif
typedef struct
{
- __size_t gl_pathc;
+ __gsize_t gl_pathc;
char **gl_pathv;
- __size_t gl_offs;
+ __gsize_t gl_offs;
int gl_flags;
/* If the GLOB_ALTDIRFUNC flag is set, the following functions
diff --git a/resolv/resolv.h b/resolv/resolv.h
index 7a8023a..b4ef66f 100644
--- a/resolv/resolv.h
+++ b/resolv/resolv.h
@@ -52,7 +52,8 @@
#ifndef _RESOLV_H_
#define _RESOLV_H_
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <sys/param.h>
#include <sys/types.h>
#include <stdio.h>
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index 0853434..e383a30 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -527,11 +527,9 @@ HEADER_ALLOWED_INCLUDES = {
# spawn.h -> sched.h
"aio.h": [ "sys/types.h" ],
"ftw.h": [ "sys/stat.h", "sys/types.h" ],
- "glob.h": [ "sys/cdefs.h" ],
"langinfo.h": [ "nl_types.h" ],
"mqueue.h": [ "fcntl.h", "sys/types.h" ],
- "pthread.h": [ "endian.h", "sched.h", "time.h",
- "sys/cdefs.h" ],
+ "pthread.h": [ "sched.h", "time.h" ],
"regex.h": [ "limits.h", "sys/types.h" ],
"sched.h": [ "time.h" ],
"semaphore.h": [ "sys/types.h" ],
@@ -550,7 +548,7 @@ HEADER_ALLOWED_INCLUDES = {
"sys/time.h": [ "sys/select.h" ],
"sys/types.h": [ "endian.h", "sys/select.h" ],
"sys/uio.h": [ "sys/types.h" ],
- "sys/un.h": [ "string.h", "sys/cdefs.h" ],
+ "sys/un.h": [ "string.h" ],
"sys/wait.h": [ "signal.h" ],
# POSIX networking headers
@@ -565,7 +563,6 @@ HEADER_ALLOWED_INCLUDES = {
# Nonstandardized top-level headers
"aliases.h": [ "sys/types.h" ],
- "ar.h": [ "sys/cdefs.h" ],
"argp.h": [ "ctype.h", "errno.h", "getopt.h",
"limits.h", "stdio.h" ],
"argz.h": [ "errno.h", "string.h" ],
@@ -594,7 +591,7 @@ HEADER_ALLOWED_INCLUDES = {
# Nonstandardized sys/ headers
"sys/acct.h": [ "endian.h", "stdint.h", "sys/types.h" ],
- "sys/auxv.h": [ "elf.h", "sys/cdefs.h" ],
+ "sys/auxv.h": [ "elf.h" ],
"sys/elf.h": [ "sys/procfs.h" ],
"sys/epoll.h": [ "stdint.h", "sys/types.h" ],
"sys/eventfd.h": [ "stdint.h" ],
@@ -649,16 +646,16 @@ HEADER_ALLOWED_INCLUDES = {
# Nonstandardized networking headers
"ifaddrs.h": [ "sys/socket.h" ],
"resolv.h": [ "arpa/nameser.h", "netinet/in.h",
- "stdio.h", "sys/cdefs.h", "sys/param.h",\
+ "stdio.h", "sys/param.h",
"sys/types.h" ],
"arpa/nameser.h": [ "arpa/nameser_compat.h", "stdint.h",
"sys/param.h", "sys/types.h" ],
"arpa/nameser_compat.h": [ "endian.h" ],
- "net/ethernet.h": [ "stdint.h", "sys/types.h", "sys/cdefs.h",
+ "net/ethernet.h": [ "stdint.h", "sys/types.h",
"net/if_ether.h" ],
"net/if_arp.h": [ "stdint.h", "sys/socket.h",
- "sys/types.h", "sys/cdefs.h" ],
+ "sys/types.h" ],
"net/if_ppp.h": [ "net/if.h", "net/ppp_defs.h", "stdint.h",
"sys/ioctl.h", "sys/types.h" ],
"net/if_shaper.h": [ "net/if.h", "stdint.h", "sys/ioctl.h",
@@ -673,8 +670,7 @@ HEADER_ALLOWED_INCLUDES = {
"sys/types.h", "stdint.h" ],
"netinet/if_fddi.h": [ "stdint.h", "sys/types.h" ],
"netinet/if_tr.h": [ "stdint.h", "sys/types.h" ],
- "netinet/igmp.h": [ "netinet/in.h", "sys/cdefs.h",
- "sys/types.h" ],
+ "netinet/igmp.h": [ "netinet/in.h", "sys/types.h" ],
"netinet/in_systm.h": [ "stdint.h", "sys/types.h" ],
"netinet/ip.h": [ "netinet/in.h", "sys/types.h" ],
"netinet/ip6.h": [ "inttypes.h", "netinet/in.h" ],
diff --git a/socket/sys/un.h b/socket/sys/un.h
index 1268360..8c7433a 100644
--- a/socket/sys/un.h
+++ b/socket/sys/un.h
@@ -18,7 +18,7 @@
#ifndef _SYS_UN_H
#define _SYS_UN_H 1
-#include <sys/cdefs.h>
+#include <features.h>
/* Get the definition of the macro to define the common sockaddr members. */
#include <bits/sockaddr.h>
diff --git a/sunrpc/rpc/auth_des.h b/sunrpc/rpc/auth_des.h
index 245675f..e60e795 100644
--- a/sunrpc/rpc/auth_des.h
+++ b/sunrpc/rpc/auth_des.h
@@ -18,7 +18,8 @@
#ifndef _RPC_AUTH_DES_H
#define _RPC_AUTH_DES_H 1
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <rpc/auth.h>
__BEGIN_DECLS
diff --git a/sunrpc/rpc/rpc_msg.h b/sunrpc/rpc/rpc_msg.h
index a2cc516..efd9ee4 100644
--- a/sunrpc/rpc/rpc_msg.h
+++ b/sunrpc/rpc/rpc_msg.h
@@ -35,7 +35,7 @@
#ifndef _RPC_MSG_H
#define _RPC_MSG_H 1
-#include <sys/cdefs.h>
+#include <features.h>
#include <rpc/xdr.h>
#include <rpc/clnt.h>
diff --git a/sysdeps/generic/memcopy.h b/sysdeps/generic/memcopy.h
index e10d01e..de32e56 100644
--- a/sysdeps/generic/memcopy.h
+++ b/sysdeps/generic/memcopy.h
@@ -20,6 +20,8 @@
#ifndef _MEMCOPY_H
#define _MEMCOPY_H 1
+#include <features.h>
+
/* The strategy of the memory functions is:
1. Copy bytes until the destination pointer is aligned.
@@ -38,7 +40,6 @@
exhaustive in the sense that I tried all alignment and length
combinations, with and without overlap. */
-#include <sys/cdefs.h>
#include <endian.h>
#include <pagecopy.h>
diff --git a/sysdeps/generic/netinet/tcp.h b/sysdeps/generic/netinet/tcp.h
index 49f1bfb..3b59e94 100644
--- a/sysdeps/generic/netinet/tcp.h
+++ b/sysdeps/generic/netinet/tcp.h
@@ -30,10 +30,9 @@
*/
#ifndef _NETINET_TCP_H
-
#define _NETINET_TCP_H 1
-#include <sys/cdefs.h>
+#include <features.h>
__BEGIN_DECLS
diff --git a/sysdeps/htl/pthread.h b/sysdeps/htl/pthread.h
index a820551..158a095 100644
--- a/sysdeps/htl/pthread.h
+++ b/sysdeps/htl/pthread.h
@@ -25,7 +25,6 @@
#include <features.h>
-#include <sys/cdefs.h>
#ifndef __extern_inline
/* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
inline semantics, unless -fgnu89-inline is used. */
diff --git a/sysdeps/mach/hurd/net/ethernet.h b/sysdeps/mach/hurd/net/ethernet.h
index 4aa67ea..8956694 100644
--- a/sysdeps/mach/hurd/net/ethernet.h
+++ b/sysdeps/mach/hurd/net/ethernet.h
@@ -21,7 +21,8 @@
#ifndef __NET_ETHERNET_H
#define __NET_ETHERNET_H 1
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <sys/types.h>
#include <stdint.h>
#include <net/if_ether.h> /* IEEE 802.3 Ethernet constants */
diff --git a/sysdeps/mach/hurd/net/if_arp.h b/sysdeps/mach/hurd/net/if_arp.h
index 6ef93c9..9e1b223 100644
--- a/sysdeps/mach/hurd/net/if_arp.h
+++ b/sysdeps/mach/hurd/net/if_arp.h
@@ -20,9 +20,9 @@
/* Based on the 4.4BSD and Linux version of this file. */
#ifndef _NET_IF_ARP_H
-
#define _NET_IF_ARP_H 1
-#include <sys/cdefs.h>
+
+#include <features.h>
#include <sys/types.h>
#include <sys/socket.h>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [glibc/zack/no-nested-includes] Don’t include sys/cdefs.h directly from public headers.
@ 2019-06-18 15:33 Zack Weinberg
0 siblings, 0 replies; 7+ messages in thread
From: Zack Weinberg @ 2019-06-18 15:33 UTC (permalink / raw)
To: glibc-cvs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 13864 bytes --]
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=e465c78bded048077a318a73931099aed0bc544f
commit e465c78bded048077a318a73931099aed0bc544f
Author: Zack Weinberg <zackw@panix.com>
Date: Sat Mar 16 14:31:08 2019 -0400
Donât include sys/cdefs.h directly from public headers.
The convention throughout glibc is that every public header includes
features.h directly, as its first action, and relies on features.h to
include sys/cdefs.h. In a few places, though, itâs been done the
other way around, usually in headers that were copied from a BSD
source (where the convention is exactly the opposite). This patch
makes all installed headers match the glibc convention.
This patch also corrects a bug in glob.h: it may declare size_t
without notifying stddef.h that it has done this, so e.g.
#define _XOPEN_SOURCE 700
#include <glob.h>
#include <stddef.h>
int dummy;
declares size_t twice, which is invalid prior to C2011. I wasnât able
to persuade gcc 8 to issue an error, even with -std=c89 -Wsystem-headers,
but clang is not so lenient.
* posix/glob.h: Include features.h, not sys/cdefs.h.
When __USE_XOPEN || USE_XOPEN2K8, include stddef.h for size_t;
otherwise, issue an immediate #error if __SIZE_TYPE__ is not
available. Use __gsize_t, not __size_t, as an impl-namespace
alternative name for size_t.
* conform/data/glob.h-data: Adjust to match.
* inet/netinet/igmp.h, mach/lock-intern.h, misc/ar.h
* misc/sys/auxv.h, resolv/resolv.h, socket/sys/un.h
* sunrpc/rpc/auth_des.h, sunrpc/rpc/rpc_msg.h
* sysdeps/generic/memcopy.h, sysdeps/generic/netinet/tcp.h
* sysdeps/htl/pthread.h, sysdeps/mach/hurd/net/ethernet.h
* sysdeps/mach/hurd/net/if_arp.h: Include features.h, not sys/cdefs.h.
* scripts/check-obsolete-constructs.py: Remove most whitelist
entries for sys/cdefs.h.
Diff:
---
conform/data/glob.h-data | 2 +-
inet/netinet/igmp.h | 3 ++-
mach/lock-intern.h | 3 ++-
misc/ar.h | 2 +-
misc/sys/auxv.h | 3 ++-
posix/glob.h | 33 ++++++++++++++++++---------------
resolv/resolv.h | 3 ++-
scripts/check-obsolete-constructs.py | 18 +++++++-----------
socket/sys/un.h | 2 +-
sunrpc/rpc/auth_des.h | 3 ++-
sunrpc/rpc/rpc_msg.h | 2 +-
sysdeps/generic/memcopy.h | 3 ++-
sysdeps/generic/netinet/tcp.h | 3 +--
sysdeps/htl/pthread.h | 1 -
sysdeps/mach/hurd/net/ethernet.h | 3 ++-
sysdeps/mach/hurd/net/if_arp.h | 4 ++--
16 files changed, 46 insertions(+), 42 deletions(-)
diff --git a/conform/data/glob.h-data b/conform/data/glob.h-data
index eca8393..6268134 100644
--- a/conform/data/glob.h-data
+++ b/conform/data/glob.h-data
@@ -1,6 +1,6 @@
#if !defined ISO && !defined ISO99 && !defined ISO11
#ifdef POSIX
-# define size_t __size_t
+# define size_t __gsize_t
#endif
type glob_t
diff --git a/inet/netinet/igmp.h b/inet/netinet/igmp.h
index 451b1ab..2884db5 100644
--- a/inet/netinet/igmp.h
+++ b/inet/netinet/igmp.h
@@ -18,7 +18,8 @@
#ifndef _NETINET_IGMP_H
#define _NETINET_IGMP_H 1
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <sys/types.h>
#ifdef __USE_MISC
diff --git a/mach/lock-intern.h b/mach/lock-intern.h
index 1988c89..a409abb 100644
--- a/mach/lock-intern.h
+++ b/mach/lock-intern.h
@@ -18,7 +18,8 @@
#ifndef _LOCK_INTERN_H
#define _LOCK_INTERN_H
-#include <sys/cdefs.h>
+#include <features.h>
+
#if defined __USE_EXTERN_INLINES && defined _LIBC
# include <lowlevellock.h>
#endif
diff --git a/misc/ar.h b/misc/ar.h
index ef2303e..adcfda4 100644
--- a/misc/ar.h
+++ b/misc/ar.h
@@ -19,7 +19,7 @@
#ifndef _AR_H
#define _AR_H 1
-#include <sys/cdefs.h>
+#include <features.h>
/* Archive files start with the ARMAG identifying string. Then follows a
`struct ar_hdr', and as many bytes of member file data as its `ar_size'
diff --git a/misc/sys/auxv.h b/misc/sys/auxv.h
index 68363b3..404da6f 100644
--- a/misc/sys/auxv.h
+++ b/misc/sys/auxv.h
@@ -19,8 +19,9 @@
#ifndef _SYS_AUXV_H
#define _SYS_AUXV_H 1
+#include <features.h>
+
#include <elf.h>
-#include <sys/cdefs.h>
#include <bits/hwcap.h>
__BEGIN_DECLS
diff --git a/posix/glob.h b/posix/glob.h
index 378b80a..e49e6c0 100644
--- a/posix/glob.h
+++ b/posix/glob.h
@@ -18,21 +18,24 @@
#ifndef _GLOB_H
#define _GLOB_H 1
-#include <sys/cdefs.h>
+#include <features.h>
__BEGIN_DECLS
-/* We need `size_t' for the following definitions. */
-#ifndef __size_t
-typedef __SIZE_TYPE__ __size_t;
-# if defined __USE_XOPEN || defined __USE_XOPEN2K8
-typedef __SIZE_TYPE__ size_t;
-# endif
+/* Structures below have size_t fields, but this header is not supposed to
+ define size_t itself, unless XSI or POSIX.1-2008 features are active.
+ We can't use __size_t as an alternative name, as we do for most types
+ with this kind of constraint, because GCC's stddef.h uses __size_t for
+ a different purpose. */
+
+#if defined __USE_XOPEN || defined __USE_XOPEN2K8
+# define __need_size_t
+# include <stddef.h>
+typedef size_t __gsize_t;
+#elif defined __SIZE_TYPE__
+typedef __SIZE_TYPE__ __gsize_t;
#else
-/* The GNU CC stddef.h version defines __size_t as empty. We need a real
- definition. */
-# undef __size_t
-# define __size_t size_t
+# error "Don't know how to define __gsize_t"
#endif
/* Bits set in the FLAGS argument to `glob'. */
@@ -81,9 +84,9 @@ struct stat;
#endif
typedef struct
{
- __size_t gl_pathc; /* Count of paths matched by the pattern. */
+ __gsize_t gl_pathc; /* Count of paths matched by the pattern. */
char **gl_pathv; /* List of matched pathnames. */
- __size_t gl_offs; /* Slots to reserve in `gl_pathv'. */
+ __gsize_t gl_offs; /* Slots to reserve in `gl_pathv'. */
int gl_flags; /* Set to FLAGS, maybe | GLOB_MAGCHAR. */
/* If the GLOB_ALTDIRFUNC flag is set, the following functions
@@ -110,9 +113,9 @@ struct stat64;
# endif
typedef struct
{
- __size_t gl_pathc;
+ __gsize_t gl_pathc;
char **gl_pathv;
- __size_t gl_offs;
+ __gsize_t gl_offs;
int gl_flags;
/* If the GLOB_ALTDIRFUNC flag is set, the following functions
diff --git a/resolv/resolv.h b/resolv/resolv.h
index 7a8023a..b4ef66f 100644
--- a/resolv/resolv.h
+++ b/resolv/resolv.h
@@ -52,7 +52,8 @@
#ifndef _RESOLV_H_
#define _RESOLV_H_
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <sys/param.h>
#include <sys/types.h>
#include <stdio.h>
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index a6ee700..5c1bb50 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -527,11 +527,9 @@ HEADER_ALLOWED_INCLUDES = {
# spawn.h -> sched.h
"aio.h": [ "sys/types.h" ],
"ftw.h": [ "sys/stat.h", "sys/types.h" ],
- "glob.h": [ "sys/cdefs.h" ],
"langinfo.h": [ "nl_types.h" ],
"mqueue.h": [ "fcntl.h", "sys/types.h" ],
- "pthread.h": [ "endian.h", "sched.h", "time.h",
- "sys/cdefs.h" ],
+ "pthread.h": [ "sched.h", "time.h" ],
"regex.h": [ "limits.h", "sys/types.h" ],
"sched.h": [ "time.h" ],
"semaphore.h": [ "sys/types.h" ],
@@ -550,7 +548,7 @@ HEADER_ALLOWED_INCLUDES = {
"sys/time.h": [ "sys/select.h" ],
"sys/types.h": [ "endian.h", "sys/select.h" ],
"sys/uio.h": [ "sys/types.h" ],
- "sys/un.h": [ "string.h", "sys/cdefs.h" ],
+ "sys/un.h": [ "string.h" ],
"sys/wait.h": [ "signal.h" ],
# POSIX networking headers
@@ -565,7 +563,6 @@ HEADER_ALLOWED_INCLUDES = {
# Nonstandardized top-level headers
"aliases.h": [ "sys/types.h" ],
- "ar.h": [ "sys/cdefs.h" ],
"argp.h": [ "ctype.h", "errno.h", "getopt.h",
"limits.h", "stdio.h" ],
"argz.h": [ "errno.h", "string.h" ],
@@ -602,7 +599,7 @@ HEADER_ALLOWED_INCLUDES = {
# Nonstandardized sys/ headers
"sys/acct.h": [ "endian.h", "stdint.h", "sys/types.h" ],
- "sys/auxv.h": [ "elf.h", "sys/cdefs.h" ],
+ "sys/auxv.h": [ "elf.h" ],
"sys/bitypes.h": [ "sys/types.h" ],
"sys/dir.h": [ "dirent.h" ],
"sys/elf.h": [ "sys/procfs.h" ],
@@ -651,16 +648,16 @@ HEADER_ALLOWED_INCLUDES = {
# Nonstandardized networking headers
"ifaddrs.h": [ "sys/socket.h" ],
"resolv.h": [ "arpa/nameser.h", "netinet/in.h",
- "stdio.h", "sys/cdefs.h", "sys/param.h",\
+ "stdio.h", "sys/param.h",
"sys/types.h" ],
"arpa/nameser.h": [ "arpa/nameser_compat.h", "stdint.h",
"sys/param.h", "sys/types.h" ],
"arpa/nameser_compat.h": [ "endian.h" ],
- "net/ethernet.h": [ "stdint.h", "sys/types.h", "sys/cdefs.h",
+ "net/ethernet.h": [ "stdint.h", "sys/types.h",
"net/if_ether.h" ],
"net/if_arp.h": [ "stdint.h", "sys/socket.h",
- "sys/types.h", "sys/cdefs.h" ],
+ "sys/types.h" ],
"net/if_ppp.h": [ "net/if.h", "net/ppp_defs.h", "stdint.h",
"sys/ioctl.h", "sys/types.h" ],
"net/if_shaper.h": [ "net/if.h", "stdint.h", "sys/ioctl.h",
@@ -675,8 +672,7 @@ HEADER_ALLOWED_INCLUDES = {
"sys/types.h", "stdint.h" ],
"netinet/if_fddi.h": [ "stdint.h", "sys/types.h" ],
"netinet/if_tr.h": [ "stdint.h", "sys/types.h" ],
- "netinet/igmp.h": [ "netinet/in.h", "sys/cdefs.h",
- "sys/types.h" ],
+ "netinet/igmp.h": [ "netinet/in.h", "sys/types.h" ],
"netinet/in_systm.h": [ "stdint.h", "sys/types.h" ],
"netinet/ip.h": [ "netinet/in.h", "sys/types.h" ],
"netinet/ip6.h": [ "inttypes.h", "netinet/in.h" ],
diff --git a/socket/sys/un.h b/socket/sys/un.h
index 1268360..8c7433a 100644
--- a/socket/sys/un.h
+++ b/socket/sys/un.h
@@ -18,7 +18,7 @@
#ifndef _SYS_UN_H
#define _SYS_UN_H 1
-#include <sys/cdefs.h>
+#include <features.h>
/* Get the definition of the macro to define the common sockaddr members. */
#include <bits/sockaddr.h>
diff --git a/sunrpc/rpc/auth_des.h b/sunrpc/rpc/auth_des.h
index 245675f..e60e795 100644
--- a/sunrpc/rpc/auth_des.h
+++ b/sunrpc/rpc/auth_des.h
@@ -18,7 +18,8 @@
#ifndef _RPC_AUTH_DES_H
#define _RPC_AUTH_DES_H 1
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <rpc/auth.h>
__BEGIN_DECLS
diff --git a/sunrpc/rpc/rpc_msg.h b/sunrpc/rpc/rpc_msg.h
index a2cc516..efd9ee4 100644
--- a/sunrpc/rpc/rpc_msg.h
+++ b/sunrpc/rpc/rpc_msg.h
@@ -35,7 +35,7 @@
#ifndef _RPC_MSG_H
#define _RPC_MSG_H 1
-#include <sys/cdefs.h>
+#include <features.h>
#include <rpc/xdr.h>
#include <rpc/clnt.h>
diff --git a/sysdeps/generic/memcopy.h b/sysdeps/generic/memcopy.h
index e10d01e..de32e56 100644
--- a/sysdeps/generic/memcopy.h
+++ b/sysdeps/generic/memcopy.h
@@ -20,6 +20,8 @@
#ifndef _MEMCOPY_H
#define _MEMCOPY_H 1
+#include <features.h>
+
/* The strategy of the memory functions is:
1. Copy bytes until the destination pointer is aligned.
@@ -38,7 +40,6 @@
exhaustive in the sense that I tried all alignment and length
combinations, with and without overlap. */
-#include <sys/cdefs.h>
#include <endian.h>
#include <pagecopy.h>
diff --git a/sysdeps/generic/netinet/tcp.h b/sysdeps/generic/netinet/tcp.h
index 49f1bfb..3b59e94 100644
--- a/sysdeps/generic/netinet/tcp.h
+++ b/sysdeps/generic/netinet/tcp.h
@@ -30,10 +30,9 @@
*/
#ifndef _NETINET_TCP_H
-
#define _NETINET_TCP_H 1
-#include <sys/cdefs.h>
+#include <features.h>
__BEGIN_DECLS
diff --git a/sysdeps/htl/pthread.h b/sysdeps/htl/pthread.h
index a820551..158a095 100644
--- a/sysdeps/htl/pthread.h
+++ b/sysdeps/htl/pthread.h
@@ -25,7 +25,6 @@
#include <features.h>
-#include <sys/cdefs.h>
#ifndef __extern_inline
/* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
inline semantics, unless -fgnu89-inline is used. */
diff --git a/sysdeps/mach/hurd/net/ethernet.h b/sysdeps/mach/hurd/net/ethernet.h
index 4aa67ea..8956694 100644
--- a/sysdeps/mach/hurd/net/ethernet.h
+++ b/sysdeps/mach/hurd/net/ethernet.h
@@ -21,7 +21,8 @@
#ifndef __NET_ETHERNET_H
#define __NET_ETHERNET_H 1
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <sys/types.h>
#include <stdint.h>
#include <net/if_ether.h> /* IEEE 802.3 Ethernet constants */
diff --git a/sysdeps/mach/hurd/net/if_arp.h b/sysdeps/mach/hurd/net/if_arp.h
index 6ef93c9..9e1b223 100644
--- a/sysdeps/mach/hurd/net/if_arp.h
+++ b/sysdeps/mach/hurd/net/if_arp.h
@@ -20,9 +20,9 @@
/* Based on the 4.4BSD and Linux version of this file. */
#ifndef _NET_IF_ARP_H
-
#define _NET_IF_ARP_H 1
-#include <sys/cdefs.h>
+
+#include <features.h>
#include <sys/types.h>
#include <sys/socket.h>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [glibc/zack/no-nested-includes] Don’t include sys/cdefs.h directly from public headers.
@ 2019-05-16 18:42 Zack Weinberg
0 siblings, 0 replies; 7+ messages in thread
From: Zack Weinberg @ 2019-05-16 18:42 UTC (permalink / raw)
To: glibc-cvs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 13788 bytes --]
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=4fcc0a149e2216d2c50c72184a2b2ea35da1ab1d
commit 4fcc0a149e2216d2c50c72184a2b2ea35da1ab1d
Author: Zack Weinberg <zackw@panix.com>
Date: Sat Mar 16 14:31:08 2019 -0400
Donât include sys/cdefs.h directly from public headers.
The convention throughout glibc is that every public header includes
features.h directly, as its first action, and relies on features.h to
include sys/cdefs.h. In a few places, though, itâs been done the
other way around, usually in headers that were copied from a BSD
source (where the convention is exactly the opposite). This patch
makes all installed headers match the glibc convention.
This patch also corrects a bug in glob.h: it may declare size_t
without notifying stddef.h that it has done this, so e.g.
#define _XOPEN_SOURCE 700
#include <glob.h>
#include <stddef.h>
int dummy;
declares size_t twice, which is invalid prior to C2011. I wasnât able
to persuade gcc 8 to issue an error, even with -std=c89 -Wsystem-headers,
but clang is not so lenient.
* posix/glob.h: Include features.h, not sys/cdefs.h.
When __USE_XOPEN || USE_XOPEN2K8, include stddef.h for size_t;
otherwise, issue an immediate #error if __SIZE_TYPE__ is not
available. Use __gsize_t, not __size_t, as an impl-namespace
alternative name for size_t.
* conform/data/glob.h-data: Adjust to match.
* inet/netinet/igmp.h, mach/lock-intern.h, misc/ar.h
* misc/sys/auxv.h, resolv/resolv.h, socket/sys/un.h
* sunrpc/rpc/auth_des.h, sunrpc/rpc/rpc_msg.h
* sysdeps/generic/memcopy.h, sysdeps/generic/netinet/tcp.h
* sysdeps/htl/pthread.h, sysdeps/mach/hurd/net/ethernet.h
* sysdeps/mach/hurd/net/if_arp.h: Include features.h, not sys/cdefs.h.
* scripts/check-obsolete-constructs.py: Remove most whitelist
entries for sys/cdefs.h.
Diff:
---
conform/data/glob.h-data | 2 +-
inet/netinet/igmp.h | 3 ++-
mach/lock-intern.h | 3 ++-
misc/ar.h | 2 +-
misc/sys/auxv.h | 3 ++-
posix/glob.h | 33 ++++++++++++++++++---------------
resolv/resolv.h | 3 ++-
scripts/check-obsolete-constructs.py | 17 +++++++----------
socket/sys/un.h | 2 +-
sunrpc/rpc/auth_des.h | 3 ++-
sunrpc/rpc/rpc_msg.h | 2 +-
sysdeps/generic/memcopy.h | 3 ++-
sysdeps/generic/netinet/tcp.h | 3 +--
sysdeps/htl/pthread.h | 1 -
sysdeps/mach/hurd/net/ethernet.h | 3 ++-
sysdeps/mach/hurd/net/if_arp.h | 4 ++--
16 files changed, 46 insertions(+), 41 deletions(-)
diff --git a/conform/data/glob.h-data b/conform/data/glob.h-data
index eca8393..6268134 100644
--- a/conform/data/glob.h-data
+++ b/conform/data/glob.h-data
@@ -1,6 +1,6 @@
#if !defined ISO && !defined ISO99 && !defined ISO11
#ifdef POSIX
-# define size_t __size_t
+# define size_t __gsize_t
#endif
type glob_t
diff --git a/inet/netinet/igmp.h b/inet/netinet/igmp.h
index dccdb11..2f5be95 100644
--- a/inet/netinet/igmp.h
+++ b/inet/netinet/igmp.h
@@ -18,7 +18,8 @@
#ifndef _NETINET_IGMP_H
#define _NETINET_IGMP_H 1
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <sys/types.h>
#ifdef __USE_MISC
diff --git a/mach/lock-intern.h b/mach/lock-intern.h
index 1988c89..a409abb 100644
--- a/mach/lock-intern.h
+++ b/mach/lock-intern.h
@@ -18,7 +18,8 @@
#ifndef _LOCK_INTERN_H
#define _LOCK_INTERN_H
-#include <sys/cdefs.h>
+#include <features.h>
+
#if defined __USE_EXTERN_INLINES && defined _LIBC
# include <lowlevellock.h>
#endif
diff --git a/misc/ar.h b/misc/ar.h
index ef2303e..adcfda4 100644
--- a/misc/ar.h
+++ b/misc/ar.h
@@ -19,7 +19,7 @@
#ifndef _AR_H
#define _AR_H 1
-#include <sys/cdefs.h>
+#include <features.h>
/* Archive files start with the ARMAG identifying string. Then follows a
`struct ar_hdr', and as many bytes of member file data as its `ar_size'
diff --git a/misc/sys/auxv.h b/misc/sys/auxv.h
index 68363b3..404da6f 100644
--- a/misc/sys/auxv.h
+++ b/misc/sys/auxv.h
@@ -19,8 +19,9 @@
#ifndef _SYS_AUXV_H
#define _SYS_AUXV_H 1
+#include <features.h>
+
#include <elf.h>
-#include <sys/cdefs.h>
#include <bits/hwcap.h>
__BEGIN_DECLS
diff --git a/posix/glob.h b/posix/glob.h
index 378b80a..e49e6c0 100644
--- a/posix/glob.h
+++ b/posix/glob.h
@@ -18,21 +18,24 @@
#ifndef _GLOB_H
#define _GLOB_H 1
-#include <sys/cdefs.h>
+#include <features.h>
__BEGIN_DECLS
-/* We need `size_t' for the following definitions. */
-#ifndef __size_t
-typedef __SIZE_TYPE__ __size_t;
-# if defined __USE_XOPEN || defined __USE_XOPEN2K8
-typedef __SIZE_TYPE__ size_t;
-# endif
+/* Structures below have size_t fields, but this header is not supposed to
+ define size_t itself, unless XSI or POSIX.1-2008 features are active.
+ We can't use __size_t as an alternative name, as we do for most types
+ with this kind of constraint, because GCC's stddef.h uses __size_t for
+ a different purpose. */
+
+#if defined __USE_XOPEN || defined __USE_XOPEN2K8
+# define __need_size_t
+# include <stddef.h>
+typedef size_t __gsize_t;
+#elif defined __SIZE_TYPE__
+typedef __SIZE_TYPE__ __gsize_t;
#else
-/* The GNU CC stddef.h version defines __size_t as empty. We need a real
- definition. */
-# undef __size_t
-# define __size_t size_t
+# error "Don't know how to define __gsize_t"
#endif
/* Bits set in the FLAGS argument to `glob'. */
@@ -81,9 +84,9 @@ struct stat;
#endif
typedef struct
{
- __size_t gl_pathc; /* Count of paths matched by the pattern. */
+ __gsize_t gl_pathc; /* Count of paths matched by the pattern. */
char **gl_pathv; /* List of matched pathnames. */
- __size_t gl_offs; /* Slots to reserve in `gl_pathv'. */
+ __gsize_t gl_offs; /* Slots to reserve in `gl_pathv'. */
int gl_flags; /* Set to FLAGS, maybe | GLOB_MAGCHAR. */
/* If the GLOB_ALTDIRFUNC flag is set, the following functions
@@ -110,9 +113,9 @@ struct stat64;
# endif
typedef struct
{
- __size_t gl_pathc;
+ __gsize_t gl_pathc;
char **gl_pathv;
- __size_t gl_offs;
+ __gsize_t gl_offs;
int gl_flags;
/* If the GLOB_ALTDIRFUNC flag is set, the following functions
diff --git a/resolv/resolv.h b/resolv/resolv.h
index 7a8023a..b4ef66f 100644
--- a/resolv/resolv.h
+++ b/resolv/resolv.h
@@ -52,7 +52,8 @@
#ifndef _RESOLV_H_
#define _RESOLV_H_
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <sys/param.h>
#include <sys/types.h>
#include <stdio.h>
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index c498f08..a06e986 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -526,11 +526,10 @@ HEADER_ALLOWED_INCLUDES = {
# spawn.h -> sched.h
"aio.h": [ "sys/types.h" ],
"ftw.h": [ "sys/stat.h", "sys/types.h" ],
- "glob.h": [ "sys/cdefs.h" ],
"langinfo.h": [ "nl_types.h" ],
"mqueue.h": [ "fcntl.h", "sys/types.h" ],
"poll.h": [ "sys/poll.h" ],
- "pthread.h": [ "sched.h", "time.h", "sys/cdefs.h" ],
+ "pthread.h": [ "sched.h", "time.h" ],
"regex.h": [ "limits.h", "sys/types.h" ],
"sched.h": [ "time.h" ],
"semaphore.h": [ "sys/types.h" ],
@@ -550,7 +549,7 @@ HEADER_ALLOWED_INCLUDES = {
"sys/time.h": [ "sys/select.h" ],
"sys/types.h": [ "endian.h" ],
"sys/uio.h": [ "sys/types.h" ],
- "sys/un.h": [ "string.h", "sys/cdefs.h" ],
+ "sys/un.h": [ "string.h" ],
"sys/wait.h": [ "signal.h" ],
# POSIX networking headers
@@ -565,7 +564,6 @@ HEADER_ALLOWED_INCLUDES = {
# Nonstandardized top-level headers
"aliases.h": [ "sys/types.h" ],
- "ar.h": [ "sys/cdefs.h" ],
"argp.h": [ "ctype.h", "errno.h", "getopt.h",
"limits.h", "stdio.h" ],
"argz.h": [ "errno.h", "string.h" ],
@@ -601,7 +599,7 @@ HEADER_ALLOWED_INCLUDES = {
# Nonstandardized sys/ headers
"sys/acct.h": [ "stdint.h", "sys/types.h" ],
- "sys/auxv.h": [ "elf.h", "sys/cdefs.h" ],
+ "sys/auxv.h": [ "elf.h" ],
"sys/bitypes.h": [ "sys/types.h" ],
"sys/dir.h": [ "dirent.h" ],
"sys/elf.h": [ "sys/procfs.h" ],
@@ -644,15 +642,15 @@ HEADER_ALLOWED_INCLUDES = {
# Nonstandardized networking headers
"ifaddrs.h": [ "sys/socket.h" ],
"resolv.h": [ "arpa/nameser.h", "netinet/in.h",
- "stdio.h", "sys/cdefs.h", "sys/param.h",\
+ "stdio.h", "sys/param.h",
"sys/types.h" ],
"arpa/nameser.h": [ "arpa/nameser_compat.h", "stdint.h",
"sys/param.h", "sys/types.h" ],
- "net/ethernet.h": [ "stdint.h", "sys/types.h", "sys/cdefs.h",
+ "net/ethernet.h": [ "stdint.h", "sys/types.h",
"net/if_ether.h" ],
"net/if_arp.h": [ "stdint.h", "sys/socket.h",
- "sys/types.h", "sys/cdefs.h" ],
+ "sys/types.h" ],
"net/if_ppp.h": [ "net/if.h", "net/ppp_defs.h", "stdint.h",
"sys/ioctl.h", "sys/types.h" ],
"net/if_shaper.h": [ "net/if.h", "stdint.h", "sys/ioctl.h",
@@ -667,8 +665,7 @@ HEADER_ALLOWED_INCLUDES = {
"sys/types.h", "stdint.h" ],
"netinet/if_fddi.h": [ "stdint.h", "sys/types.h" ],
"netinet/if_tr.h": [ "stdint.h", "sys/types.h" ],
- "netinet/igmp.h": [ "netinet/in.h", "sys/cdefs.h",
- "sys/types.h" ],
+ "netinet/igmp.h": [ "netinet/in.h", "sys/types.h" ],
"netinet/in_systm.h": [ "stdint.h", "sys/types.h" ],
"netinet/ip.h": [ "netinet/in.h", "sys/types.h" ],
"netinet/ip6.h": [ "inttypes.h", "netinet/in.h" ],
diff --git a/socket/sys/un.h b/socket/sys/un.h
index 1268360..8c7433a 100644
--- a/socket/sys/un.h
+++ b/socket/sys/un.h
@@ -18,7 +18,7 @@
#ifndef _SYS_UN_H
#define _SYS_UN_H 1
-#include <sys/cdefs.h>
+#include <features.h>
/* Get the definition of the macro to define the common sockaddr members. */
#include <bits/sockaddr.h>
diff --git a/sunrpc/rpc/auth_des.h b/sunrpc/rpc/auth_des.h
index 245675f..e60e795 100644
--- a/sunrpc/rpc/auth_des.h
+++ b/sunrpc/rpc/auth_des.h
@@ -18,7 +18,8 @@
#ifndef _RPC_AUTH_DES_H
#define _RPC_AUTH_DES_H 1
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <rpc/auth.h>
__BEGIN_DECLS
diff --git a/sunrpc/rpc/rpc_msg.h b/sunrpc/rpc/rpc_msg.h
index a2cc516..efd9ee4 100644
--- a/sunrpc/rpc/rpc_msg.h
+++ b/sunrpc/rpc/rpc_msg.h
@@ -35,7 +35,7 @@
#ifndef _RPC_MSG_H
#define _RPC_MSG_H 1
-#include <sys/cdefs.h>
+#include <features.h>
#include <rpc/xdr.h>
#include <rpc/clnt.h>
diff --git a/sysdeps/generic/memcopy.h b/sysdeps/generic/memcopy.h
index e10d01e..de32e56 100644
--- a/sysdeps/generic/memcopy.h
+++ b/sysdeps/generic/memcopy.h
@@ -20,6 +20,8 @@
#ifndef _MEMCOPY_H
#define _MEMCOPY_H 1
+#include <features.h>
+
/* The strategy of the memory functions is:
1. Copy bytes until the destination pointer is aligned.
@@ -38,7 +40,6 @@
exhaustive in the sense that I tried all alignment and length
combinations, with and without overlap. */
-#include <sys/cdefs.h>
#include <endian.h>
#include <pagecopy.h>
diff --git a/sysdeps/generic/netinet/tcp.h b/sysdeps/generic/netinet/tcp.h
index 49f1bfb..3b59e94 100644
--- a/sysdeps/generic/netinet/tcp.h
+++ b/sysdeps/generic/netinet/tcp.h
@@ -30,10 +30,9 @@
*/
#ifndef _NETINET_TCP_H
-
#define _NETINET_TCP_H 1
-#include <sys/cdefs.h>
+#include <features.h>
__BEGIN_DECLS
diff --git a/sysdeps/htl/pthread.h b/sysdeps/htl/pthread.h
index a820551..158a095 100644
--- a/sysdeps/htl/pthread.h
+++ b/sysdeps/htl/pthread.h
@@ -25,7 +25,6 @@
#include <features.h>
-#include <sys/cdefs.h>
#ifndef __extern_inline
/* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
inline semantics, unless -fgnu89-inline is used. */
diff --git a/sysdeps/mach/hurd/net/ethernet.h b/sysdeps/mach/hurd/net/ethernet.h
index 4aa67ea..8956694 100644
--- a/sysdeps/mach/hurd/net/ethernet.h
+++ b/sysdeps/mach/hurd/net/ethernet.h
@@ -21,7 +21,8 @@
#ifndef __NET_ETHERNET_H
#define __NET_ETHERNET_H 1
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <sys/types.h>
#include <stdint.h>
#include <net/if_ether.h> /* IEEE 802.3 Ethernet constants */
diff --git a/sysdeps/mach/hurd/net/if_arp.h b/sysdeps/mach/hurd/net/if_arp.h
index 6ef93c9..9e1b223 100644
--- a/sysdeps/mach/hurd/net/if_arp.h
+++ b/sysdeps/mach/hurd/net/if_arp.h
@@ -20,9 +20,9 @@
/* Based on the 4.4BSD and Linux version of this file. */
#ifndef _NET_IF_ARP_H
-
#define _NET_IF_ARP_H 1
-#include <sys/cdefs.h>
+
+#include <features.h>
#include <sys/types.h>
#include <sys/socket.h>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [glibc/zack/no-nested-includes] Don’t include sys/cdefs.h directly from public headers.
@ 2019-05-16 18:36 Zack Weinberg
0 siblings, 0 replies; 7+ messages in thread
From: Zack Weinberg @ 2019-05-16 18:36 UTC (permalink / raw)
To: glibc-cvs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 13788 bytes --]
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=7888495259cfb7b9a9334aa4f4c4846d6166340d
commit 7888495259cfb7b9a9334aa4f4c4846d6166340d
Author: Zack Weinberg <zackw@panix.com>
Date: Sat Mar 16 14:31:08 2019 -0400
Donât include sys/cdefs.h directly from public headers.
The convention throughout glibc is that every public header includes
features.h directly, as its first action, and relies on features.h to
include sys/cdefs.h. In a few places, though, itâs been done the
other way around, usually in headers that were copied from a BSD
source (where the convention is exactly the opposite). This patch
makes all installed headers match the glibc convention.
This patch also corrects a bug in glob.h: it may declare size_t
without notifying stddef.h that it has done this, so e.g.
#define _XOPEN_SOURCE 700
#include <glob.h>
#include <stddef.h>
int dummy;
declares size_t twice, which is invalid prior to C2011. I wasnât able
to persuade gcc 8 to issue an error, even with -std=c89 -Wsystem-headers,
but clang is not so lenient.
* posix/glob.h: Include features.h, not sys/cdefs.h.
When __USE_XOPEN || USE_XOPEN2K8, include stddef.h for size_t;
otherwise, issue an immediate #error if __SIZE_TYPE__ is not
available. Use __gsize_t, not __size_t, as an impl-namespace
alternative name for size_t.
* conform/data/glob.h-data: Adjust to match.
* inet/netinet/igmp.h, mach/lock-intern.h, misc/ar.h
* misc/sys/auxv.h, resolv/resolv.h, socket/sys/un.h
* sunrpc/rpc/auth_des.h, sunrpc/rpc/rpc_msg.h
* sysdeps/generic/memcopy.h, sysdeps/generic/netinet/tcp.h
* sysdeps/htl/pthread.h, sysdeps/mach/hurd/net/ethernet.h
* sysdeps/mach/hurd/net/if_arp.h: Include features.h, not sys/cdefs.h.
* scripts/check-obsolete-constructs.py: Remove most whitelist
entries for sys/cdefs.h.
Diff:
---
conform/data/glob.h-data | 2 +-
inet/netinet/igmp.h | 3 ++-
mach/lock-intern.h | 3 ++-
misc/ar.h | 2 +-
misc/sys/auxv.h | 3 ++-
posix/glob.h | 33 ++++++++++++++++++---------------
resolv/resolv.h | 3 ++-
scripts/check-obsolete-constructs.py | 17 +++++++----------
socket/sys/un.h | 2 +-
sunrpc/rpc/auth_des.h | 3 ++-
sunrpc/rpc/rpc_msg.h | 2 +-
sysdeps/generic/memcopy.h | 3 ++-
sysdeps/generic/netinet/tcp.h | 3 +--
sysdeps/htl/pthread.h | 1 -
sysdeps/mach/hurd/net/ethernet.h | 3 ++-
sysdeps/mach/hurd/net/if_arp.h | 4 ++--
16 files changed, 46 insertions(+), 41 deletions(-)
diff --git a/conform/data/glob.h-data b/conform/data/glob.h-data
index eca8393..6268134 100644
--- a/conform/data/glob.h-data
+++ b/conform/data/glob.h-data
@@ -1,6 +1,6 @@
#if !defined ISO && !defined ISO99 && !defined ISO11
#ifdef POSIX
-# define size_t __size_t
+# define size_t __gsize_t
#endif
type glob_t
diff --git a/inet/netinet/igmp.h b/inet/netinet/igmp.h
index dccdb11..2f5be95 100644
--- a/inet/netinet/igmp.h
+++ b/inet/netinet/igmp.h
@@ -18,7 +18,8 @@
#ifndef _NETINET_IGMP_H
#define _NETINET_IGMP_H 1
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <sys/types.h>
#ifdef __USE_MISC
diff --git a/mach/lock-intern.h b/mach/lock-intern.h
index 1988c89..a409abb 100644
--- a/mach/lock-intern.h
+++ b/mach/lock-intern.h
@@ -18,7 +18,8 @@
#ifndef _LOCK_INTERN_H
#define _LOCK_INTERN_H
-#include <sys/cdefs.h>
+#include <features.h>
+
#if defined __USE_EXTERN_INLINES && defined _LIBC
# include <lowlevellock.h>
#endif
diff --git a/misc/ar.h b/misc/ar.h
index ef2303e..adcfda4 100644
--- a/misc/ar.h
+++ b/misc/ar.h
@@ -19,7 +19,7 @@
#ifndef _AR_H
#define _AR_H 1
-#include <sys/cdefs.h>
+#include <features.h>
/* Archive files start with the ARMAG identifying string. Then follows a
`struct ar_hdr', and as many bytes of member file data as its `ar_size'
diff --git a/misc/sys/auxv.h b/misc/sys/auxv.h
index 68363b3..404da6f 100644
--- a/misc/sys/auxv.h
+++ b/misc/sys/auxv.h
@@ -19,8 +19,9 @@
#ifndef _SYS_AUXV_H
#define _SYS_AUXV_H 1
+#include <features.h>
+
#include <elf.h>
-#include <sys/cdefs.h>
#include <bits/hwcap.h>
__BEGIN_DECLS
diff --git a/posix/glob.h b/posix/glob.h
index 378b80a..e49e6c0 100644
--- a/posix/glob.h
+++ b/posix/glob.h
@@ -18,21 +18,24 @@
#ifndef _GLOB_H
#define _GLOB_H 1
-#include <sys/cdefs.h>
+#include <features.h>
__BEGIN_DECLS
-/* We need `size_t' for the following definitions. */
-#ifndef __size_t
-typedef __SIZE_TYPE__ __size_t;
-# if defined __USE_XOPEN || defined __USE_XOPEN2K8
-typedef __SIZE_TYPE__ size_t;
-# endif
+/* Structures below have size_t fields, but this header is not supposed to
+ define size_t itself, unless XSI or POSIX.1-2008 features are active.
+ We can't use __size_t as an alternative name, as we do for most types
+ with this kind of constraint, because GCC's stddef.h uses __size_t for
+ a different purpose. */
+
+#if defined __USE_XOPEN || defined __USE_XOPEN2K8
+# define __need_size_t
+# include <stddef.h>
+typedef size_t __gsize_t;
+#elif defined __SIZE_TYPE__
+typedef __SIZE_TYPE__ __gsize_t;
#else
-/* The GNU CC stddef.h version defines __size_t as empty. We need a real
- definition. */
-# undef __size_t
-# define __size_t size_t
+# error "Don't know how to define __gsize_t"
#endif
/* Bits set in the FLAGS argument to `glob'. */
@@ -81,9 +84,9 @@ struct stat;
#endif
typedef struct
{
- __size_t gl_pathc; /* Count of paths matched by the pattern. */
+ __gsize_t gl_pathc; /* Count of paths matched by the pattern. */
char **gl_pathv; /* List of matched pathnames. */
- __size_t gl_offs; /* Slots to reserve in `gl_pathv'. */
+ __gsize_t gl_offs; /* Slots to reserve in `gl_pathv'. */
int gl_flags; /* Set to FLAGS, maybe | GLOB_MAGCHAR. */
/* If the GLOB_ALTDIRFUNC flag is set, the following functions
@@ -110,9 +113,9 @@ struct stat64;
# endif
typedef struct
{
- __size_t gl_pathc;
+ __gsize_t gl_pathc;
char **gl_pathv;
- __size_t gl_offs;
+ __gsize_t gl_offs;
int gl_flags;
/* If the GLOB_ALTDIRFUNC flag is set, the following functions
diff --git a/resolv/resolv.h b/resolv/resolv.h
index 7a8023a..b4ef66f 100644
--- a/resolv/resolv.h
+++ b/resolv/resolv.h
@@ -52,7 +52,8 @@
#ifndef _RESOLV_H_
#define _RESOLV_H_
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <sys/param.h>
#include <sys/types.h>
#include <stdio.h>
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index c498f08..a06e986 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -526,11 +526,10 @@ HEADER_ALLOWED_INCLUDES = {
# spawn.h -> sched.h
"aio.h": [ "sys/types.h" ],
"ftw.h": [ "sys/stat.h", "sys/types.h" ],
- "glob.h": [ "sys/cdefs.h" ],
"langinfo.h": [ "nl_types.h" ],
"mqueue.h": [ "fcntl.h", "sys/types.h" ],
"poll.h": [ "sys/poll.h" ],
- "pthread.h": [ "sched.h", "time.h", "sys/cdefs.h" ],
+ "pthread.h": [ "sched.h", "time.h" ],
"regex.h": [ "limits.h", "sys/types.h" ],
"sched.h": [ "time.h" ],
"semaphore.h": [ "sys/types.h" ],
@@ -550,7 +549,7 @@ HEADER_ALLOWED_INCLUDES = {
"sys/time.h": [ "sys/select.h" ],
"sys/types.h": [ "endian.h" ],
"sys/uio.h": [ "sys/types.h" ],
- "sys/un.h": [ "string.h", "sys/cdefs.h" ],
+ "sys/un.h": [ "string.h" ],
"sys/wait.h": [ "signal.h" ],
# POSIX networking headers
@@ -565,7 +564,6 @@ HEADER_ALLOWED_INCLUDES = {
# Nonstandardized top-level headers
"aliases.h": [ "sys/types.h" ],
- "ar.h": [ "sys/cdefs.h" ],
"argp.h": [ "ctype.h", "errno.h", "getopt.h",
"limits.h", "stdio.h" ],
"argz.h": [ "errno.h", "string.h" ],
@@ -601,7 +599,7 @@ HEADER_ALLOWED_INCLUDES = {
# Nonstandardized sys/ headers
"sys/acct.h": [ "stdint.h", "sys/types.h" ],
- "sys/auxv.h": [ "elf.h", "sys/cdefs.h" ],
+ "sys/auxv.h": [ "elf.h" ],
"sys/bitypes.h": [ "sys/types.h" ],
"sys/dir.h": [ "dirent.h" ],
"sys/elf.h": [ "sys/procfs.h" ],
@@ -644,15 +642,15 @@ HEADER_ALLOWED_INCLUDES = {
# Nonstandardized networking headers
"ifaddrs.h": [ "sys/socket.h" ],
"resolv.h": [ "arpa/nameser.h", "netinet/in.h",
- "stdio.h", "sys/cdefs.h", "sys/param.h",\
+ "stdio.h", "sys/param.h",
"sys/types.h" ],
"arpa/nameser.h": [ "arpa/nameser_compat.h", "stdint.h",
"sys/param.h", "sys/types.h" ],
- "net/ethernet.h": [ "stdint.h", "sys/types.h", "sys/cdefs.h",
+ "net/ethernet.h": [ "stdint.h", "sys/types.h",
"net/if_ether.h" ],
"net/if_arp.h": [ "stdint.h", "sys/socket.h",
- "sys/types.h", "sys/cdefs.h" ],
+ "sys/types.h" ],
"net/if_ppp.h": [ "net/if.h", "net/ppp_defs.h", "stdint.h",
"sys/ioctl.h", "sys/types.h" ],
"net/if_shaper.h": [ "net/if.h", "stdint.h", "sys/ioctl.h",
@@ -667,8 +665,7 @@ HEADER_ALLOWED_INCLUDES = {
"sys/types.h", "stdint.h" ],
"netinet/if_fddi.h": [ "stdint.h", "sys/types.h" ],
"netinet/if_tr.h": [ "stdint.h", "sys/types.h" ],
- "netinet/igmp.h": [ "netinet/in.h", "sys/cdefs.h",
- "sys/types.h" ],
+ "netinet/igmp.h": [ "netinet/in.h", "sys/types.h" ],
"netinet/in_systm.h": [ "stdint.h", "sys/types.h" ],
"netinet/ip.h": [ "netinet/in.h", "sys/types.h" ],
"netinet/ip6.h": [ "inttypes.h", "netinet/in.h" ],
diff --git a/socket/sys/un.h b/socket/sys/un.h
index 1268360..8c7433a 100644
--- a/socket/sys/un.h
+++ b/socket/sys/un.h
@@ -18,7 +18,7 @@
#ifndef _SYS_UN_H
#define _SYS_UN_H 1
-#include <sys/cdefs.h>
+#include <features.h>
/* Get the definition of the macro to define the common sockaddr members. */
#include <bits/sockaddr.h>
diff --git a/sunrpc/rpc/auth_des.h b/sunrpc/rpc/auth_des.h
index 245675f..e60e795 100644
--- a/sunrpc/rpc/auth_des.h
+++ b/sunrpc/rpc/auth_des.h
@@ -18,7 +18,8 @@
#ifndef _RPC_AUTH_DES_H
#define _RPC_AUTH_DES_H 1
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <rpc/auth.h>
__BEGIN_DECLS
diff --git a/sunrpc/rpc/rpc_msg.h b/sunrpc/rpc/rpc_msg.h
index a2cc516..efd9ee4 100644
--- a/sunrpc/rpc/rpc_msg.h
+++ b/sunrpc/rpc/rpc_msg.h
@@ -35,7 +35,7 @@
#ifndef _RPC_MSG_H
#define _RPC_MSG_H 1
-#include <sys/cdefs.h>
+#include <features.h>
#include <rpc/xdr.h>
#include <rpc/clnt.h>
diff --git a/sysdeps/generic/memcopy.h b/sysdeps/generic/memcopy.h
index e10d01e..de32e56 100644
--- a/sysdeps/generic/memcopy.h
+++ b/sysdeps/generic/memcopy.h
@@ -20,6 +20,8 @@
#ifndef _MEMCOPY_H
#define _MEMCOPY_H 1
+#include <features.h>
+
/* The strategy of the memory functions is:
1. Copy bytes until the destination pointer is aligned.
@@ -38,7 +40,6 @@
exhaustive in the sense that I tried all alignment and length
combinations, with and without overlap. */
-#include <sys/cdefs.h>
#include <endian.h>
#include <pagecopy.h>
diff --git a/sysdeps/generic/netinet/tcp.h b/sysdeps/generic/netinet/tcp.h
index 49f1bfb..3b59e94 100644
--- a/sysdeps/generic/netinet/tcp.h
+++ b/sysdeps/generic/netinet/tcp.h
@@ -30,10 +30,9 @@
*/
#ifndef _NETINET_TCP_H
-
#define _NETINET_TCP_H 1
-#include <sys/cdefs.h>
+#include <features.h>
__BEGIN_DECLS
diff --git a/sysdeps/htl/pthread.h b/sysdeps/htl/pthread.h
index a820551..158a095 100644
--- a/sysdeps/htl/pthread.h
+++ b/sysdeps/htl/pthread.h
@@ -25,7 +25,6 @@
#include <features.h>
-#include <sys/cdefs.h>
#ifndef __extern_inline
/* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
inline semantics, unless -fgnu89-inline is used. */
diff --git a/sysdeps/mach/hurd/net/ethernet.h b/sysdeps/mach/hurd/net/ethernet.h
index 4aa67ea..8956694 100644
--- a/sysdeps/mach/hurd/net/ethernet.h
+++ b/sysdeps/mach/hurd/net/ethernet.h
@@ -21,7 +21,8 @@
#ifndef __NET_ETHERNET_H
#define __NET_ETHERNET_H 1
-#include <sys/cdefs.h>
+#include <features.h>
+
#include <sys/types.h>
#include <stdint.h>
#include <net/if_ether.h> /* IEEE 802.3 Ethernet constants */
diff --git a/sysdeps/mach/hurd/net/if_arp.h b/sysdeps/mach/hurd/net/if_arp.h
index 6ef93c9..9e1b223 100644
--- a/sysdeps/mach/hurd/net/if_arp.h
+++ b/sysdeps/mach/hurd/net/if_arp.h
@@ -20,9 +20,9 @@
/* Based on the 4.4BSD and Linux version of this file. */
#ifndef _NET_IF_ARP_H
-
#define _NET_IF_ARP_H 1
-#include <sys/cdefs.h>
+
+#include <features.h>
#include <sys/types.h>
#include <sys/socket.h>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-01-08 19:19 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-26 16:36 [glibc/zack/no-nested-includes] Don’t include sys/cdefs.h directly from public headers Zack Weinberg
-- strict thread matches above, loose matches on Subject: below --
2020-01-08 19:19 Zack Weinberg
2019-06-26 15:50 Zack Weinberg
2019-06-20 16:06 Zack Weinberg
2019-06-18 15:33 Zack Weinberg
2019-05-16 18:42 Zack Weinberg
2019-05-16 18:36 Zack Weinberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).