Changeset f94a11f in mainline


Ignore:
Timestamp:
2025-04-15T18:38:48Z (19 hours ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master
Children:
65bf084
Parents:
5d2bdaa
Message:

Rename mbstate_t field to prevent confusion with continuation bytes

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • abi/include/_bits/mbstate_t.h

    r5d2bdaa rf94a11f  
    3737
    3838typedef struct {
    39         unsigned short continuation;
     39        unsigned short state;
    4040} mbstate_t;
    4141
  • common/stdc/uchar.c

    r5d2bdaa rf94a11f  
    111111        if (!s) {
    112112                // Equivalent to mbrtoc32(NULL, "", 1, mb).
    113                 if (mb->continuation) {
     113                if (mb->state) {
    114114                        _set_ilseq();
    115115                        return UCHAR_ILSEQ;
     
    121121        size_t i = 0;
    122122
    123         if (!mb->continuation) {
     123        if (!mb->state) {
    124124                /* Clean slate, read initial byte. */
    125125
     
    152152
    153153                        /* 2 byte encoding               110xxxxx */
    154                         mb->continuation = b ^ 0b0000000011000000;
     154                        mb->state = b ^ 0b0000000011000000;
    155155
    156156                } else if (_is_3_byte(b)) {
    157157                        /* 3 byte encoding               1110xxxx */
    158                         mb->continuation = b ^ 0b1111110011100000;
     158                        mb->state = b ^ 0b1111110011100000;
    159159
    160160                } else if (_is_4_byte(b)) {
    161161                        /* 4 byte encoding               11110xxx */
    162                         mb->continuation = b ^ 0b1111111100000000;
     162                        mb->state = b ^ 0b1111111100000000;
    163163                }
    164164        }
     
    168168                uint8_t b = s[i];
    169169
    170                 if (!_is_continuation(b) || _is_non_shortest(mb->continuation, b)) {
     170                if (!_is_continuation(b) || _is_non_shortest(mb->state, b)) {
    171171                        _set_ilseq();
    172172                        return UCHAR_ILSEQ;
     
    174174
    175175                /* Top bit becomes zero just before the last byte is shifted in. */
    176                 if (!(mb->continuation & 0x8000)) {
    177                         *c = ((char32_t) mb->continuation) << 6 | (b & 0x3f);
    178                         mb->continuation = 0;
     176                if (!(mb->state & 0x8000)) {
     177                        *c = ((char32_t) mb->state) << 6 | (b & 0x3f);
     178                        mb->state = 0;
    179179                        return ++i;
    180180                }
    181181
    182                 mb->continuation = mb->continuation << 6 | (b & 0x3f);
     182                mb->state = mb->state << 6 | (b & 0x3f);
    183183        }
    184184
     
    253253        if (!s) {
    254254                /* Equivalent to mbrtoc16(NULL, "", 1, mb). */
    255                 if (mb->continuation) {
     255                if (mb->state) {
    256256                        _set_ilseq();
    257257                        return UCHAR_ILSEQ;
     
    261261        }
    262262
    263         if ((mb->continuation & 0xD000) == 0xD000) {
     263        if ((mb->state & 0xD000) == 0xD000) {
    264264                /* mbstate_t contains the second surrogate character. */
    265265                /* mbrtoc32() will never set it to such value.        */
    266                 *c = mb->continuation;
    267                 mb->continuation = 0;
     266                *c = mb->state;
     267                mb->state = 0;
    268268                return UCHAR_CONTINUED;
    269269        }
     
    276276                } else {
    277277                        /* Encode UTF-16 surrogates. */
    278                         mb->continuation = (c32 & 0x3FF) + 0xDC00;
     278                        mb->state = (c32 & 0x3FF) + 0xDC00;
    279279                        *c = (c32 >> 10) + 0xD7C0;
    280280                }
     
    298298        if (!s) {
    299299                // Equivalent to c16rtomb(buf, L’\0’, mb).
    300                 if (mb->continuation) {
     300                if (mb->state) {
    301301                        _set_ilseq();
    302302                        return UCHAR_ILSEQ;
     
    307307
    308308        if (!_is_surrogate(c)) {
    309                 if (mb->continuation) {
     309                if (mb->state) {
    310310                        _set_ilseq();
    311311                        return UCHAR_ILSEQ;
     
    315315        }
    316316
    317         if (!mb->continuation) {
    318                 mb->continuation = c;
     317        if (!mb->state) {
     318                mb->state = c;
    319319                return 0;
    320320        }
     
    323323
    324324        /* Decode UTF-16 surrogates. */
    325         if (_is_low_surrogate(mb->continuation) && _is_high_surrogate(c)) {
    326                 c32 = ((c - 0xD7C0) << 10) | (mb->continuation - 0xDC00);
    327         } else if (_is_high_surrogate(mb->continuation) && _is_low_surrogate(c)) {
    328                 c32 = ((mb->continuation - 0xD7C0) << 10) | (c - 0xDC00);
     325        if (_is_low_surrogate(mb->state) && _is_high_surrogate(c)) {
     326                c32 = ((c - 0xD7C0) << 10) | (mb->state - 0xDC00);
     327        } else if (_is_high_surrogate(mb->state) && _is_low_surrogate(c)) {
     328                c32 = ((mb->state - 0xD7C0) << 10) | (c - 0xDC00);
    329329        } else {
    330330                _set_ilseq();
     
    332332        }
    333333
    334         mb->continuation = 0;
     334        mb->state = 0;
    335335        return c32rtomb(s, c32, mb);
    336336}
  • common/stdc/wchar.c

    r5d2bdaa rf94a11f  
    4646int mbsinit(const mbstate_t *ps)
    4747{
    48         return ps == NULL || ps->continuation == 0;
     48        return ps == NULL || ps->state == 0;
    4949}
    5050
Note: See TracChangeset for help on using the changeset viewer.