diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-01-16 16:34:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-16 16:34:21 (GMT) |
commit | 4d9aec022063dcfc4cf40ae46b1c4a968297e664 (patch) | |
tree | d422eb5dbd9f265fca38e7315b95ab3faa66adab /Modules/_io/bufferedio.c | |
parent | 378edee0a3b913d60653dc17dfe61d83405a8135 (diff) | |
download | cpython-4d9aec022063dcfc4cf40ae46b1c4a968297e664.zip cpython-4d9aec022063dcfc4cf40ae46b1c4a968297e664.tar.gz cpython-4d9aec022063dcfc4cf40ae46b1c4a968297e664.tar.bz2 |
bpo-31572: Get rid of PyObject_HasAttr() and _PyObject_HasAttrId() in the _io module. (#3726)
Diffstat (limited to 'Modules/_io/bufferedio.c')
-rw-r--r-- | Modules/_io/bufferedio.c | 32 |
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); |