Commits

Martin von Löwis committed 5a29473

Replace {Get,Set,Has}AttrString with *AttrId.

Comments (0)

Files changed (5)

Modules/_io/_iomodule.c

 
     _Py_IDENTIFIER(isatty);
     _Py_IDENTIFIER(fileno);
+    _Py_IDENTIFIER(mode);
 
     if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|sizzziO:open", kwlist,
                                      &file, &mode, &buffering,
     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;

Modules/_io/bufferedio.c

 _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);
 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 */
 {
     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();

Modules/_io/fileio.c

 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();

Modules/_io/iobase.c

    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 *
 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;
     }
     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);

Modules/_io/textio.c

 _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);
         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))
     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))
     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) {
     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();
         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();
 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 *