mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
CJK codecs: less magic macros, require explicit semicolon
This commit is contained in:
parent
146a2ed0f2
commit
14c9fea60a
10 changed files with 233 additions and 190 deletions
|
@ -108,24 +108,26 @@ static const struct dbcs_map *mapping_list;
|
|||
} while (0)
|
||||
#define NEXT(i, o) \
|
||||
do { \
|
||||
NEXT_INCHAR(i); \
|
||||
NEXT_OUT(o); \
|
||||
NEXT_INCHAR(i); \
|
||||
NEXT_OUT(o); \
|
||||
} while (0)
|
||||
|
||||
#define REQUIRE_INBUF(n) \
|
||||
if (inleft < (n)) \
|
||||
return MBERR_TOOFEW;
|
||||
#define REQUIRE_OUTBUF(n) \
|
||||
if (outleft < (n)) \
|
||||
return MBERR_TOOSMALL;
|
||||
do { \
|
||||
if (outleft < (n)) \
|
||||
return MBERR_TOOSMALL; \
|
||||
} while (0)
|
||||
|
||||
#define INBYTE1 ((*inbuf)[0])
|
||||
#define INBYTE2 ((*inbuf)[1])
|
||||
#define INBYTE3 ((*inbuf)[2])
|
||||
#define INBYTE4 ((*inbuf)[3])
|
||||
|
||||
#define INCHAR1 PyUnicode_READ(kind, data, *inpos)
|
||||
#define INCHAR2 PyUnicode_READ(kind, data, *inpos + 1)
|
||||
#define INCHAR1 (PyUnicode_READ(kind, data, *inpos))
|
||||
#define INCHAR2 (PyUnicode_READ(kind, data, *inpos + 1))
|
||||
|
||||
#define OUTCHAR(c) \
|
||||
do { \
|
||||
|
@ -138,35 +140,47 @@ static const struct dbcs_map *mapping_list;
|
|||
Py_UCS4 _c1 = (c1); \
|
||||
Py_UCS4 _c2 = (c2); \
|
||||
if (_PyUnicodeWriter_Prepare(writer, 2, Py_MAX(_c1, c2)) < 0) \
|
||||
return MBERR_EXCEPTION; \
|
||||
return MBERR_EXCEPTION; \
|
||||
PyUnicode_WRITE(writer->kind, writer->data, writer->pos, _c1); \
|
||||
PyUnicode_WRITE(writer->kind, writer->data, writer->pos + 1, _c2); \
|
||||
writer->pos += 2; \
|
||||
} while (0)
|
||||
|
||||
#define OUTBYTE1(c) ((*outbuf)[0]) = (c);
|
||||
#define OUTBYTE2(c) ((*outbuf)[1]) = (c);
|
||||
#define OUTBYTE3(c) ((*outbuf)[2]) = (c);
|
||||
#define OUTBYTE4(c) ((*outbuf)[3]) = (c);
|
||||
#define OUTBYTE1(c) \
|
||||
do { ((*outbuf)[0]) = (c); } while (0)
|
||||
#define OUTBYTE2(c) \
|
||||
do { ((*outbuf)[1]) = (c); } while (0)
|
||||
#define OUTBYTE3(c) \
|
||||
do { ((*outbuf)[2]) = (c); } while (0)
|
||||
#define OUTBYTE4(c) \
|
||||
do { ((*outbuf)[3]) = (c); } while (0)
|
||||
|
||||
#define WRITEBYTE1(c1) \
|
||||
REQUIRE_OUTBUF(1) \
|
||||
(*outbuf)[0] = (c1);
|
||||
do { \
|
||||
REQUIRE_OUTBUF(1); \
|
||||
(*outbuf)[0] = (c1); \
|
||||
} while (0)
|
||||
#define WRITEBYTE2(c1, c2) \
|
||||
REQUIRE_OUTBUF(2) \
|
||||
(*outbuf)[0] = (c1); \
|
||||
(*outbuf)[1] = (c2);
|
||||
do { \
|
||||
REQUIRE_OUTBUF(2); \
|
||||
(*outbuf)[0] = (c1); \
|
||||
(*outbuf)[1] = (c2); \
|
||||
} while (0)
|
||||
#define WRITEBYTE3(c1, c2, c3) \
|
||||
REQUIRE_OUTBUF(3) \
|
||||
(*outbuf)[0] = (c1); \
|
||||
(*outbuf)[1] = (c2); \
|
||||
(*outbuf)[2] = (c3);
|
||||
do { \
|
||||
REQUIRE_OUTBUF(3); \
|
||||
(*outbuf)[0] = (c1); \
|
||||
(*outbuf)[1] = (c2); \
|
||||
(*outbuf)[2] = (c3); \
|
||||
} while (0)
|
||||
#define WRITEBYTE4(c1, c2, c3, c4) \
|
||||
REQUIRE_OUTBUF(4) \
|
||||
(*outbuf)[0] = (c1); \
|
||||
(*outbuf)[1] = (c2); \
|
||||
(*outbuf)[2] = (c3); \
|
||||
(*outbuf)[3] = (c4);
|
||||
do { \
|
||||
REQUIRE_OUTBUF(4); \
|
||||
(*outbuf)[0] = (c1); \
|
||||
(*outbuf)[1] = (c2); \
|
||||
(*outbuf)[2] = (c3); \
|
||||
(*outbuf)[3] = (c4); \
|
||||
} while (0)
|
||||
|
||||
#define _TRYMAP_ENC(m, assi, val) \
|
||||
((m)->map != NULL && (val) >= (m)->bottom && \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue