summaryrefslogtreecommitdiffstats
path: root/Modules/_io/iobase.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_io/iobase.c')
-rw-r--r--Modules/_io/iobase.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c
index 35c7cdd..3bce1a5 100644
--- a/Modules/_io/iobase.c
+++ b/Modules/_io/iobase.c
@@ -59,8 +59,9 @@ PyDoc_STRVAR(iobase_doc,
of the IOBase object rather than the virtual `closed` attribute as returned
by whatever subclass. */
+_Py_IDENTIFIER(__IOBase_closed);
#define IS_CLOSED(self) \
- PyObject_HasAttrString(self, "__IOBase_closed")
+ _PyObject_HasAttrId(self, &PyId___IOBase_closed)
/* Internal methods */
static PyObject *
@@ -97,7 +98,9 @@ PyDoc_STRVAR(iobase_tell_doc,
static PyObject *
iobase_tell(PyObject *self, PyObject *args)
{
- return PyObject_CallMethod(self, "seek", "ii", 0, 1);
+ _Py_IDENTIFIER(seek);
+
+ return _PyObject_CallMethodId(self, &PyId_seek, "ii", 0, 1);
}
PyDoc_STRVAR(iobase_truncate_doc,
@@ -190,12 +193,13 @@ static PyObject *
iobase_close(PyObject *self, PyObject *args)
{
PyObject *res;
+ _Py_IDENTIFIER(__IOBase_closed);
if (IS_CLOSED(self))
Py_RETURN_NONE;
res = PyObject_CallMethodObjArgs(self, _PyIO_str_flush, NULL);
- PyObject_SetAttrString(self, "__IOBase_closed", Py_True);
+ _PyObject_SetAttrId(self, &PyId___IOBase_closed, Py_True);
if (res == NULL) {
return NULL;
}
@@ -464,12 +468,14 @@ iobase_readline(PyObject *self, PyObject *args)
int has_peek = 0;
PyObject *buffer, *result;
Py_ssize_t old_size = -1;
+ _Py_IDENTIFIER(read);
+ _Py_IDENTIFIER(peek);
if (!PyArg_ParseTuple(args, "|O&:readline", &_PyIO_ConvertSsize_t, &limit)) {
return NULL;
}
- if (PyObject_HasAttrString(self, "peek"))
+ if (_PyObject_HasAttrId(self, &PyId_peek))
has_peek = 1;
buffer = PyByteArray_FromStringAndSize(NULL, 0);
@@ -481,7 +487,9 @@ iobase_readline(PyObject *self, PyObject *args)
PyObject *b;
if (has_peek) {
- PyObject *readahead = PyObject_CallMethod(self, "peek", "i", 1);
+ _Py_IDENTIFIER(peek);
+ PyObject *readahead = _PyObject_CallMethodId(self, &PyId_peek, "i", 1);
+
if (readahead == NULL)
goto fail;
if (!PyBytes_Check(readahead)) {
@@ -515,7 +523,7 @@ iobase_readline(PyObject *self, PyObject *args)
Py_DECREF(readahead);
}
- b = PyObject_CallMethod(self, "read", "n", nreadahead);
+ b = _PyObject_CallMethodId(self, &PyId_read, "n", nreadahead);
if (b == NULL)
goto fail;
if (!PyBytes_Check(b)) {
@@ -601,7 +609,9 @@ iobase_readlines(PyObject *self, PyObject *args)
/* XXX special-casing this made sense in the Python version in order
to remove the bytecode interpretation overhead, but it could
probably be removed here. */
- PyObject *ret = PyObject_CallMethod(result, "extend", "O", self);
+ _Py_IDENTIFIER(extend);
+ PyObject *ret = _PyObject_CallMethodId(result, &PyId_extend, "O", self);
+
if (ret == NULL) {
Py_DECREF(result);
return NULL;
@@ -781,8 +791,11 @@ rawiobase_read(PyObject *self, PyObject *args)
return NULL;
}
- if (n < 0)
- return PyObject_CallMethod(self, "readall", NULL);
+ if (n < 0) {
+ _Py_IDENTIFIER(readall);
+
+ return _PyObject_CallMethodId(self, &PyId_readall, NULL);
+ }
/* TODO: allocate a bytes object directly instead and manually construct
a writable memoryview pointing to it. */
@@ -823,8 +836,9 @@ rawiobase_readall(PyObject *self, PyObject *args)
return NULL;
while (1) {
- PyObject *data = PyObject_CallMethod(self, "read",
- "i", DEFAULT_BUFFER_SIZE);
+ _Py_IDENTIFIER(read);
+ PyObject *data = _PyObject_CallMethodId(self, &PyId_read,
+ "i", DEFAULT_BUFFER_SIZE);
if (!data) {
Py_DECREF(chunks);
return NULL;