diff options
author | Rich Felker <dalias@aerifal.cx> | 2011-02-27 00:28:59 -0500 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2011-02-27 00:28:59 -0500 |
commit | 015d33c5075b9c0a4df8f28e844e4f7ace91c647 (patch) | |
tree | 6afdfbd8af5c6c7a550f8cf4a070e965b6806897 /src/multibyte | |
parent | 2a195dd31ceb2a483ea547444aac080bee132ad2 (diff) | |
download | musl-015d33c5075b9c0a4df8f28e844e4f7ace91c647.tar.gz musl-015d33c5075b9c0a4df8f28e844e4f7ace91c647.tar.bz2 musl-015d33c5075b9c0a4df8f28e844e4f7ace91c647.tar.xz musl-015d33c5075b9c0a4df8f28e844e4f7ace91c647.zip |
cleanup utf-8 multibyte code, use visibility if possible
this code was written independently of musl, with support for a the
backwards, nonstandard "31-bit unicode" some libraries/apps might
want. unfortunately the extra code (inside #ifdef) makes the source
harder to read and makes code that should be simple look complex, so
i'm removing it. anyone who wants to use the old code can find it in
the history or from elsewhere.
also, change the visibility of the __fsmu8 state machine table to
hidden, if supported. this should improve performance slightly in
shared-library builds.
Diffstat (limited to 'src/multibyte')
-rw-r--r-- | src/multibyte/internal.c | 28 | ||||
-rw-r--r-- | src/multibyte/internal.h | 45 | ||||
-rw-r--r-- | src/multibyte/mbsrtowcs.c | 16 |
3 files changed, 5 insertions, 84 deletions
diff --git a/src/multibyte/internal.c b/src/multibyte/internal.c index e9b938dd..11b9818f 100644 --- a/src/multibyte/internal.c +++ b/src/multibyte/internal.c @@ -15,27 +15,6 @@ R(0x80,0xc0) ) \ | ( R(0x80,0xc0) >> 6 ) \ | x ) -#ifdef I_FAILED_TO_RTFM_RFC3629 -#define F0(x) (( x==0 ? R(0x90,0xc0) : \ - R(0x80,0xc0) ) \ - | ( R(0x80,0xc0) >> 6 ) \ - | ( R(0x80,0xc0) >> 12 ) \ - | x ) -#define F8(x) (( x==0 ? R(0xa0,0xc0) : \ - R(0x80,0xc0) ) \ - | ( R(0x80,0xc0) >> 6 ) \ - | ( R(0x80,0xc0) >> 12 ) \ - | ( R(0x80,0xc0) >> 18 ) \ - | x ) -#define FC(x) (( x==0 ? R(0x88,0xc0) : \ - R(0x80,0xc0) ) \ - | ( R(0x80,0xc0) >> 6 ) \ - | ( R(0x80,0xc0) >> 12 ) \ - | ( R(0x80,0xc0) >> 18 ) \ - | ( R(0x80,0xc0) >> 24 ) \ - | x ) -#define F(x) ( x<8 ? F0(x) : x<12 ? F8((x&3)) : x<14 ? FC((x&1)) : -1 ) -#else #define F(x) ( ( x>=5 ? 0 : \ x==0 ? R(0x90,0xc0) : \ x==4 ? R(0x80,0xa0) : \ @@ -43,7 +22,6 @@ | ( R(0x80,0xc0) >> 6 ) \ | ( R(0x80,0xc0) >> 12 ) \ | x ) -#endif const uint32_t bittab[] = { C(0x2),C(0x3),C(0x4),C(0x5),C(0x6),C(0x7), @@ -52,9 +30,5 @@ const uint32_t bittab[] = { D(0x8),D(0x9),D(0xa),D(0xb),D(0xc),D(0xd),D(0xe),D(0xf), E(0x0),E(0x1),E(0x2),E(0x3),E(0x4),E(0x5),E(0x6),E(0x7), 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 I_FAILED_TO_RTFM_RFC3629 - F(0x5),F(0x6),F(0x7), - F(0x8),F(0x9),F(0xa),F(0xb),F(0xc),F(0xd) -#endif + F(0x0),F(0x1),F(0x2),F(0x3),F(0x4) }; diff --git a/src/multibyte/internal.h b/src/multibyte/internal.h index ec52bdfa..df47331e 100644 --- a/src/multibyte/internal.h +++ b/src/multibyte/internal.h @@ -4,45 +4,13 @@ * unnecessary. */ -#define LIBC -#ifndef LIBC -/* rename functions not to conflict with libc */ -#ifndef myprefix -#define myprefix fsmu8_ -#endif -#define concat2(a,b) a ## b -#define concat(a,b) concat2(a,b) -#define prefix(b) concat(myprefix,b) - -#undef mblen -#undef mbrlen -#undef mbrtowc -#undef mbsinit -#undef mbsnrtowcs -#undef mbsrtowcs -#undef wcrtomb -#undef wcsrtombs -#undef wcstombs -#undef wctomb -#define mblen prefix(mblen) -#define mbrlen prefix(mbrlen) -#define mbrtowc prefix(mbrtowc) -#define mbsinit prefix(mbsinit) -#define mbsnrtowcs prefix(mbsnrtowcs) -#define mbsrtowcs prefix(mbsrtowcs) -#define mbstowcs prefix(mbstowcs) -#define wcrtomb prefix(wcrtomb) -#define wcsnrtombs prefix(wcsnrtombs) -#define wcsrtombs prefix(wcsrtombs) -#define wcstombs prefix(wcstombs) -#define wctomb prefix(wctomb) - -#define bittab prefix(bittab) -#else #define bittab __fsmu8 -#endif +#if 100*__GNUC__+__GNUC_MINOR__ >= 303 || defined(__PCC__) || defined(__TINYC__) +extern const uint32_t bittab[] __attribute__((visibility("hidden"))); +#else extern const uint32_t bittab[]; +#endif /* Upper 6 state bits are a negative integer offset to bound-check next byte */ /* equivalent to: ( (b-0x80) | (b+offset) ) & ~0x3f */ @@ -52,10 +20,5 @@ extern const uint32_t bittab[]; #define R(a,b) ((uint32_t)((a==0x80 ? 0x40-b : -a) << 23)) #define FAILSTATE R(0x80,0x80) -#ifdef I_FAILED_TO_RTFM_RFC3629 -#define SA 0xc2u -#define SB 0xfeu -#else #define SA 0xc2u #define SB 0xf5u -#endif diff --git a/src/multibyte/mbsrtowcs.c b/src/multibyte/mbsrtowcs.c index 64399cf2..ebf0d6c9 100644 --- a/src/multibyte/mbsrtowcs.c +++ b/src/multibyte/mbsrtowcs.c @@ -42,12 +42,6 @@ size_t mbsrtowcs(wchar_t *ws, const char **src, size_t wn, mbstate_t *st) resume0: if (OOB(c,*s)) goto ilseq2; s++; c <<= 6; if (!(c&(1U<<31))) break; -#ifdef I_FAILED_TO_RTFM_RFC3629 - if (*s++-0x80u >= 0x40) goto ilseq2; - c <<= 6; if (!(c&(1U<<31))) break; - if (*s++-0x80u >= 0x40) goto ilseq2; - c <<= 6; if (!(c&(1U<<31))) break; -#endif if (*s++-0x80u >= 0x40) goto ilseq2; c <<= 6; if (!(c&(1U<<31))) break; if (*s++-0x80u >= 0x40) goto ilseq2; @@ -89,16 +83,6 @@ resume: c = (c<<6) | *s++-0x80; if (!(c&(1U<<31))) break; -#ifdef I_FAILED_TO_RTFM_RFC3629 - if (*s-0x80u >= 0x40) goto ilseq; - c = (c<<6) | *s++-0x80; - if (!(c&(1U<<31))) break; - - if (*s-0x80u >= 0x40) goto ilseq; - c = (c<<6) | *s++-0x80; - if (!(c&(1U<<31))) break; -#endif - if (*s-0x80u >= 0x40) goto ilseq; c = (c<<6) | *s++-0x80; if (!(c&(1U<<31))) break; |