summaryrefslogtreecommitdiffstats
path: root/Modules/cjkcodecs
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2007-11-22 21:33:52 (GMT)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2007-11-22 21:33:52 (GMT)
commit3ee05afa53663452da0176c6a35cffeb8d45166d (patch)
treec869e6784087f9969ada93555e2437ca633bf5d4 /Modules/cjkcodecs
parentaf59346f1ac1d1acf0d17b789d0e69f6d95d6e38 (diff)
downloadcpython-3ee05afa53663452da0176c6a35cffeb8d45166d.zip
cpython-3ee05afa53663452da0176c6a35cffeb8d45166d.tar.gz
cpython-3ee05afa53663452da0176c6a35cffeb8d45166d.tar.bz2
Stream functions like read() are supposed to return bytes, not buffer.
Now multibytecodec directly works with PyStrings, and disallow PyBytes.
Diffstat (limited to 'Modules/cjkcodecs')
-rw-r--r--Modules/cjkcodecs/multibytecodec.c26
1 files changed, 9 insertions, 17 deletions
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c
index 3e4e22d..a05a017 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -1230,15 +1230,7 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self,
if (cres == NULL)
goto errorexit;
- if (PyString_Check(cres)) {
- PyObject *cres2 = PyBytes_FromObject(cres);
- if (cres2 == NULL)
- return NULL;
- Py_DECREF(cres);
- cres = cres2;
- }
-
- if (!PyBytes_Check(cres)) {
+ if (!PyString_Check(cres)) {
PyErr_Format(PyExc_TypeError,
"stream function returned a "
"non-bytes object (%.100s)",
@@ -1246,28 +1238,28 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self,
goto errorexit;
}
- endoffile = (PyBytes_GET_SIZE(cres) == 0);
+ endoffile = (PyString_GET_SIZE(cres) == 0);
if (self->pendingsize > 0) {
PyObject *ctr;
char *ctrdata;
- rsize = PyBytes_GET_SIZE(cres) + self->pendingsize;
- ctr = PyBytes_FromStringAndSize(NULL, rsize);
+ rsize = PyString_GET_SIZE(cres) + self->pendingsize;
+ ctr = PyString_FromStringAndSize(NULL, rsize);
if (ctr == NULL)
goto errorexit;
- ctrdata = PyBytes_AS_STRING(ctr);
+ ctrdata = PyString_AS_STRING(ctr);
memcpy(ctrdata, self->pending, self->pendingsize);
memcpy(ctrdata + self->pendingsize,
- PyBytes_AS_STRING(cres),
- PyBytes_GET_SIZE(cres));
+ PyString_AS_STRING(cres),
+ PyString_GET_SIZE(cres));
Py_DECREF(cres);
cres = ctr;
self->pendingsize = 0;
}
- rsize = PyBytes_GET_SIZE(cres);
- if (decoder_prepare_buffer(&buf, PyBytes_AS_STRING(cres),
+ rsize = PyString_GET_SIZE(cres);
+ if (decoder_prepare_buffer(&buf, PyString_AS_STRING(cres),
rsize) != 0)
goto errorexit;