Skip to content

Commit 3ee05af

Browse files
committed
Stream functions like read() are supposed to return bytes, not buffer.
Now multibytecodec directly works with PyStrings, and disallow PyBytes.
1 parent af59346 commit 3ee05af

1 file changed

Lines changed: 9 additions & 17 deletions

File tree

Modules/cjkcodecs/multibytecodec.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,44 +1230,36 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self,
12301230
if (cres == NULL)
12311231
goto errorexit;
12321232

1233-
if (PyString_Check(cres)) {
1234-
PyObject *cres2 = PyBytes_FromObject(cres);
1235-
if (cres2 == NULL)
1236-
return NULL;
1237-
Py_DECREF(cres);
1238-
cres = cres2;
1239-
}
1240-
1241-
if (!PyBytes_Check(cres)) {
1233+
if (!PyString_Check(cres)) {
12421234
PyErr_Format(PyExc_TypeError,
12431235
"stream function returned a "
12441236
"non-bytes object (%.100s)",
12451237
cres->ob_type->tp_name);
12461238
goto errorexit;
12471239
}
12481240

1249-
endoffile = (PyBytes_GET_SIZE(cres) == 0);
1241+
endoffile = (PyString_GET_SIZE(cres) == 0);
12501242

12511243
if (self->pendingsize > 0) {
12521244
PyObject *ctr;
12531245
char *ctrdata;
12541246

1255-
rsize = PyBytes_GET_SIZE(cres) + self->pendingsize;
1256-
ctr = PyBytes_FromStringAndSize(NULL, rsize);
1247+
rsize = PyString_GET_SIZE(cres) + self->pendingsize;
1248+
ctr = PyString_FromStringAndSize(NULL, rsize);
12571249
if (ctr == NULL)
12581250
goto errorexit;
1259-
ctrdata = PyBytes_AS_STRING(ctr);
1251+
ctrdata = PyString_AS_STRING(ctr);
12601252
memcpy(ctrdata, self->pending, self->pendingsize);
12611253
memcpy(ctrdata + self->pendingsize,
1262-
PyBytes_AS_STRING(cres),
1263-
PyBytes_GET_SIZE(cres));
1254+
PyString_AS_STRING(cres),
1255+
PyString_GET_SIZE(cres));
12641256
Py_DECREF(cres);
12651257
cres = ctr;
12661258
self->pendingsize = 0;
12671259
}
12681260

1269-
rsize = PyBytes_GET_SIZE(cres);
1270-
if (decoder_prepare_buffer(&buf, PyBytes_AS_STRING(cres),
1261+
rsize = PyString_GET_SIZE(cres);
1262+
if (decoder_prepare_buffer(&buf, PyString_AS_STRING(cres),
12711263
rsize) != 0)
12721264
goto errorexit;
12731265

0 commit comments

Comments
 (0)