diff options
author | Rich Felker <dalias@aerifal.cx> | 2019-09-08 17:33:48 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2019-09-08 17:33:48 -0400 |
commit | 1f0e9f9cc2e3fa354f94e18b3b362de5f1ec7272 (patch) | |
tree | 8c20ef31affe0b6dcb940c716a9cf76f74450ee0 | |
parent | 8a544ee3a2a75af278145b09531177cab4939b41 (diff) | |
download | musl-1f0e9f9cc2e3fa354f94e18b3b362de5f1ec7272.zip musl-1f0e9f9cc2e3fa354f94e18b3b362de5f1ec7272.tar.gz musl-1f0e9f9cc2e3fa354f94e18b3b362de5f1ec7272.tar.bz2 |
honor __WCHAR_TYPE__ on archs with legacy long definition of wchar_t
historically, a number of 32-bit archs used long rather than int for
wchar_t, for no good reason. GCC still uses the historical types, but
clang replaced them all with int, and it seems PCC uses int too.
mismatching the compiler's type for wchar_t is not an option due to
wide string literals.
note that the mismatch does not affect C++ ABI since wchar_t is its
own builtin type/keyword in C++, distinct from both int and long, not
a typedef.
i386 already worked around this by honoring __WCHAR_TYPE__ if defined
by the compiler, and only using the official legacy ABI type if not.
add the same to the other affected archs.
it might make sense at some point to switch to using int as the
default if __WCHAR_TYPE__ is not defined, if the expectations is that
new compilers will treat int as the correct choice, but it's unlikely
that the case where __WCHAR_TYPE__ is undefined will ever be used
anyway. I actually wanted to move the definition of wchar_t to the
top-level shared alltypes.h.in, using __WCHAR_TYPE__ and falling back
to int if not defined, but that can't be done without assuming all
compilers define __WCHAR_TYPE__ thanks to some pathological archs
where the ABI has wchar_t as an unsigned type.
-rw-r--r-- | arch/m68k/bits/alltypes.h.in | 4 | ||||
-rw-r--r-- | arch/powerpc/bits/alltypes.h.in | 4 | ||||
-rw-r--r-- | arch/sh/bits/alltypes.h.in | 4 | ||||
-rw-r--r-- | arch/x32/bits/alltypes.h.in | 4 |
4 files changed, 16 insertions, 0 deletions
diff --git a/arch/m68k/bits/alltypes.h.in b/arch/m68k/bits/alltypes.h.in index a4a8141..bd37a63 100644 --- a/arch/m68k/bits/alltypes.h.in +++ b/arch/m68k/bits/alltypes.h.in @@ -6,8 +6,12 @@ TYPEDEF __builtin_va_list va_list; TYPEDEF __builtin_va_list __isoc_va_list; #ifndef __cplusplus +#ifdef __WCHAR_TYPE__ +TYPEDEF __WCHAR_TYPE__ wchar_t; +#else TYPEDEF long wchar_t; #endif +#endif #if __mcffpu__ TYPEDEF float float_t; diff --git a/arch/powerpc/bits/alltypes.h.in b/arch/powerpc/bits/alltypes.h.in index 37f27d6..8e687ef 100644 --- a/arch/powerpc/bits/alltypes.h.in +++ b/arch/powerpc/bits/alltypes.h.in @@ -6,8 +6,12 @@ TYPEDEF __builtin_va_list va_list; TYPEDEF __builtin_va_list __isoc_va_list; #ifndef __cplusplus +#ifdef __WCHAR_TYPE__ +TYPEDEF __WCHAR_TYPE__ wchar_t; +#else TYPEDEF long wchar_t; #endif +#endif TYPEDEF float float_t; TYPEDEF double double_t; diff --git a/arch/sh/bits/alltypes.h.in b/arch/sh/bits/alltypes.h.in index 37f27d6..8e687ef 100644 --- a/arch/sh/bits/alltypes.h.in +++ b/arch/sh/bits/alltypes.h.in @@ -6,8 +6,12 @@ TYPEDEF __builtin_va_list va_list; TYPEDEF __builtin_va_list __isoc_va_list; #ifndef __cplusplus +#ifdef __WCHAR_TYPE__ +TYPEDEF __WCHAR_TYPE__ wchar_t; +#else TYPEDEF long wchar_t; #endif +#endif TYPEDEF float float_t; TYPEDEF double double_t; diff --git a/arch/x32/bits/alltypes.h.in b/arch/x32/bits/alltypes.h.in index 1639129..c612eec 100644 --- a/arch/x32/bits/alltypes.h.in +++ b/arch/x32/bits/alltypes.h.in @@ -6,8 +6,12 @@ TYPEDEF __builtin_va_list va_list; TYPEDEF __builtin_va_list __isoc_va_list; #ifndef __cplusplus +#ifdef __WCHAR_TYPE__ +TYPEDEF __WCHAR_TYPE__ wchar_t; +#else TYPEDEF long wchar_t; #endif +#endif #if defined(__FLT_EVAL_METHOD__) && __FLT_EVAL_METHOD__ == 2 TYPEDEF long double float_t; |