summaryrefslogtreecommitdiffstats
path: root/Modules/_io/bytesio.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_io/bytesio.c')
-rw-r--r--Modules/_io/bytesio.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c
index 54840bb..b55ab72 100644
--- a/Modules/_io/bytesio.c
+++ b/Modules/_io/bytesio.c
@@ -258,10 +258,10 @@ bytesio_tell(bytesio *self)
}
PyDoc_STRVAR(read_doc,
-"read([size]) -> read at most size bytes, returned as a string.\n"
+"read([size]) -> read at most size bytes, returned as a bytes object.\n"
"\n"
"If the size argument is negative, read until EOF is reached.\n"
-"Return an empty string at EOF.");
+"Return an empty bytes object at EOF.");
static PyObject *
bytesio_read(bytesio *self, PyObject *args)
@@ -307,10 +307,10 @@ bytesio_read(bytesio *self, PyObject *args)
PyDoc_STRVAR(read1_doc,
-"read1(size) -> read at most size bytes, returned as a string.\n"
+"read1(size) -> read at most size bytes, returned as a bytes object.\n"
"\n"
"If the size argument is negative or omitted, read until EOF is reached.\n"
-"Return an empty string at EOF.");
+"Return an empty bytes object at EOF.");
static PyObject *
bytesio_read1(bytesio *self, PyObject *n)
@@ -326,11 +326,11 @@ bytesio_read1(bytesio *self, PyObject *n)
}
PyDoc_STRVAR(readline_doc,
-"readline([size]) -> next line from the file, as a string.\n"
+"readline([size]) -> next line from the file, as a bytes object.\n"
"\n"
"Retain newline. A non-negative size argument limits the maximum\n"
"number of bytes to return (an incomplete line may be returned then).\n"
-"Return an empty string at EOF.\n");
+"Return an empty bytes object at EOF.\n");
static PyObject *
bytesio_readline(bytesio *self, PyObject *args)
@@ -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);
}
@@ -528,7 +530,7 @@ bytesio_iternext(bytesio *self)
}
PyDoc_STRVAR(seek_doc,
-"seek(pos, whence=0) -> int. Change stream position.\n"
+"seek(pos[, whence]) -> int. Change stream position.\n"
"\n"
"Seek to byte offset pos relative to position indicated by whence:\n"
" 0 Start of stream (the default). pos should be >= 0;\n"
@@ -613,11 +615,11 @@ bytesio_write(bytesio *self, PyObject *obj)
}
PyDoc_STRVAR(writelines_doc,
-"writelines(sequence_of_strings) -> None. Write strings to the file.\n"
+"writelines(lines) -> None. Write bytes objects to the file.\n"
"\n"
-"Note that newlines are not added. The sequence can be any iterable\n"
-"object producing strings. This is equivalent to calling write() for\n"
-"each string.");
+"Note that newlines are not added. The argument can be any iterable\n"
+"object producing bytes objects. This is equivalent to calling write() for\n"
+"each bytes object.");
static PyObject *
bytesio_writelines(bytesio *self, PyObject *v)
@@ -655,6 +657,7 @@ PyDoc_STRVAR(close_doc,
static PyObject *
bytesio_close(bytesio *self)
{
+ CHECK_EXPORTS(self);
if (self->buf != NULL) {
PyMem_Free(self->buf);
self->buf = NULL;