This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
[PATCH] Update newlib so that it passes libc++'s tests
- From: JF Bastien <jfb at chromium dot org>
- To: newlib at sourceware dot org
- Date: Mon, 16 Dec 2013 16:54:05 -0800
- Subject: [PATCH] Update newlib so that it passes libc++'s tests
- Authentication-results: sourceware.org; auth=none
Fix issues that LLVM's libc++ test suite finds when setting newlib as
the C library:
- limits.h: define LLONG_MIN, LLONG_MAX and ULLONG_MAX for C++11 too.
- stdint.h: define WCHAR_MIN and WCHAR_MAX according to
__WCHAR_UNSIGNED__ if it is provided, and correct the limit when
unsigned (to 32 all-1 bits, not 31). Make sure stdint.h and wchar.h
are in sync.
- stdint.h: similarly for WINT_MIN and WINT_MAX according to
__WINT_UNSIGNED__.
- stdlib.h: define struct lldiv_t, _Exit, atoll, llabs and lldiv for
C99 and C++11.
- stdlib.h: move wcstold to wchar.h.
- wchar.h: define WCHAR_MIN and WCHAR_MAX according to
__WCHAR_UNSIGNED__ if it is provided, and correct the limit when
unsigned (to 32 all-1 bits, not 31). Make sure stdint.h and wchar.h
are in sync.
- wchar.h: define file as in stdio.h.
- stdlib.h: move wcstold from stdlib.h.
Note that libc++ also needs changes to adapt to newlib's C flavor, I'm
sending a separate patch to the cfe-commits@cs.uiuc.edu mailing list.
Index: newlib/libc/include/limits.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/limits.h,v
retrieving revision 1.3
diff -u -r1.3 limits.h
--- newlib/libc/include/limits.h 31 Oct 2008 21:03:41 -0000 1.3
+++ newlib/libc/include/limits.h 17 Dec 2013 00:40:00 -0000
@@ -96,7 +96,8 @@
# define __LONG_LONG_MAX__ 9223372036854775807LL
# endif
-# if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+# if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
+ (defined(__cplusplus) && __cplusplus >= 201103L)
/* Minimum and maximum values a `signed long long int' can hold. */
# undef LLONG_MIN
# define LLONG_MIN (-LLONG_MAX-1)
@@ -143,4 +144,3 @@
#ifndef PATH_MAX
#define PATH_MAX 4096
#endif
-
Index: newlib/libc/include/stdint.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/stdint.h,v
retrieving revision 1.17
diff -u -r1.17 stdint.h
--- newlib/libc/include/stdint.h 3 Dec 2013 16:04:41 -0000 1.17
+++ newlib/libc/include/stdint.h 17 Dec 2013 00:40:00 -0000
@@ -423,23 +423,42 @@
#endif
#define PTRDIFF_MIN (-PTRDIFF_MAX - 1)
+#ifndef WCHAR_MIN
+#ifdef __WCHAR_MIN__
+#define WCHAR_MIN __WCHAR_MIN__
+#elif defined(__WCHAR_UNSIGNED__)
+#define WCHAR_MIN 0
+#else
+#define WCHAR_MIN (-0x7fffffff - 1)
+#endif
+#endif
+
+#ifndef WCHAR_MAX
#ifdef __WCHAR_MAX__
#define WCHAR_MAX __WCHAR_MAX__
+#elif defined(__WCHAR_UNSIGNED__)
+#define WCHAR_MAX 0xffffffffu
+#else
+#define WCHAR_MAX 0x7fffffffu
#endif
-#ifdef __WCHAR_MIN__
-#define WCHAR_MIN __WCHAR_MIN__
#endif
/* wint_t is unsigned int on almost all GCC targets. */
#ifdef __WINT_MAX__
#define WINT_MAX __WINT_MAX__
#else
+#elif defined(__WINT_UNSIGNED__)
#define WINT_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U)
+#else
+#define WINT_MAX __STDINT_EXP(INT_MAX)
#endif
#ifdef __WINT_MIN__
#define WINT_MIN __WINT_MIN__
#else
+#elif defined(__WINT_UNSIGNED__)
#define WINT_MIN 0U
+#else
+#define WINT_MIN (-WINT_MAX - 1)
#endif
/** Macros for minimum-width integer constant expressions */
Index: newlib/libc/include/stdlib.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/stdlib.h,v
retrieving revision 1.48
diff -u -r1.48 stdlib.h
--- newlib/libc/include/stdlib.h 20 Nov 2013 09:46:39 -0000 1.48
+++ newlib/libc/include/stdlib.h 17 Dec 2013 00:40:00 -0000
@@ -39,7 +39,9 @@
long rem; /* remainder */
} ldiv_t;
-#ifndef __STRICT_ANSI__
+#if !defined(__STRICT_ANSI__) || \
+ (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
+ (defined(__cplusplus) && __cplusplus >= 201103L)
typedef struct
{
long long int quot; /* quotient */
@@ -149,7 +151,13 @@
char * _EXFUN(l64a,(long __input));
char * _EXFUN(_l64a_r,(struct _reent *,long __input));
int _EXFUN(on_exit,(_VOID (*__func)(int, _PTR),_PTR __arg));
-_VOID _EXFUN(_Exit,(int __status) _ATTRIBUTE ((noreturn)));
+#endif /* ! __STRICT_ANSI__ */
+#if !defined(__STRICT_ANSI__) || \
+ (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
+ (defined(__cplusplus) && __cplusplus >= 201103L)
+_VOID _EXFUN(_Exit,(int __status) _ATTRIBUTE ((noreturn)));
+#endif
+#ifndef __STRICT_ANSI__
int _EXFUN(putenv,(char *__string));
int _EXFUN(_putenv_r,(struct _reent *, char *__string));
_PTR _EXFUN(_reallocf_r,(struct _reent *, _PTR, size_t));
@@ -187,12 +195,18 @@
_EXFUN(_seed48_r,(struct _reent *, unsigned short [3]));
_VOID _EXFUN(srand48,(long));
_VOID _EXFUN(_srand48_r,(struct _reent *, long));
+#endif /* ! __STRICT_ANSI__ */
+#if !defined(__STRICT_ANSI__) || \
+ (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
+ (defined(__cplusplus) && __cplusplus >= 201103L)
long long _EXFUN(atoll,(const char *__nptr));
+#endif
+#ifndef __STRICT_ANSI__
long long _EXFUN(_atoll_r,(struct _reent *, const char *__nptr));
-long long _EXFUN(llabs,(long long));
-lldiv_t _EXFUN(lldiv,(long long __numer, long long __denom));
#endif /* ! __STRICT_ANSI__ */
#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L) || (__cplusplus >= 201103L)
+long long _EXFUN(llabs,(long long));
+lldiv_t _EXFUN(lldiv,(long long __numer, long long __denom));
long long _EXFUN(strtoll,(const char *__restrict __n, char **__restrict __end_PTR, int __base));
#endif
#ifndef __STRICT_ANSI__
@@ -233,7 +247,6 @@
#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L) || (__cplusplus >= 201103L)
extern long double strtold (const char *__restrict, char **__restrict);
#endif
-extern long double wcstold (const wchar_t *, wchar_t **);
#endif /* _LDBL_EQ_DBL */
_END_STD_C
Index: newlib/libc/include/wchar.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/wchar.h,v
retrieving revision 1.33
diff -u -r1.33 wchar.h
--- newlib/libc/include/wchar.h 26 Nov 2013 17:20:59 -0000 1.33
+++ newlib/libc/include/wchar.h 17 Dec 2013 00:40:00 -0000
@@ -25,12 +25,20 @@
#endif
#ifndef WCHAR_MIN
+#ifdef __WCHAR_MIN__
+#define WCHAR_MIN __WCHAR_MIN__
+#elif defined(__WCHAR_UNSIGNED__)
#define WCHAR_MIN 0
+#else
+#define WCHAR_MIN (-0x7fffffff - 1)
+#endif
#endif
#ifndef WCHAR_MAX
#ifdef __WCHAR_MAX__
#define WCHAR_MAX __WCHAR_MAX__
+#elif defined(__WCHAR_UNSIGNED__)
+#define WCHAR_MAX 0xffffffffu
#else
#define WCHAR_MAX 0x7fffffffu
#endif
@@ -38,6 +46,9 @@
_BEGIN_STD_C
+/* As in stdio.h, <sys/reent.h> defines __FILE. */
+typedef __FILE FILE;
+
/* As required by POSIX.1-2008, declare tm as incomplete type.
The actual definition is in time.h. */
struct tm;
@@ -130,6 +141,10 @@
long long _EXFUN(_wcstoll_r, (struct _reent *, const wchar_t *, wchar_t **, int));
unsigned long _EXFUN(_wcstoul_r, (struct _reent *, const wchar_t *, wchar_t **, int));
unsigned long long _EXFUN(_wcstoull_r, (struct _reent *, const wchar_t *, wchar_t **, int));
+/* On platforms where long double equals double. */
+#ifdef _LDBL_EQ_DBL
+long double _EXFUN(wcstold, (const wchar_t *, wchar_t **));
+#endif /* _LDBL_EQ_DBL */
wint_t _EXFUN(fgetwc, (__FILE *));
wchar_t *_EXFUN(fgetws, (wchar_t *__restrict, int, __FILE *__restrict));