diff options
-rw-r--r-- | Modules/_io/_iomodule.c | 3 | ||||
-rw-r--r-- | Modules/_io/bufferedio.c | 8 | ||||
-rw-r--r-- | Modules/_io/fileio.c | 3 | ||||
-rw-r--r-- | Modules/_io/iobase.c | 9 | ||||
-rw-r--r-- | Modules/_io/textio.c | 16 |
5 files changed, 25 insertions, 14 deletions
diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index a8d3ed4..6e8d374 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -233,6 +233,7 @@ io_open(PyObject *self, PyObject *args, PyObject *kwds) _Py_IDENTIFIER(isatty); _Py_IDENTIFIER(fileno); + _Py_IDENTIFIER(mode); if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|sizzziO:open", kwlist, &file, &mode, &buffering, @@ -440,7 +441,7 @@ io_open(PyObject *self, PyObject *args, PyObject *kwds) if (wrapper == NULL) goto error; - if (PyObject_SetAttrString(wrapper, "mode", modeobj) < 0) + if (_PyObject_SetAttrId(wrapper, &PyId_mode, modeobj) < 0) goto error; Py_DECREF(modeobj); return wrapper; diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index 880ed78..87fac7c 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -17,6 +17,8 @@ _Py_IDENTIFIER(close); _Py_IDENTIFIER(_dealloc_warn); _Py_IDENTIFIER(flush); _Py_IDENTIFIER(isatty); +_Py_IDENTIFIER(mode); +_Py_IDENTIFIER(name); _Py_IDENTIFIER(peek); _Py_IDENTIFIER(read); _Py_IDENTIFIER(read1); @@ -556,14 +558,14 @@ static PyObject * buffered_name_get(buffered *self, void *context) { CHECK_INITIALIZED(self) - return PyObject_GetAttrString(self->raw, "name"); + return _PyObject_GetAttrId(self->raw, &PyId_name); } static PyObject * buffered_mode_get(buffered *self, void *context) { CHECK_INITIALIZED(self) - return PyObject_GetAttrString(self->raw, "mode"); + return _PyObject_GetAttrId(self->raw, &PyId_mode); } /* Lower-level APIs */ @@ -1301,7 +1303,7 @@ buffered_repr(buffered *self) { PyObject *nameobj, *res; - nameobj = PyObject_GetAttrString((PyObject *) self, "name"); + nameobj = _PyObject_GetAttrId((PyObject *) self, &PyId_name); if (nameobj == NULL) { if (PyErr_ExceptionMatches(PyExc_AttributeError)) PyErr_Clear(); diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index e3c0dd9..7364523 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -993,12 +993,13 @@ mode_string(fileio *self) static PyObject * fileio_repr(fileio *self) { + _Py_IDENTIFIER(name); PyObject *nameobj, *res; if (self->fd < 0) return PyUnicode_FromFormat("<_io.FileIO [closed]>"); - nameobj = PyObject_GetAttrString((PyObject *) self, "name"); + nameobj = _PyObject_GetAttrId((PyObject *) self, &PyId_name); if (nameobj == NULL) { if (PyErr_ExceptionMatches(PyExc_AttributeError)) PyErr_Clear(); diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c index 52f6aa0..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 * @@ -192,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; } @@ -467,12 +469,13 @@ iobase_readline(PyObject *self, PyObject *args) 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); diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index c63c3c7..e9abaf4 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -19,7 +19,11 @@ _Py_IDENTIFIER(fileno); _Py_IDENTIFIER(flush); _Py_IDENTIFIER(getpreferredencoding); _Py_IDENTIFIER(isatty); +_Py_IDENTIFIER(mode); +_Py_IDENTIFIER(name); +_Py_IDENTIFIER(raw); _Py_IDENTIFIER(read); +_Py_IDENTIFIER(read1); _Py_IDENTIFIER(readable); _Py_IDENTIFIER(replace); _Py_IDENTIFIER(reset); @@ -999,7 +1003,7 @@ textiowrapper_init(textio *self, PyObject *args, PyObject *kwds) ci = _PyCodec_Lookup(encoding); if (ci == NULL) goto error; - res = PyObject_GetAttrString(ci, "name"); + res = _PyObject_GetAttrId(ci, &PyId_name); Py_DECREF(ci); if (res == NULL) { if (PyErr_ExceptionMatches(PyExc_AttributeError)) @@ -1026,7 +1030,7 @@ textiowrapper_init(textio *self, PyObject *args, PyObject *kwds) if (Py_TYPE(buffer) == &PyBufferedReader_Type || Py_TYPE(buffer) == &PyBufferedWriter_Type || Py_TYPE(buffer) == &PyBufferedRandom_Type) { - raw = PyObject_GetAttrString(buffer, "raw"); + raw = _PyObject_GetAttrId(buffer, &PyId_raw); /* Cache the raw FileIO object to speed up 'closed' checks */ if (raw == NULL) { if (PyErr_ExceptionMatches(PyExc_AttributeError)) @@ -1046,7 +1050,7 @@ textiowrapper_init(textio *self, PyObject *args, PyObject *kwds) self->seekable = self->telling = PyObject_IsTrue(res); Py_DECREF(res); - self->has_read1 = PyObject_HasAttrString(buffer, "read1"); + self->has_read1 = _PyObject_HasAttrId(buffer, &PyId_read1); self->encoding_start_of_stream = 0; if (self->seekable && self->encoder) { @@ -2401,7 +2405,7 @@ textiowrapper_repr(textio *self) res = PyUnicode_FromString("<_io.TextIOWrapper"); if (res == NULL) return NULL; - nameobj = PyObject_GetAttrString((PyObject *) self, "name"); + nameobj = _PyObject_GetAttrId((PyObject *) self, &PyId_name); if (nameobj == NULL) { if (PyErr_ExceptionMatches(PyExc_AttributeError)) PyErr_Clear(); @@ -2417,7 +2421,7 @@ textiowrapper_repr(textio *self) if (res == NULL) return NULL; } - modeobj = PyObject_GetAttrString((PyObject *) self, "mode"); + modeobj = _PyObject_GetAttrId((PyObject *) self, &PyId_mode); if (modeobj == NULL) { if (PyErr_ExceptionMatches(PyExc_AttributeError)) PyErr_Clear(); @@ -2578,7 +2582,7 @@ static PyObject * textiowrapper_name_get(textio *self, void *context) { CHECK_INITIALIZED(self); - return PyObject_GetAttrString(self->buffer, "name"); + return _PyObject_GetAttrId(self->buffer, &PyId_name); } static PyObject * |