aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2019-05-28 13:59:08 -0400
committerZack Weinberg <zackw@panix.com>2020-01-08 13:41:32 -0500
commitcb54252075282ed6ed171a5b0d8eb372c2b06522 (patch)
treee30c4cc531ade5622e560e0e0844a9c3aaa31a06 /stdlib
parent7e51209849daa7183794e8b0870a97de4c38e3ac (diff)
downloadglibc-cb54252075282ed6ed171a5b0d8eb372c2b06522.zip
glibc-cb54252075282ed6ed171a5b0d8eb372c2b06522.tar.gz
glibc-cb54252075282ed6ed171a5b0d8eb372c2b06522.tar.bz2
Add bits/types/ wrappers for stddef.h and stdarg.h types.
We rely on the compiler's stddef.h and stdarg.h to define size_t, ptrdiff_t, wchar_t, NULL, and __gnuc_va_list, and to implement a convention that allows us to request the definition of a specific one: for instance #define __need_size_t #include <stddef.h> is expected to define size_t but not any of the other things stddef.h defines. This patch hides that convention behind a set of bits/types/ headers, which allows check-obsolete-constructs.py to verify that none of our headers include these headers unconditionally. (Both of them define at least one item in the user namespace that no other header is supposed to expose.) It will also facilitate coping with compilers that don’t implement the __need convention. (That scenario is not hypothetical, see the next patch.) Only public headers use the new bits headers. Non-public headers and .c files in our codebase, that were formerly defining __need macros, now just include stddef.h and/or stdarg.h without any __need macros. A few files didn’t need to be including stddef.h / stdarg.h at all. Uses of NULL in public headers that aren’t expected to define NULL are changed to a bare 0. bits/NULL.h is only used by headers that are expected to define NULL. malloc.h and printf.h were, in fact, including stddef.h and/or stdarg.h unconditionally; they no longer do that. This broke a few of our test cases, which are fixed by adding appropriate inclusions to the relevant .c files. * stdlib/bits/NULL.h * stdlib/bits/types/__va_list.h * stdlib/bits/types/ptrdiff_t.h * stdlib/bits/types/size_t.h * stdlib/bits/types/va_list.h * stdlib/bits/types/wchar_t.h: New headers defining a single type or macro each. * stdlib/Makefile: Install new headers. * include/bits/NULL.h * include/bits/types/__va_list.h * include/bits/types/ptrdiff_t.h * include/bits/types/size_t.h * include/bits/types/va_list.h * include/bits/types/wchar_t.h: New wrapper headers. * malloc/malloc.h: Don’t include stdio.h or stddef.h. Include bits/NULL.h, bits/types/size_t.h, bits/types/ptrdiff_t.h, and bits/types/FILE.h. * stdio-common/printf.h: Don’t include stddef.h or stdarg.h. Include bits/types/size_t.h, bits/types/wchar_t.h, and bits/types/__va_list.h. Use __gnuc_va_list instead of va_list in prototypes. * libio/bits/types/struct_FILE.h: Include bits/types/size_t.h. * misc/sys/param.h: Include features.h. * sysvipc/sys/msg.h: Include bits/msq.h after all bits/types/ headers. * sysvipc/sys/sem.h: Include bits/sem.h after all bits/types/ headers. * sysvipc/sys/shm.h: Include bits/shm.h after all bits/types/ headers. * hurd/hurd/signal.h: Don’t use NULL. * hurd/hurd/ioctl.h: Don’t include stdarg.h. * hurd/hurd/userlink.h: Don’t include stddef.h. Don’t use NULL. * intl/libintl.h: Don’t include stddef.h. Don’t use NULL. * intl/gettext.c, intl/ngettext.c: Include stddef.h unconditionally. Don’t define any __need macros first. Don’t include stdlib.h. * sysdeps/posix/sigignore.c:, sysdeps/posix/sigset.c: Don’t include errno.h or string.h. * malloc/tst-malloc-thread-fail.c: Include stddef.h. * malloc/tst-malloc_info.c: Include stdio.h. * stdio-common/tst-vfprintf-user-type.c: Include stdarg.h. * string/tst-cmp.c: Include stdio.h. * debug/wcpcpy_chk.c, iconv/loop.c, iconv/skeleton.c * signal/sighold.c, signal/sigrelse.c, stdio-common/tempname.c * sysdeps/generic/ldsodefs.h, sysdeps/nptl/libc-lock.h * sysdeps/nptl/libc-lockP.h, sysdeps/posix/waitid.c * wcsmbs/wcstol_l.c, wcsmbs/wcstoll_l.c, wcsmbs/wcstoul_l.c * wcsmbs/wcstoull_l.c, sysdeps/posix/sigignore.c * sysdeps/posix/sigset.c: Don’t define __need macros before including stddef.h. * bits/socket.h, bits/types/stack_t.h, dirent/dirent.h * dlfcn/dlfcn.h, gmon/sys/profil.h, grp/grp.h, gshadow/gshadow.h * hurd/hurd/signal.h, hurd/hurd/sigpreempt.h, iconv/gconv.h * include/set-hooks.h, include/stdio.h, inet/aliases.h * io/sys/sendfile.h, libio/stdio.h, misc/bits/types/struct_iovec.h * misc/search.h, misc/sys/mman.h, misc/syslog.h, posix/glob.h * posix/sched.h, posix/sys/types.h, posix/unistd.h * posix/wordexp.h, pwd/pwd.h, shadow/shadow.h, signal/signal.h * socket/sys/socket.h, stdlib/alloca.h, stdlib/monetary.h * stdlib/stdlib.h, stdlib/sys/random.h, string/string.h * string/strings.h, sunrpc/rpc/netdb.h * sysdeps/htl/bits/types/struct___pthread_attr.h * sysdeps/mach/hurd/bits/socket.h * sysdeps/unix/sysv/linux/bits/socket.h * sysdeps/unix/sysv/linux/bits/types/stack_t.h * sysdeps/unix/sysv/linux/ia64/bits/sigcontext.h * sysdeps/unix/sysv/linux/mips/bits/types/stack_t.h * sysdeps/unix/sysv/linux/scsi/sg.h * sysdeps/unix/sysv/linux/sys/sysctl.h * sysvipc/sys/msg.h, sysvipc/sys/sem.h, sysvipc/sys/shm.h * time/time.h, wcsmbs/uchar.h, wcsmbs/wchar.h: Use bits/types/size_t.h instead of __need_size_t. * iconv/gconv.h, iconv/iconv.h, libio/libio.h * stdlib/inttypes.h, stdlib/stdlib.h, wcsmbs/wchar.h: Use bits/types/wchar_t.h instead of __need_wchar_t. * libio/stdio.h, locale/locale.h, misc/sys/param.h * posix/sched.h, posix/unistd.h, stdlib/stdlib.h * string/string.h, sysdeps/unix/sysv/linux/bits/sigcontext.h * time/time.h, wcsmbs/wchar.h: Use bits/NULL.h instead of __need_NULL. * libio/stdio.h, misc/err.h: Use bits/types/__va_list.h instead of __need___va_list. * libio/stdio.h: Use bits/types/va_list.h instead of manually defining va_list. * hurd/hurd/userlink.h, misc/sys/mman.h, posix/sched.h * sysdeps/mach/hurd/bits/socket.h * sysdeps/unix/sysv/linux/ia64/bits/sigcontext.h * wcsmbs/wchar.h: Reorganize includes; no semantic effect. * stdlib/stdlib.h: Normalize format of multiple include guard. * sysdeps/unix/sysv/linux/bits/sigcontext.h: Annotate workarounds for kernel header bugs. * sysdeps/unix/sysv/linux/aarch64/sys/user.h * sysdeps/unix/sysv/linux/arm/sys/user.h * sysdeps/unix/sysv/linux/m68k/sys/user.h * sysdeps/unix/sysv/linux/microblaze/sys/user.h * sysdeps/unix/sysv/linux/nios2/sys/user.h * sysdeps/unix/sysv/linux/s390/sys/user.h * sysdeps/unix/sysv/linux/x86/sys/user.h Include features.h. * sysdeps/unix/sysv/linux/alpha/sys/user.h * sysdeps/unix/sysv/linux/ia64/sys/user.h * sysdeps/unix/sysv/linux/mips/sys/user.h * sysdeps/unix/sysv/linux/powerpc/sys/user.h * sysdeps/unix/sysv/linux/sh/sys/user.h * sysdeps/unix/sysv/linux/sparc/sys/user.h Include features.h and bits/types/size_t.h, in that order. Include kernel headers, if any, after those two. Don’t include stddef.h or sys/types.h. * scripts/check-obsolete-constructs.py (UNIVERSAL_ALLOWED_INCLUDES): Remove stddef.h and stdarg.h. (HEADER_ALLOWED_INCLUDES): Update.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/Makefile4
-rw-r--r--stdlib/alloca.h3
-rw-r--r--stdlib/bits/NULL.h8
-rw-r--r--stdlib/bits/types/__va_list.h9
-rw-r--r--stdlib/bits/types/ptrdiff_t.h9
-rw-r--r--stdlib/bits/types/size_t.h9
-rw-r--r--stdlib/bits/types/va_list.h15
-rw-r--r--stdlib/bits/types/wchar_t.h9
-rw-r--r--stdlib/inttypes.h3
-rw-r--r--stdlib/monetary.h3
-rw-r--r--stdlib/stdlib.h11
11 files changed, 69 insertions, 14 deletions
diff --git a/stdlib/Makefile b/stdlib/Makefile
index 45214b5..6f8e6ba 100644
--- a/stdlib/Makefile
+++ b/stdlib/Makefile
@@ -29,7 +29,9 @@ headers := stdlib.h bits/stdlib.h bits/stdlib-ldbl.h bits/stdlib-float.h \
ucontext.h sys/ucontext.h bits/indirect-return.h \
alloca.h fmtmsg.h \
bits/stdlib-bsearch.h sys/random.h bits/stdint-intn.h \
- bits/stdint-uintn.h bits/time64.h \
+ bits/stdint-uintn.h bits/time64.h bits/NULL.h \
+ bits/types/ptrdiff_t.h bits/types/size_t.h bits/types/wchar_t.h \
+ bits/types/__va_list.h bits/types/va_list.h
routines := \
atof atoi atol atoll \
diff --git a/stdlib/alloca.h b/stdlib/alloca.h
index bd44688..a5b0b7a 100644
--- a/stdlib/alloca.h
+++ b/stdlib/alloca.h
@@ -20,8 +20,7 @@
#include <features.h>
-#define __need_size_t
-#include <stddef.h>
+#include <bits/types/size_t.h>
__BEGIN_DECLS
diff --git a/stdlib/bits/NULL.h b/stdlib/bits/NULL.h
new file mode 100644
index 0000000..79285bd
--- /dev/null
+++ b/stdlib/bits/NULL.h
@@ -0,0 +1,8 @@
+#ifndef _BITS_NULL_H
+#define _BITS_NULL_H 1
+
+/* We rely on the compiler's stddef.h to define NULL for us. */
+#define __need_NULL
+#include <stddef.h>
+
+#endif
diff --git a/stdlib/bits/types/__va_list.h b/stdlib/bits/types/__va_list.h
new file mode 100644
index 0000000..e3c53c3
--- /dev/null
+++ b/stdlib/bits/types/__va_list.h
@@ -0,0 +1,9 @@
+#ifndef ____va_list_defined
+#define ____va_list_defined 1
+
+/* We rely on the compiler's stdarg.h to define __gnuc_va_list for us. */
+#define __need___va_list
+#include <stdarg.h>
+#undef __need___va_list
+
+#endif
diff --git a/stdlib/bits/types/ptrdiff_t.h b/stdlib/bits/types/ptrdiff_t.h
new file mode 100644
index 0000000..23a8b98
--- /dev/null
+++ b/stdlib/bits/types/ptrdiff_t.h
@@ -0,0 +1,9 @@
+#ifndef __ptrdiff_t_defined
+#define __ptrdiff_t_defined 1
+
+/* We rely on the compiler's stddef.h to define ptrdiff_t for us. */
+#define __need_ptrdiff_t
+#include <stddef.h>
+#undef __need_ptrdiff_t
+
+#endif
diff --git a/stdlib/bits/types/size_t.h b/stdlib/bits/types/size_t.h
new file mode 100644
index 0000000..e151458
--- /dev/null
+++ b/stdlib/bits/types/size_t.h
@@ -0,0 +1,9 @@
+#ifndef __size_t_defined
+#define __size_t_defined 1
+
+/* We rely on the compiler's stddef.h to define size_t for us. */
+#define __need_size_t
+#include <stddef.h>
+#undef __need_size_t
+
+#endif
diff --git a/stdlib/bits/types/va_list.h b/stdlib/bits/types/va_list.h
new file mode 100644
index 0000000..6f3acac
--- /dev/null
+++ b/stdlib/bits/types/va_list.h
@@ -0,0 +1,15 @@
+/* This guard macro needs to match the one used by at least gcc and
+ clang's stdarg.h to indicate that va_list, specifically, has been
+ defined. */
+#ifndef _VA_LIST
+
+#include <bits/types/__va_list.h>
+
+/* Check again, __va_list.h may not have been able to avoid including
+ all of stdarg.h. */
+# ifndef _VA_LIST
+typedef __gnuc_va_list va_list;
+# endif
+# define _VA_LIST
+
+#endif
diff --git a/stdlib/bits/types/wchar_t.h b/stdlib/bits/types/wchar_t.h
new file mode 100644
index 0000000..1e44e15
--- /dev/null
+++ b/stdlib/bits/types/wchar_t.h
@@ -0,0 +1,9 @@
+#ifndef __wchar_t_defined
+#define __wchar_t_defined 1
+
+/* We rely on the compiler's stddef.h to define wchar_t for us. */
+#define __need_wchar_t
+#include <stddef.h>
+#undef __need_wchar_t
+
+#endif
diff --git a/stdlib/inttypes.h b/stdlib/inttypes.h
index c5ec307..f42cea5 100644
--- a/stdlib/inttypes.h
+++ b/stdlib/inttypes.h
@@ -32,8 +32,7 @@
#elif defined __WCHAR_TYPE__
typedef __WCHAR_TYPE__ __gwchar_t;
#else
-# define __need_wchar_t
-# include <stddef.h>
+#include <bits/types/wchar_t.h>
typedef wchar_t __gwchar_t;
#endif
diff --git a/stdlib/monetary.h b/stdlib/monetary.h
index 8f268a0..80f4ea1 100644
--- a/stdlib/monetary.h
+++ b/stdlib/monetary.h
@@ -22,9 +22,8 @@
#include <features.h>
/* Get needed types. */
-#define __need_size_t
-#include <stddef.h>
#include <bits/types.h>
+#include <bits/types/size_t.h>
#include <bits/types/ssize_t.h>
__BEGIN_DECLS
diff --git a/stdlib/stdlib.h b/stdlib/stdlib.h
index 9f1f1b8..3e3351e 100644
--- a/stdlib/stdlib.h
+++ b/stdlib/stdlib.h
@@ -20,20 +20,17 @@
*/
#ifndef _STDLIB_H
+#define _STDLIB_H 1
#define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
#include <bits/libc-header-start.h>
-/* Get size_t, wchar_t and NULL from <stddef.h>. */
-#define __need_size_t
-#define __need_wchar_t
-#define __need_NULL
-#include <stddef.h>
+#include <bits/types/size_t.h>
+#include <bits/types/wchar_t.h>
+#include <bits/NULL.h>
__BEGIN_DECLS
-#define _STDLIB_H 1
-
#if (defined __USE_XOPEN || defined __USE_XOPEN2K8) && !defined _SYS_WAIT_H
/* XPG requires a few symbols from <sys/wait.h> being defined. */
# include <bits/waitflags.h>