Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d1f9942

Browse files
committed
Issue #18408: Fix cjkcodecs decoders, add a new MBERR_EXCEPTION constant to
notify exceptions raised by the _PyUnicodeWriter API
1 parent 85c761d commit d1f9942

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

Modules/cjkcodecs/cjkcodecs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ static const struct dbcs_map *mapping_list;
130130
#define OUTCHAR(c) \
131131
do { \
132132
if (_PyUnicodeWriter_WriteChar(writer, (c)) < 0) \
133-
return MBERR_TOOSMALL; \
133+
return MBERR_EXCEPTION; \
134134
} while (0)
135135

136136
#define OUTCHAR2(c1, c2) \
137137
do { \
138138
Py_UCS4 _c1 = (c1); \
139139
Py_UCS4 _c2 = (c2); \
140140
if (_PyUnicodeWriter_Prepare(writer, 2, Py_MAX(_c1, c2)) < 0) \
141-
return MBERR_TOOSMALL; \
141+
return MBERR_EXCEPTION; \
142142
PyUnicode_WRITE(writer->kind, writer->data, writer->pos, _c1); \
143143
PyUnicode_WRITE(writer->kind, writer->data, writer->pos + 1, _c2); \
144144
writer->pos += 2; \

Modules/cjkcodecs/multibytecodec.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ multibytecodec_decerror(MultibyteCodec *codec,
384384
PyErr_SetString(PyExc_RuntimeError,
385385
"internal codec error");
386386
return -1;
387+
case MBERR_EXCEPTION:
388+
return -1;
387389
default:
388390
PyErr_SetString(PyExc_RuntimeError,
389391
"unknown runtime error");

Modules/cjkcodecs/multibytecodec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ typedef struct {
112112
#define MBERR_TOOSMALL (-1) /* insufficient output buffer space */
113113
#define MBERR_TOOFEW (-2) /* incomplete input buffer */
114114
#define MBERR_INTERNAL (-3) /* internal runtime error */
115+
#define MBERR_EXCEPTION (-4) /* an exception has been raised */
115116

116117
#define ERROR_STRICT (PyObject *)(1)
117118
#define ERROR_IGNORE (PyObject *)(2)

0 commit comments

Comments
 (0)