Skip to content

Commit 059189c

Browse files
committed
Some small cleanups for multibyte functions
1 parent 5e1107c commit 059189c

File tree

8 files changed

+16
-14
lines changed

8 files changed

+16
-14
lines changed

multibyte/internal.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
| x )
1818
#define F(x) ( ( x>=5 ? 0 : \
1919
x==0 ? R(0x90,0xc0) : \
20-
x==4 ? R(0x80,0xa0) : \
20+
x==4 ? R(0x80,0x90) : \
2121
R(0x80,0xc0) ) \
2222
| ( R(0x80,0xc0) >> 6 ) \
2323
| ( R(0x80,0xc0) >> 12 ) \
@@ -32,7 +32,3 @@ const uint32_t bittab[] = {
3232
E(0x8),E(0x9),E(0xa),E(0xb),E(0xc),E(0xd),E(0xe),E(0xf),
3333
F(0x0),F(0x1),F(0x2),F(0x3),F(0x4)
3434
};
35-
36-
#ifdef BROKEN_VISIBILITY
37-
__asm__(".hidden __fsmu8");
38-
#endif

multibyte/internal.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ extern const uint32_t bittab[]; /* ATTR_LIBC_VISIBILITY; */
1616
#define OOB(c,b) (((((b)>>3)-0x10)|(((b)>>3)+((int32_t)(c)>>26))) & ~7)
1717

1818
/* Interval [a,b). Either a must be 80 or b must be c0, lower 3 bits clear. */
19-
#define R(a,b) ((uint32_t)((a==0x80 ? 0x40-b : -a) << 23))
19+
#define R(a,b) ((uint32_t)(a==0x80 ? 0x40u-b : 0u-a) << 23)
2020
#define FAILSTATE R(0x80,0x80)
2121

2222
#define SA 0xc2u
2323
#define SB 0xf4u
24+
25+
/* Arbitrary encoding for representing code units instead of characters. */
26+
#define CODEUNIT(c) (0xdfff & (signed char)(c))
27+
#define IS_CODEUNIT(c) ((unsigned)(c)-0xdf80 < 0x80)

multibyte/mbrlen.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313

1414
size_t mbrlen(const char *__restrict s, size_t n, mbstate_t *__restrict st)
1515
{
16-
static unsigned internal;
17-
return mbrtowc(0, s, n, st ? st : (mbstate_t *)&internal);
16+
static mbstate_t internal;
17+
return mbrtowc(0, s, n, st ? st : &internal);
1818
}

multibyte/mbrtowc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ size_t mbrtowc(wchar_t *__restrict wc, const char *__restrict src, size_t n, mbs
1717
unsigned c;
1818
const unsigned char *s = (const void *)src;
1919
const unsigned N = n;
20+
wchar_t dummy;
2021

2122
if (!st) st = &internal_state;
2223
c = st->__opaque1;
2324

2425
if (!s) {
2526
if (c) goto ilseq;
2627
return 0;
27-
} else if (!wc) wc = (void *)&wc;
28+
} else if (!wc) wc = &dummy;
2829

2930
if (!n) return -2;
3031
if (!c) {

multibyte/mbsinit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313

1414
int mbsinit(const mbstate_t *st)
1515
{
16-
return !st || !*(unsigned *)st;
16+
return !st || !st->__opaque1;
1717
}

multibyte/mbsnrtowcs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ size_t mbsnrtowcs(wchar_t *__restrict wcs, const char **__restrict src, size_t n
5252
break;
5353
}
5454
/* have to roll back partial character */
55-
*(unsigned *)st = 0;
55+
st->__opaque1 = 0;
5656
break;
5757
}
5858
s += l; n -= l;

multibyte/mbsrtowcs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ size_t mbsrtowcs(wchar_t *__restrict ws, const char **__restrict src, size_t wn,
1717
size_t wn0 = wn;
1818
unsigned c = 0;
1919

20-
if (st && (c = *(unsigned *)st)) {
20+
if (st && (c = st->__opaque1) != 0) {
2121
if (ws) {
22-
*(unsigned *)st = 0;
22+
st->__opaque1 = 0;
2323
goto resume;
2424
} else {
2525
goto resume0;

multibyte/mbtowc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ int mbtowc(wchar_t *__restrict wc, const char *__restrict src, size_t n)
1515
{
1616
unsigned c;
1717
const unsigned char *s = (const void *)src;
18+
wchar_t dummy;
1819

1920
if (!s) return 0;
2021
if (!n) goto ilseq;
21-
if (!wc) wc = (void *)&wc;
22+
if (!wc) wc = &dummy;
2223

2324
if (*s < 0x80) return !!(*wc = *s);
2425
if (*s-SA > SB-SA) goto ilseq;

0 commit comments

Comments
 (0)