diff --git a/multibyte/internal.c b/multibyte/internal.c index ab22806..2652f12 100644 --- a/multibyte/internal.c +++ b/multibyte/internal.c @@ -17,7 +17,7 @@ | x ) #define F(x) ( ( x>=5 ? 0 : \ x==0 ? R(0x90,0xc0) : \ - x==4 ? R(0x80,0xa0) : \ + x==4 ? R(0x80,0x90) : \ R(0x80,0xc0) ) \ | ( R(0x80,0xc0) >> 6 ) \ | ( R(0x80,0xc0) >> 12 ) \ @@ -32,7 +32,3 @@ const uint32_t bittab[] = { E(0x8),E(0x9),E(0xa),E(0xb),E(0xc),E(0xd),E(0xe),E(0xf), F(0x0),F(0x1),F(0x2),F(0x3),F(0x4) }; - -#ifdef BROKEN_VISIBILITY -__asm__(".hidden __fsmu8"); -#endif diff --git a/multibyte/internal.h b/multibyte/internal.h index 1adf722..791bda4 100644 --- a/multibyte/internal.h +++ b/multibyte/internal.h @@ -16,8 +16,12 @@ extern const uint32_t bittab[]; /* ATTR_LIBC_VISIBILITY; */ #define OOB(c,b) (((((b)>>3)-0x10)|(((b)>>3)+((int32_t)(c)>>26))) & ~7) /* Interval [a,b). Either a must be 80 or b must be c0, lower 3 bits clear. */ -#define R(a,b) ((uint32_t)((a==0x80 ? 0x40-b : -a) << 23)) +#define R(a,b) ((uint32_t)(a==0x80 ? 0x40u-b : 0u-a) << 23) #define FAILSTATE R(0x80,0x80) #define SA 0xc2u #define SB 0xf4u + +/* Arbitrary encoding for representing code units instead of characters. */ +#define CODEUNIT(c) (0xdfff & (signed char)(c)) +#define IS_CODEUNIT(c) ((unsigned)(c)-0xdf80 < 0x80) diff --git a/multibyte/mbrlen.c b/multibyte/mbrlen.c index a0a53b0..b26abd2 100644 --- a/multibyte/mbrlen.c +++ b/multibyte/mbrlen.c @@ -13,6 +13,6 @@ size_t mbrlen(const char *__restrict s, size_t n, mbstate_t *__restrict st) { - static unsigned internal; - return mbrtowc(0, s, n, st ? st : (mbstate_t *)&internal); + static mbstate_t internal; + return mbrtowc(0, s, n, st ? st : &internal); } diff --git a/multibyte/mbrtowc.c b/multibyte/mbrtowc.c index 89545a0..bd016bb 100644 --- a/multibyte/mbrtowc.c +++ b/multibyte/mbrtowc.c @@ -17,6 +17,7 @@ size_t mbrtowc(wchar_t *__restrict wc, const char *__restrict src, size_t n, mbs unsigned c; const unsigned char *s = (const void *)src; const unsigned N = n; + wchar_t dummy; if (!st) st = &internal_state; c = st->__opaque1; @@ -24,7 +25,7 @@ size_t mbrtowc(wchar_t *__restrict wc, const char *__restrict src, size_t n, mbs if (!s) { if (c) goto ilseq; return 0; - } else if (!wc) wc = (void *)&wc; + } else if (!wc) wc = &dummy; if (!n) return -2; if (!c) { diff --git a/multibyte/mbsinit.c b/multibyte/mbsinit.c index c0e7e49..bb09c7d 100644 --- a/multibyte/mbsinit.c +++ b/multibyte/mbsinit.c @@ -13,5 +13,5 @@ int mbsinit(const mbstate_t *st) { - return !st || !*(unsigned *)st; + return !st || !st->__opaque1; } diff --git a/multibyte/mbsnrtowcs.c b/multibyte/mbsnrtowcs.c index 9ac1694..ab03f33 100644 --- a/multibyte/mbsnrtowcs.c +++ b/multibyte/mbsnrtowcs.c @@ -52,7 +52,7 @@ size_t mbsnrtowcs(wchar_t *__restrict wcs, const char **__restrict src, size_t n break; } /* have to roll back partial character */ - *(unsigned *)st = 0; + st->__opaque1 = 0; break; } s += l; n -= l; diff --git a/multibyte/mbsrtowcs.c b/multibyte/mbsrtowcs.c index cc4ba45..8e47bf0 100644 --- a/multibyte/mbsrtowcs.c +++ b/multibyte/mbsrtowcs.c @@ -17,9 +17,9 @@ size_t mbsrtowcs(wchar_t *__restrict ws, const char **__restrict src, size_t wn, size_t wn0 = wn; unsigned c = 0; - if (st && (c = *(unsigned *)st)) { + if (st && (c = st->__opaque1) != 0) { if (ws) { - *(unsigned *)st = 0; + st->__opaque1 = 0; goto resume; } else { goto resume0; diff --git a/multibyte/mbtowc.c b/multibyte/mbtowc.c index 85f81ae..f38733e 100644 --- a/multibyte/mbtowc.c +++ b/multibyte/mbtowc.c @@ -15,10 +15,11 @@ int mbtowc(wchar_t *__restrict wc, const char *__restrict src, size_t n) { unsigned c; const unsigned char *s = (const void *)src; + wchar_t dummy; if (!s) return 0; if (!n) goto ilseq; - if (!wc) wc = (void *)&wc; + if (!wc) wc = &dummy; if (*s < 0x80) return !!(*wc = *s); if (*s-SA > SB-SA) goto ilseq;