fix types for wctype_t and wctrans_t
authorRich Felker <dalias@aerifal.cx>
Tue, 5 Mar 2013 00:22:14 +0000 (19:22 -0500)
committerRich Felker <dalias@aerifal.cx>
Tue, 5 Mar 2013 00:22:14 +0000 (19:22 -0500)
wctype_t was incorrectly "int" rather than "long" on x86_64. not only
is this an ABI incompatibility; it's also a major design flaw if we
ever wanted wctype_t to be implemented as a pointer, which would be
necessary if locales support custom character classes, since int is
too small to store a converted pointer. this commit fixes wctype_t to
be unsigned long on all archs, matching the LSB ABI; this change does
not matter for C code, but for C++ it affects mangling.

the same issue applied to wctrans_t. glibc/LSB defines this type as
const __int32_t *, but since no such definition is visible, I've just
expanded the definition, int, everywhere.

it would be nice if these types (which don't vary by arch) could be in
wctype.h, but the OB XSI requirement in POSIX that wchar.h expose some
types and functions from wctype.h precludes doing so. glibc works
around this with some hideous hacks, but trying to duplicate that
would go against the intent of musl's headers.

arch/arm/bits/alltypes.h.sh
arch/i386/bits/alltypes.h.sh
arch/microblaze/bits/alltypes.h.sh
arch/mips/bits/alltypes.h.sh
arch/powerpc/bits/alltypes.h.sh
arch/x86_64/bits/alltypes.h.sh
src/ctype/wctrans.c

index 274de0d..a531ee0 100755 (executable)
@@ -26,8 +26,8 @@ TYPEDEF __builtin_va_list va_list;
 TYPEDEF unsigned wchar_t;
 #endif
 TYPEDEF int wint_t;
 TYPEDEF unsigned wchar_t;
 #endif
 TYPEDEF int wint_t;
-TYPEDEF long wctrans_t;
-TYPEDEF long wctype_t;
+TYPEDEF const int * wctrans_t;
+TYPEDEF unsigned long wctype_t;
 
 TYPEDEF signed char int8_t;
 TYPEDEF short       int16_t;
 
 TYPEDEF signed char int8_t;
 TYPEDEF short       int16_t;
index 10fcf6a..13def83 100755 (executable)
@@ -34,8 +34,8 @@ TYPEDEF long wchar_t;
 #endif
 #endif
 TYPEDEF long wint_t;
 #endif
 #endif
 TYPEDEF long wint_t;
-TYPEDEF long wctrans_t;
-TYPEDEF long wctype_t;
+TYPEDEF const int * wctrans_t;
+TYPEDEF unsigned long wctype_t;
 
 TYPEDEF signed char int8_t;
 TYPEDEF short       int16_t;
 
 TYPEDEF signed char int8_t;
 TYPEDEF short       int16_t;
index c909bc3..2397c6c 100755 (executable)
@@ -26,8 +26,8 @@ TYPEDEF __builtin_va_list va_list;
 TYPEDEF int wchar_t;
 #endif
 TYPEDEF int wint_t;
 TYPEDEF int wchar_t;
 #endif
 TYPEDEF int wint_t;
-TYPEDEF long wctrans_t;
-TYPEDEF long wctype_t;
+TYPEDEF const int * wctrans_t;
+TYPEDEF unsigned long wctype_t;
 
 TYPEDEF signed char int8_t;
 TYPEDEF short       int16_t;
 
 TYPEDEF signed char int8_t;
 TYPEDEF short       int16_t;
index c909bc3..2397c6c 100755 (executable)
@@ -26,8 +26,8 @@ TYPEDEF __builtin_va_list va_list;
 TYPEDEF int wchar_t;
 #endif
 TYPEDEF int wint_t;
 TYPEDEF int wchar_t;
 #endif
 TYPEDEF int wint_t;
-TYPEDEF long wctrans_t;
-TYPEDEF long wctype_t;
+TYPEDEF const int * wctrans_t;
+TYPEDEF unsigned long wctype_t;
 
 TYPEDEF signed char int8_t;
 TYPEDEF short       int16_t;
 
 TYPEDEF signed char int8_t;
 TYPEDEF short       int16_t;
index befad08..f3dac12 100755 (executable)
@@ -26,8 +26,8 @@ TYPEDEF __builtin_va_list va_list;
 TYPEDEF long wchar_t;
 #endif
 TYPEDEF int wint_t;
 TYPEDEF long wchar_t;
 #endif
 TYPEDEF int wint_t;
-TYPEDEF long wctrans_t;
-TYPEDEF long wctype_t;
+TYPEDEF const int * wctrans_t;
+TYPEDEF unsigned long wctype_t;
 
 TYPEDEF signed char int8_t;
 TYPEDEF short       int16_t;
 
 TYPEDEF signed char int8_t;
 TYPEDEF short       int16_t;
index 083ea23..bc9a3cc 100755 (executable)
@@ -25,8 +25,8 @@ TYPEDEF __builtin_va_list va_list;
 TYPEDEF int wchar_t;
 #endif
 TYPEDEF int wint_t;
 TYPEDEF int wchar_t;
 #endif
 TYPEDEF int wint_t;
-TYPEDEF int wctrans_t;
-TYPEDEF int wctype_t;
+TYPEDEF const int * wctrans_t;
+TYPEDEF unsigned long wctype_t;
 
 TYPEDEF signed char int8_t;
 TYPEDEF short       int16_t;
 
 TYPEDEF signed char int8_t;
 TYPEDEF short       int16_t;
index 03e9fd6..739869d 100644 (file)
@@ -3,14 +3,14 @@
 
 wctrans_t wctrans(const char *class)
 {
 
 wctrans_t wctrans(const char *class)
 {
-       if (!strcmp(class, "toupper")) return 1;
-       if (!strcmp(class, "tolower")) return 2;
+       if (!strcmp(class, "toupper")) return (wctrans_t)1;
+       if (!strcmp(class, "tolower")) return (wctrans_t)2;
        return 0;
 }
 
 wint_t towctrans(wint_t wc, wctrans_t trans)
 {
        return 0;
 }
 
 wint_t towctrans(wint_t wc, wctrans_t trans)
 {
-       if (trans == 1) return towupper(wc);
-       if (trans == 2) return towlower(wc);
+       if (trans == (wctrans_t)1) return towupper(wc);
+       if (trans == (wctrans_t)2) return towlower(wc);
        return wc;
 }
        return wc;
 }