C++ header compatibility patches, revised
Benjamin Kosnik
bkoz@redhat.com
Sat Jun 22 00:41:00 GMT 2002
This is the revised patch for newlib and libstdc++-v3's "c" header
model. The libstdc++ bits are already checked in.
Switching between current behavior and stricter behavior for C++ gives
equivalent testsuite results.
Jeff if you could check this in I'd appreciate it.
thanks,
benjamin
tested x86/linux -x xscale-elf, defaults
tested x86/linux -x- powerpc-eabisim, c headers + "-D_HAVE_STD_CXX"
2002-06-21 Benjamin Kosnik <bkoz@redhat.com>
* libc/include/stdio.h: Untangle, add _BEGIN_STD_C and _END_STD_C.
* libc/include/time.h: Same.
* libc/include/string.h: Same.
* libc/include/stdlib.h: Same.
* libc/include/signal.h: Same.
* libc/include/setjmp.h: Same.
* libc/include/math.h: Same.
* libc/include/locale.h: Same.
* libc/include/ctype.h: Same.
* libc/include/_ansi.h (_BEGIN_STD_C): Add.
(_END_STD_C): Add.
(_HAVE_STD_CXX): Add.
Index: libc/include/_ansi.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/_ansi.h,v
retrieving revision 1.2
diff -c -p -r1.2 _ansi.h
*** libc/include/_ansi.h 6 Sep 2000 20:46:27 -0000 1.2
--- libc/include/_ansi.h 22 Jun 2002 06:59:24 -0000
***************
*** 74,77 ****
--- 74,95 ----
#define _ATTRIBUTE(attrs)
#endif
+ /* ISO C++. */
+
+ #ifdef __cplusplus
+ #if !(defined(_BEGIN_STD_C) && defined(_END_STD_C))
+ #ifdef _HAVE_STD_CXX
+ #define _BEGIN_STD_C namespace std { extern "C" {
+ #define _END_STD_C } }
+ #else
+ #define _BEGIN_STD_C extern "C" {
+ #define _END_STD_C }
+ #endif
+ #endif
+ #else
+ #define _BEGIN_STD_C
+ #define _END_STD_C
+ #endif
+
#endif /* _ANSIDECL_H_ */
Index: libc/include/ctype.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/ctype.h,v
retrieving revision 1.6
diff -c -p -r1.6 ctype.h
*** libc/include/ctype.h 18 Jun 2002 18:49:14 -0000 1.6
--- libc/include/ctype.h 22 Jun 2002 06:59:25 -0000
***************
*** 1,11 ****
#ifndef _CTYPE_H_
- #ifdef __cplusplus
- extern "C" {
- #endif
#define _CTYPE_H_
#include "_ansi.h"
int _EXFUN(isalnum, (int __c));
int _EXFUN(isalpha, (int __c));
int _EXFUN(iscntrl, (int __c));
--- 1,10 ----
#ifndef _CTYPE_H_
#define _CTYPE_H_
#include "_ansi.h"
+ _BEGIN_STD_C
+
int _EXFUN(isalnum, (int __c));
int _EXFUN(isalpha, (int __c));
int _EXFUN(iscntrl, (int __c));
*************** extern __IMPORT _CONST char _ctype_[];
*** 66,72 ****
#define toascii(c) ((c)&0177)
#endif
! #ifdef __cplusplus
! }
! #endif
#endif /* _CTYPE_H_ */
--- 65,70 ----
#define toascii(c) ((c)&0177)
#endif
! _END_STD_C
!
#endif /* _CTYPE_H_ */
Index: libc/include/locale.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/locale.h,v
retrieving revision 1.2
diff -c -p -r1.2 locale.h
*** libc/include/locale.h 5 Feb 2001 21:51:43 -0000 1.2
--- libc/include/locale.h 22 Jun 2002 06:59:25 -0000
***************
*** 5,13 ****
*/
#ifndef _LOCALE_H_
- #ifdef __cplusplus
- extern "C" {
- #endif
#define _LOCALE_H_
#include "_ansi.h"
--- 5,10 ----
*************** extern "C" {
*** 24,29 ****
--- 21,28 ----
#define LC_TIME 5
#define LC_MESSAGES 6
+ _BEGIN_STD_C
+
struct lconv
{
char *decimal_point;
*************** struct _reent;
*** 55,61 ****
char *_EXFUN(_setlocale_r,(struct _reent *, int category, const char *locale));
struct lconv *_EXFUN(_localeconv_r,(struct _reent *));
! #ifdef __cplusplus
! }
! #endif
#endif /* _LOCALE_H_ */
--- 54,59 ----
char *_EXFUN(_setlocale_r,(struct _reent *, int category, const char *locale));
struct lconv *_EXFUN(_localeconv_r,(struct _reent *));
! _END_STD_C
!
#endif /* _LOCALE_H_ */
Index: libc/include/math.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/math.h,v
retrieving revision 1.11
diff -c -p -r1.11 math.h
*** libc/include/math.h 21 Jun 2002 18:15:43 -0000 1.11
--- libc/include/math.h 22 Jun 2002 06:59:26 -0000
***************
*** 1,9 ****
/* math.h -- Definitions for the math floating point package. */
#ifndef _MATH_H_
- #ifdef __cplusplus
- extern "C" {
- #endif
#define _MATH_H_
#include <sys/reent.h>
--- 1,6 ----
*************** extern "C" {
*** 11,16 ****
--- 8,15 ----
#include <machine/ieeefp.h>
#include "_ansi.h"
+ _BEGIN_STD_C
+
#ifndef HUGE_VAL
/* Define HUGE_VAL as infinity, unless HUGE_VAL is already defined
*************** extern __IMPORT _CONST _LIB_VERSION_TYPE
*** 360,370 ****
#endif /* ! defined (__STRICT_ANSI__) */
#ifdef __FAST_MATH__
#include <machine/fastmath.h>
#endif
- #ifdef __cplusplus
- }
- #endif
#endif /* _MATH_H_ */
--- 359,368 ----
#endif /* ! defined (__STRICT_ANSI__) */
+ _END_STD_C
+
#ifdef __FAST_MATH__
#include <machine/fastmath.h>
#endif
#endif /* _MATH_H_ */
Index: libc/include/setjmp.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/setjmp.h,v
retrieving revision 1.1.1.1
diff -c -p -r1.1.1.1 setjmp.h
*** libc/include/setjmp.h 17 Feb 2000 19:39:46 -0000 1.1.1.1
--- libc/include/setjmp.h 22 Jun 2002 06:59:26 -0000
***************
*** 4,22 ****
*/
#ifndef _SETJMP_H_
- #ifdef __cplusplus
- extern "C" {
- #endif
#define _SETJMP_H_
#include "_ansi.h"
#include <machine/setjmp.h>
void _EXFUN(longjmp,(jmp_buf __jmpb, int __retval));
int _EXFUN(setjmp,(jmp_buf __jmpb));
! #ifdef __cplusplus
! }
! #endif
#endif /* _SETJMP_H_ */
--- 4,20 ----
*/
#ifndef _SETJMP_H_
#define _SETJMP_H_
#include "_ansi.h"
#include <machine/setjmp.h>
+ _BEGIN_STD_C
+
void _EXFUN(longjmp,(jmp_buf __jmpb, int __retval));
int _EXFUN(setjmp,(jmp_buf __jmpb));
! _END_STD_C
!
#endif /* _SETJMP_H_ */
Index: libc/include/signal.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/signal.h,v
retrieving revision 1.1.1.1
diff -c -p -r1.1.1.1 signal.h
*** libc/include/signal.h 17 Feb 2000 19:39:46 -0000 1.1.1.1
--- libc/include/signal.h 22 Jun 2002 06:59:26 -0000
***************
*** 1,12 ****
#ifndef _SIGNAL_H_
- #ifdef __cplusplus
- extern "C" {
- #endif
#define _SIGNAL_H_
#include "_ansi.h"
#include <sys/signal.h>
typedef int sig_atomic_t; /* Atomic entity type (ANSI) */
#if defined(__STDC__) || defined(__cplusplus)
--- 1,11 ----
#ifndef _SIGNAL_H_
#define _SIGNAL_H_
#include "_ansi.h"
#include <sys/signal.h>
+ _BEGIN_STD_C
+
typedef int sig_atomic_t; /* Atomic entity type (ANSI) */
#if defined(__STDC__) || defined(__cplusplus)
*************** _sig_func_ptr _EXFUN(signal, (int, _sig_
*** 31,37 ****
int _EXFUN(raise, (int));
#endif
! #ifdef __cplusplus
! }
! #endif
#endif /* _SIGNAL_H_ */
--- 30,35 ----
int _EXFUN(raise, (int));
#endif
! _END_STD_C
!
#endif /* _SIGNAL_H_ */
Index: libc/include/stdio.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/stdio.h,v
retrieving revision 1.13
diff -c -p -r1.13 stdio.h
*** libc/include/stdio.h 21 Jun 2002 18:29:17 -0000 1.13
--- libc/include/stdio.h 22 Jun 2002 06:59:27 -0000
***************
*** 24,32 ****
*/
#ifndef _STDIO_H_
- #ifdef __cplusplus
- extern "C" {
- #endif
#define _STDIO_H_
#include "_ansi.h"
--- 24,29 ----
*************** extern "C" {
*** 48,53 ****
--- 45,52 ----
#include <sys/reent.h>
#include <sys/types.h>
+ _BEGIN_STD_C
+
typedef _fpos_t fpos_t;
typedef struct __sFILE FILE;
*************** static __inline int __sputc(int _c, FILE
*** 385,391 ****
#endif
#endif
! #ifdef __cplusplus
! }
! #endif
#endif /* _STDIO_H_ */
--- 384,389 ----
#endif
#endif
! _END_STD_C
!
#endif /* _STDIO_H_ */
Index: libc/include/stdlib.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/stdlib.h,v
retrieving revision 1.16
diff -c -p -r1.16 stdlib.h
*** libc/include/stdlib.h 13 Jun 2002 23:24:03 -0000 1.16
--- libc/include/stdlib.h 22 Jun 2002 06:59:27 -0000
***************
*** 5,13 ****
*/
#ifndef _STDLIB_H_
- #ifdef __cplusplus
- extern "C" {
- #endif
#define _STDLIB_H_
#include "_ansi.h"
--- 5,10 ----
*************** extern "C" {
*** 22,27 ****
--- 19,26 ----
#include <alloca.h>
#endif
+ _BEGIN_STD_C
+
typedef struct
{
int quot; /* quotient */
*************** int _EXFUN(_system_r,(struct _reent *, c
*** 176,182 ****
_VOID _EXFUN(__eprintf,(const char *, const char *, unsigned int, const char *));
! #ifdef __cplusplus
! }
! #endif
#endif /* _STDLIB_H_ */
--- 175,180 ----
_VOID _EXFUN(__eprintf,(const char *, const char *, unsigned int, const char *));
! _END_STD_C
!
#endif /* _STDLIB_H_ */
Index: libc/include/string.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/string.h,v
retrieving revision 1.12
diff -c -p -r1.12 string.h
*** libc/include/string.h 5 Jun 2002 20:58:54 -0000 1.12
--- libc/include/string.h 22 Jun 2002 06:59:27 -0000
***************
*** 7,16 ****
#ifndef _STRING_H_
#define _STRING_H_
- #ifdef __cplusplus
- extern "C" {
- #endif
-
#include "_ansi.h"
#include <sys/reent.h>
--- 7,12 ----
*************** extern "C" {
*** 21,26 ****
--- 17,24 ----
#define NULL 0
#endif
+ _BEGIN_STD_C
+
_PTR _EXFUN(memchr,(const _PTR, int, size_t));
int _EXFUN(memcmp,(const _PTR, const _PTR, size_t));
_PTR _EXFUN(memcpy,(_PTR, const _PTR, size_t));
*************** char *_EXFUN(strsignal, (int __signo));
*** 94,100 ****
#endif /* ! __STRICT_ANSI__ */
! #ifdef __cplusplus
! }
! #endif
#endif /* _STRING_H_ */
--- 92,97 ----
#endif /* ! __STRICT_ANSI__ */
! _END_STD_C
!
#endif /* _STRING_H_ */
Index: libc/include/time.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/time.h,v
retrieving revision 1.9
diff -c -p -r1.9 time.h
*** libc/include/time.h 21 Jun 2002 18:29:17 -0000 1.9
--- libc/include/time.h 22 Jun 2002 06:59:28 -0000
***************
*** 10,19 ****
#include "_ansi.h"
#include <sys/reent.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
-
#ifndef NULL
#define NULL 0
#endif
--- 10,15 ----
*************** extern "C" {
*** 32,37 ****
--- 28,35 ----
#include <sys/types.h>
+ _BEGIN_STD_C
+
struct tm
{
int tm_sec;
*************** char *_EXFUN(timezone, (void));
*** 115,126 ****
--- 113,128 ----
#endif /* __CYGWIN__ */
#endif /* !__STRICT_ANSI__ */
+ _END_STD_C
+
#include <sys/features.h>
#if defined(_POSIX_TIMERS)
#include <signal.h>
+ _BEGIN_STD_C
+
/* Clocks, P1003.1b-1993, p. 263 */
int _EXFUN(clock_settime, (clockid_t clock_id, const struct timespec *tp));
*************** int _EXFUN(timer_getoverrun, (timer_t ti
*** 148,155 ****
--- 150,160 ----
int _EXFUN(nanosleep, (const struct timespec *rqtp, struct timespec *rmtp));
+ _END_STD_C
+
#endif /* _POSIX_TIMERS */
+
/* CPU-time Clock Attributes, P1003.4b/D8, p. 54 */
/* values for the clock enable attribute */
*************** int _EXFUN(clock_getenable_attr, (clocki
*** 214,221 ****
#endif /* _POSIX_CPUTIME or _POSIX_THREAD_CPUTIME */
- #ifdef __cplusplus
- }
- #endif
#endif /* _TIME_H_ */
--- 219,223 ----
Index: libc/include/machine/setjmp.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/machine/setjmp.h,v
retrieving revision 1.10
diff -c -p -r1.10 setjmp.h
*** libc/include/machine/setjmp.h 18 Jun 2002 21:20:21 -0000 1.10
--- libc/include/machine/setjmp.h 22 Jun 2002 06:59:28 -0000
***************
*** 1,3 ****
--- 1,6 ----
+
+ _BEGIN_STD_C
+
#if defined(__arm__) || defined(__thumb__)
/*
* All callee preserved registers:
*************** typedef _JBTYPE jmp_buf[_JBLEN];
*** 175,180 ****
--- 178,185 ----
#else
typedef int jmp_buf[_JBLEN];
#endif
+
+ _END_STD_C
#if defined(__CYGWIN__) || defined(__rtems__)
#include <signal.h>
Index: libc/include/sys/types.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/sys/types.h,v
retrieving revision 1.14
diff -c -p -r1.14 types.h
*** libc/include/sys/types.h 21 Jun 2002 18:15:53 -0000 1.14
--- libc/include/sys/types.h 22 Jun 2002 06:59:29 -0000
***************
*** 18,23 ****
--- 18,25 ----
#ifndef _SYS_TYPES_H
#define _SYS_TYPES_H
+ #include <_ansi.h>
+
#if defined (_WIN32) || defined (__CYGWIN__)
#define __MS_types__
#endif
*************** typedef unsigned short ushort; /* Syste
*** 62,67 ****
--- 64,71 ----
typedef unsigned int uint; /* System V compatibility */
# endif /*!_POSIX_SOURCE */
+ _BEGIN_STD_C
+
#ifndef __clock_t_defined
typedef _CLOCK_T_ clock_t;
#define __clock_t_defined
*************** typedef _CLOCK_T_ clock_t;
*** 71,80 ****
--- 75,91 ----
typedef _TIME_T_ time_t;
#define __time_t_defined
+ _END_STD_C
+
+
/* Time Value Specification Structures, P1003.1b-1993, p. 261 */
struct timespec {
+ #if _HAVE_STD_CXX
+ std::time_t tv_sec; /* Seconds */
+ #else
time_t tv_sec; /* Seconds */
+ #endif
long tv_nsec; /* Nanoseconds */
};
More information about the Newlib
mailing list