about summary refs log tree commit diff
path: root/wcsmbs/bits
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2019-05-29 14:23:32 -0400
committerZack Weinberg <zackw@panix.com>2020-01-08 13:42:38 -0500
commitee57733099e3d12bc0a822a2d56f4e5b1b2cdae1 (patch)
treefec88df12537c3adb30770b4673b510542e47f94 /wcsmbs/bits
parentcb54252075282ed6ed171a5b0d8eb372c2b06522 (diff)
downloadglibc-ee57733099e3d12bc0a822a2d56f4e5b1b2cdae1.tar.gz
glibc-ee57733099e3d12bc0a822a2d56f4e5b1b2cdae1.tar.xz
glibc-ee57733099e3d12bc0a822a2d56f4e5b1b2cdae1.zip
Don’t rely on stddef.h or stdarg.h for individual type definitions.
In the course of developing earlier patches in this series I
discovered that clang’s stddef.h does not implement the __need_*
convention correctly: in C++, under some circumstances __need_NULL
will also cause a definition of nullptr_t, and when the “modules”
feature is enabled, all of the __need macros are ignored and all of
stddef.h is exposed.  (I’m not sure how to actually make either of
these things happen, I discovered the problem by reading the file.)

Worse, clang’s stdarg.h does not implement __need___va_list *at all*;
including its stdarg.h will always expose all of its definitions.

These are bugs in clang but it seems prudent to work around them, and
the simplest way to do so is to have the bits/types/ headers
introduced in the previous patch make definitions themselves, when
possible.  For size_t, ptrdiff_t, and wchar_t, we can use the
predefined macros __SIZE_TYPE__, __PTRDIFF_TYPE__, and __WCHAR_TYPE__,
when available, falling back to the old approach.  For __gnuc_va_list,
we have a whitelist of compilers known to provide __builtin_va_list,
falling back to the old approach.  NULL and va_list are defined
ab initio.

An additional complication is that we must be able to tell stddef.h
and stdarg.h _not_ to define again things we have already defined.  It
appears to me, based on inspection of clang, GCC, and icc stddef.h and
stdarg.h, that we can use the macros _SIZE_T, _PTRDIFF_T, _WCHAR_T,
_VA_LIST, and __GNUC_VA_LIST to accomplish this.

Since we are no longer relying on stdarg.h to define an
implementation-namespace alias for us, I thought it would make sense
also to stop calling it __gnuc_va_list.  The bulk of this patch is
a mechanical substitution of __va_list for __gnuc_va_list throughout
our headers.

Copyright boilerplate is added to stdlib/bits/NULL.h and stdlib/bits/types/*.h
because they now contain enough commentary and code that they could
plausibly be copyrightable.

	* stdlib/bits/NULL.h: Do not use stddef.h to define NULL.
	Define NULL ab initio if not already defined, as `((void *)0)` for C,
	and either `__null` or 0 for C++, depending on compiler support.

	* stdlib/bits/types/__va_list.h: If __builtin_va_list is known to
	be available, use it to define __va_list without including
	stdarg.h.  Otherwise use __need___va_list to request a definition
	of __gnuc_va_list and nothing else from stdarg.h, then use that to
	define __va_list.
	* stdlib/bits/types/va_list.h: Use __va_list, not __gnuc_va_list,
	to define va_list.  Improve commentary.

	* stdlib/bits/types/ptrdiff_t.h: If __PTRDIFF_TYPE__ is defined,
	use it to define ptrdiff_t without including stddef.h.  Otherwise
	use __need_ptrdiff_t to request a definition of ptrdiff_t and
	nothing else from stddef.h.  Use _PTRDIFF_T as guard macro to
	match behavior of common stddef.h implementations.
	* stdlib/bits/types/size_t.h: Similarly for size_t, with
	__SIZE_TYPE__, __need_size_t, and _SIZE_T.
	* stdlib/bits/types/wchar_t.h: Similarly for wchar_t, with
	__WCHAR_TYPE__, __need_wchar_t, and _WCHAR_T.  If __cplusplus
	is defined, do nothing; wchar_t is built-in in C++.

	* conform/data/stdio.h-data, conform/data/wchar.h-data
	* include/err.h, include/stdio.h, include/syslog.h, include/wchar.h
	* libio/bits/stdio.h, libio/bits/stdio2.h, libio/iolibio.h
	* libio/libio.h, libio/stdio.h, libio/vwprintf.c, misc/bits/syslog.h
	* misc/err.c, misc/err.h, misc/syslog.h, stdio-common/printf.h
	* sysdeps/ieee754/ldbl-opt/nldbl-compat.c
	* sysdeps/ieee754/ldbl-opt/nldbl-compat.h
	* wcsmbs/bits/wchar2.h, wcsmbs/wchar.h:
	Replace all uses of __gnuc_va_list with __va_list.

        * scripts/check-obsolete-constructs.py (HEADER_ALLOWED_INCLUDES):
        bits/NULL.h is no longer allowed to include stddef.h.
Diffstat (limited to 'wcsmbs/bits')
-rw-r--r--wcsmbs/bits/wchar2.h14
1 files changed, 7 insertions, 7 deletions
diff --git a/wcsmbs/bits/wchar2.h b/wcsmbs/bits/wchar2.h
index 86e8e23e76..defd9b2189 100644
--- a/wcsmbs/bits/wchar2.h
+++ b/wcsmbs/bits/wchar2.h
@@ -303,17 +303,17 @@ __NTH (swprintf (wchar_t *__restrict __s, size_t __n,
 extern int __vswprintf_chk (wchar_t *__restrict __s, size_t __n,
 			    int __flag, size_t __s_len,
 			    const wchar_t *__restrict __format,
-			    __gnuc_va_list __arg)
+			    __va_list __arg)
      __THROW /* __attribute__ ((__format__ (__wprintf__, 5, 0))) */;
 
 extern int __REDIRECT_NTH_LDBL (__vswprintf_alias,
 				(wchar_t *__restrict __s, size_t __n,
 				 const wchar_t *__restrict __fmt,
-				 __gnuc_va_list __ap), vswprintf);
+				 __va_list __ap), vswprintf);
 
 __fortify_function int
 __NTH (vswprintf (wchar_t *__restrict __s, size_t __n,
-		  const wchar_t *__restrict __fmt, __gnuc_va_list __ap))
+		  const wchar_t *__restrict __fmt, __va_list __ap))
 {
   if (__bos (__s) != (size_t) -1 || __USE_FORTIFY_LEVEL > 1)
     return __vswprintf_chk (__s, __n,  __USE_FORTIFY_LEVEL - 1,
@@ -330,9 +330,9 @@ extern int __wprintf_chk (int __flag, const wchar_t *__restrict __format,
 			  ...);
 extern int __vfwprintf_chk (__FILE *__restrict __stream, int __flag,
 			    const wchar_t *__restrict __format,
-			    __gnuc_va_list __ap);
+			    __va_list __ap);
 extern int __vwprintf_chk (int __flag, const wchar_t *__restrict __format,
-			   __gnuc_va_list __ap);
+			   __va_list __ap);
 
 # ifdef __va_arg_pack
 __fortify_function int
@@ -355,14 +355,14 @@ fwprintf (__FILE *__restrict __stream, const wchar_t *__restrict __fmt, ...)
 # endif
 
 __fortify_function int
-vwprintf (const wchar_t *__restrict __fmt, __gnuc_va_list __ap)
+vwprintf (const wchar_t *__restrict __fmt, __va_list __ap)
 {
   return __vwprintf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __ap);
 }
 
 __fortify_function int
 vfwprintf (__FILE *__restrict __stream,
-	   const wchar_t *__restrict __fmt, __gnuc_va_list __ap)
+	   const wchar_t *__restrict __fmt, __va_list __ap)
 {
   return __vfwprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt, __ap);
 }