This is the mail archive of the mailing list for the newlib 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]

Re: [PATCH] Update newlib so that it passes libc++'s tests

On 12/18/2013 04:53 PM, JF Bastien wrote:

Thanks for pointing this out, I wasn't aware of this latest glibc fix.
Here's an updated definition (for both stdint.h and wchar.h). If it
looks good I'll update the patch, assuming the rest of the ongoing
discussion doesn't change this snippet further. To summarize other
discussions, the code first relies on the compiler's own defines
(__WCHAR_{MIN,MAX}__) and stdint.h/wchar.h includes (which could
define WCHAR_{MIN,MAX}) to do the right thing. If that fails then
AFAICT we're stuck with making an educated guess as to what the
"right" value is, and in some cases that guess will necessarily be
wrong because we can't use casts. Newlib's current guess (before my
patch) is 32-bits, so I decided to stick to that and I don't think
going with 16-bits is any better (it's also wrong in some cases, but
now it's also different from what previous newlib versions used to

I'm of course open to suggestions here, but I'm not seeing a better
solution and hope someone else sees one.
There is a better way than guessing, but it is ugly: add a configure-time check that determines what the value is and puts it into the generated newlib.h (in a manner analogous to how _LDBL_EQ_DBL is, for example).

#ifndef WCHAR_MIN
#ifdef __WCHAR_MIN__
#elif defined(__WCHAR_UNSIGNED__) || (L'\0' - 1 > 0)
#define WCHAR_MIN (0 + L'\0')
#define WCHAR_MIN (-0x7fffffff - 1 + L'\0')

#ifndef WCHAR_MAX
#ifdef __WCHAR_MAX__
#elif defined(__WCHAR_UNSIGNED__) || (L'\0' - 1 > 0)
#define WCHAR_MAX (0xffffffffu + L'\0')
#define WCHAR_MAX (0x7fffffffu + L'\0')
The present wchar.h is broken in this manner already for WCHAR_MAX, so it might not be unreasonable to do this for wchar.h now and follow up with a fix for the existing MAX issue. It probably is not good, however, to add the breakage to stdint.h.

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