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


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

[PATCH] Always suppress libc-internal declarations for C++ code.


C++ is only used for tests, and some of the internal declarations are
not C++-safe.  Rather than playing whack-a-mole with problems, just
turn on _ISOMAC mode for all C++ code.  (It might make sense to do
this for all IS_IN(nonlib) code as well, and it might also make sense to
suppress most of libc-symbols.h in either or both cases, but when I
tried that it looked to have more fallout than I feel like dealing with
today.)

This flushed out some minor problems: test-skeleton.c uses uintptr_t
but wasn't including <stdint.h>, libio.h tested _GNU_SOURCE instead of
__USE_GNU in one place.

Tested on x86_64-linux-gnu and compile-tested on everything else using
Joseph's build-many-glibcs script.  OK?

zw

	* include/libc-symbols.h: Define _ISOMAC when __cplusplus is defined.
	* include/errno.h, include/stdio.h, include/stdlib.h
	* include/time.h, include/unistd.h, include/wchar.h: No need to
	check __cplusplus nor use __BEGIN_DECLS/__END_DECLS.

	* test-skeleton.c: Include <stdint.h> when thread-testing API is
	activated.
	* libio/libio.h: Use __USE_GNU, not _GNU_SOURCE.
---
 include/errno.h        | 2 +-
 include/libc-symbols.h | 9 +++++++++
 include/stdio.h        | 5 -----
 include/stdlib.h       | 4 ----
 include/time.h         | 4 ----
 include/unistd.h       | 3 ---
 include/wchar.h        | 2 --
 libio/libio.h          | 2 +-
 test-skeleton.c        | 1 +
 9 files changed, 12 insertions(+), 20 deletions(-)

diff --git a/include/errno.h b/include/errno.h
index 7df41df..73fc32e 100644
--- a/include/errno.h
+++ b/include/errno.h
@@ -2,7 +2,7 @@
  #include <stdlib/errno.h>
 -#if defined _ERRNO_H && !defined _ISOMAC && !defined __cplusplus
+#if defined _ERRNO_H && !defined _ISOMAC
  # if IS_IN (rtld)
 #  include <dl-sysdep.h>
diff --git a/include/libc-symbols.h b/include/libc-symbols.h
index 1c91f2e..a7d96cc 100644
--- a/include/libc-symbols.h
+++ b/include/libc-symbols.h
@@ -76,6 +76,15 @@
 #define HAVE_ISWCTYPE	1
 #define ENABLE_NLS	1
 +/* As C++ is only used in tests, and the internal-use declarations
+   found in wrapper headers in include/ are not always C++-safe,
+   instruct those headers not to provide any of those declarations
+   when compiling C++.  */
+
+#ifdef __cplusplus
+# define _ISOMAC 1
+#endif
+
 /* The symbols in all the user (non-_) macros are C symbols.  */
  #ifndef __SYMBOL_PREFIX
diff --git a/include/stdio.h b/include/stdio.h
index 30e737e..266c3bb 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -5,7 +5,6 @@
 #  include <libio/stdio.h>
  /* Now define the internal interfaces.  */
-__BEGIN_DECLS
  extern int __fcloseall (void);
 extern int __snprintf (char *__restrict __s, size_t __maxlen,
@@ -30,7 +29,6 @@ extern int __vsscanf (const char *__restrict __s,
 		      _G_va_list __arg)
      __attribute__ ((__format__ (__scanf__, 2, 0)));
 -#  ifndef __cplusplus
 extern int __sprintf_chk (char *, int, size_t, const char *, ...) __THROW;
 extern int __snprintf_chk (char *, size_t, int, size_t, const char *, ...)
      __THROW;
@@ -52,7 +50,6 @@ extern int __obstack_printf_chk (struct obstack *,
int, const char *, ...)
      __THROW;
 extern int __obstack_vprintf_chk (struct obstack *, int, const char *,
 				  _G_va_list) __THROW;
-#  endif
  extern int __isoc99_fscanf (FILE *__restrict __stream,
 			    const char *__restrict __format, ...) __wur;
@@ -202,7 +199,5 @@ gets (char *__str)
 extern FILE * __fmemopen (void *buf, size_t len, const char *mode);
 libc_hidden_proto (__fmemopen)
 -__END_DECLS
 # endif
-
 #endif
diff --git a/include/stdlib.h b/include/stdlib.h
index 352339e..8039876 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -13,8 +13,6 @@
 #if !defined __Need_M_And_C && !defined _ISOMAC
 # include <sys/stat.h>
 -__BEGIN_DECLS
-
 extern __typeof (strtol_l) __strtol_l;
 extern __typeof (strtoul_l) __strtoul_l;
 extern __typeof (strtoll_l) __strtoll_l;
@@ -265,8 +263,6 @@ extern __typeof (unsetenv) unsetenv attribute_hidden;
 extern __typeof (__strtoul_internal) __strtoul_internal attribute_hidden;
 # endif
 -__END_DECLS
-
 #endif
  #undef __Need_M_And_C
diff --git a/include/time.h b/include/time.h
index 684ceb8..8fe1818 100644
--- a/include/time.h
+++ b/include/time.h
@@ -4,8 +4,6 @@
 #ifndef _ISOMAC
 # include <xlocale.h>
 -__BEGIN_DECLS
-
 extern __typeof (strftime_l) __strftime_l;
 libc_hidden_proto (__strftime_l)
 extern __typeof (strptime_l) __strptime_l;
@@ -112,7 +110,5 @@ extern double __difftime (time_t time1, time_t time0);
    actual clock ID.  */
 #define CLOCK_IDFIELD_SIZE	3
 -__END_DECLS
-
 #endif
 #endif
diff --git a/include/unistd.h b/include/unistd.h
index 16d68a1..fbcea1b 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -2,7 +2,6 @@
 # include <posix/unistd.h>
  # ifndef _ISOMAC
-__BEGIN_DECLS
  libc_hidden_proto (_exit, __noreturn__)
 rtld_hidden_proto (_exit, __noreturn__)
@@ -188,7 +187,5 @@ extern int __getlogin_r_loginuid (char *name, size_t
namesize)
 extern __typeof (__access) __access_noerrno attribute_hidden;
 #  endif
 -__END_DECLS
 # endif
-
 #endif
diff --git a/include/wchar.h b/include/wchar.h
index 6272130..e2579a1 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -172,7 +172,6 @@ extern int __vfwprintf (__FILE *__restrict __s,
 			const wchar_t *__restrict __format,
 			__gnuc_va_list __arg)
      /* __attribute__ ((__format__ (__wprintf__, 2, 0))) */;
-#ifndef __cplusplus
 extern int __vfwprintf_chk (FILE *__restrict __s, int __flag,
 			    const wchar_t *__restrict __format,
 			    __gnuc_va_list __arg)
@@ -184,7 +183,6 @@ extern int __vswprintf_chk (wchar_t *__restrict __s,
size_t __n,
      /* __attribute__ ((__format__ (__wprintf__, 5, 0))) */;
 libc_hidden_proto (__vfwprintf_chk)
 libc_hidden_proto (__vswprintf_chk)
-#endif
  extern int __isoc99_fwscanf (__FILE *__restrict __stream,
 			     const wchar_t *__restrict __format, ...);
diff --git a/libio/libio.h b/libio/libio.h
index efd09f1..f4ead83 100644
--- a/libio/libio.h
+++ b/libio/libio.h
@@ -353,7 +353,7 @@ typedef int __io_seek_fn (void *__cookie,
_IO_off64_t *__pos, int __w);
 typedef int __io_close_fn (void *__cookie);
  -#ifdef _GNU_SOURCE
+#ifdef __USE_GNU
 /* User-visible names for the above.  */
 typedef __io_read_fn cookie_read_function_t;
 typedef __io_write_fn cookie_write_function_t;
diff --git a/test-skeleton.c b/test-skeleton.c
index fa457be..c7954ca 100644
--- a/test-skeleton.c
+++ b/test-skeleton.c
@@ -611,6 +611,7 @@ main (int argc, char *argv[])
 /* The following functionality is only available if <pthread.h> was
    included before this file.  */
 #ifdef _PTHREAD_H
+#include <stdint.h>
  /* Call pthread_sigmask with error checking.  */
 static void
-- 
2.10.2


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