diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-02-02 23:25:42 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-02-02 23:25:42 (GMT) |
commit | 3dd3e26680110b3eeadedc9c8457dfe1db2b913c (patch) | |
tree | 584a98eda6e93033ddaf313b95826e6e3cd887cb /Modules/_io | |
parent | 0b2a6dc42b9bf02408764133a8dfcd843bbd0e66 (diff) | |
parent | 4fdb68491e8b2d044c9173babf625bbb815c39d1 (diff) | |
download | cpython-3dd3e26680110b3eeadedc9c8457dfe1db2b913c.zip cpython-3dd3e26680110b3eeadedc9c8457dfe1db2b913c.tar.gz cpython-3dd3e26680110b3eeadedc9c8457dfe1db2b913c.tar.bz2 |
Issue #22896: Avoid to use PyObject_AsCharBuffer(), PyObject_AsReadBuffer()
and PyObject_AsWriteBuffer().
Diffstat (limited to 'Modules/_io')
-rw-r--r-- | Modules/_io/bytesio.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c index 56ad788..801ddcd 100644 --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -553,17 +553,18 @@ PyDoc_STRVAR(readinto_doc, "is set not to block as has no data to read."); static PyObject * -bytesio_readinto(bytesio *self, PyObject *buffer) +bytesio_readinto(bytesio *self, PyObject *arg) { - void *raw_buffer; + Py_buffer buffer; Py_ssize_t len, n; CHECK_CLOSED(self, NULL); - if (PyObject_AsWriteBuffer(buffer, &raw_buffer, &len) == -1) + if (!PyArg_Parse(arg, "w*", &buffer)) return NULL; /* adjust invalid sizes */ + len = buffer.len; n = self->string_size - self->pos; if (len > n) { len = n; @@ -571,10 +572,11 @@ bytesio_readinto(bytesio *self, PyObject *buffer) len = 0; } - memcpy(raw_buffer, self->buf + self->pos, len); + memcpy(buffer.buf, self->buf + self->pos, len); assert(self->pos + len < PY_SSIZE_T_MAX); assert(len >= 0); self->pos += len; + PyBuffer_Release(&buffer); return PyLong_FromSsize_t(len); } |