summaryrefslogtreecommitdiffstats
path: root/Modules/_io/bufferedio.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_io/bufferedio.c')
-rw-r--r--Modules/_io/bufferedio.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
index d7e82b9..b81abde 100644
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -1521,7 +1521,7 @@ static PyObject *
_bufferedreader_read_all(buffered *self)
{
Py_ssize_t current_size;
- PyObject *res = NULL, *data = NULL, *tmp = NULL, *chunks = NULL;
+ PyObject *res = NULL, *data = NULL, *tmp = NULL, *chunks = NULL, *readall;
/* First copy what we have in the current buffer. */
current_size = Py_SAFE_DOWNCAST(READAHEAD(self), Py_off_t, Py_ssize_t);
@@ -1541,32 +1541,28 @@ _bufferedreader_read_all(buffered *self)
}
_bufferedreader_reset_buf(self);
- if (PyObject_HasAttr(self->raw, _PyIO_str_readall)) {
- tmp = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_readall, NULL);
+ readall = _PyObject_GetAttrWithoutError(self->raw, _PyIO_str_readall);
+ if (readall) {
+ tmp = _PyObject_CallNoArg(readall);
+ Py_DECREF(readall);
if (tmp == NULL)
goto cleanup;
if (tmp != Py_None && !PyBytes_Check(tmp)) {
PyErr_SetString(PyExc_TypeError, "readall() should return bytes");
goto cleanup;
}
- if (tmp == Py_None) {
- if (current_size == 0) {
- res = Py_None;
- goto cleanup;
- } else {
- res = data;
- goto cleanup;
+ if (current_size == 0) {
+ res = tmp;
+ } else {
+ if (tmp != Py_None) {
+ PyBytes_Concat(&data, tmp);
}
- }
- else if (current_size) {
- PyBytes_Concat(&data, tmp);
res = data;
- goto cleanup;
- }
- else {
- res = tmp;
- goto cleanup;
}
+ goto cleanup;
+ }
+ else if (PyErr_Occurred()) {
+ goto cleanup;
}
chunks = PyList_New(0);