summaryrefslogtreecommitdiff
path: root/Modules/_io/bytesio.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_io/bytesio.c')
-rw-r--r--Modules/_io/bytesio.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c
index 54840bb88a..57c207341c 100644
--- a/Modules/_io/bytesio.c
+++ b/Modules/_io/bytesio.c
@@ -437,17 +437,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);
- 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;
@@ -455,10 +456,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);
}