Make _PyUnicode_FromId return borrowed references.

http://mail.python.org/pipermail/python-dev/2011-November/114347.html
This commit is contained in:
Martin v. Löwis 2011-11-07 13:00:05 +01:00
parent e9b11c1cd8
commit d10759f6ed
5 changed files with 5 additions and 12 deletions

View file

@ -814,11 +814,10 @@ PyObject *
_PyObject_GetAttrId(PyObject *v, _Py_Identifier *name)
{
PyObject *result;
PyObject *oname = _PyUnicode_FromId(name);
PyObject *oname = _PyUnicode_FromId(name); /* borrowed */
if (!oname)
return NULL;
result = PyObject_GetAttr(v, oname);
Py_DECREF(oname);
return result;
}
@ -826,11 +825,10 @@ int
_PyObject_HasAttrId(PyObject *v, _Py_Identifier *name)
{
int result;
PyObject *oname = _PyUnicode_FromId(name);
PyObject *oname = _PyUnicode_FromId(name); /* borrowed */
if (!oname)
return -1;
result = PyObject_HasAttr(v, oname);
Py_DECREF(oname);
return result;
}
@ -838,11 +836,10 @@ int
_PyObject_SetAttrId(PyObject *v, _Py_Identifier *name, PyObject *w)
{
int result;
PyObject *oname = _PyUnicode_FromId(name);
PyObject *oname = _PyUnicode_FromId(name); /* borrowed */
if (!oname)
return -1;
result = PyObject_SetAttr(v, oname, w);
Py_DECREF(oname);
return result;
}

View file

@ -1716,11 +1716,10 @@ get_dict_descriptor(PyTypeObject *type)
PyObject *dict_str;
PyObject *descr;
dict_str = _PyUnicode_FromId(&PyId___dict__);
dict_str = _PyUnicode_FromId(&PyId___dict__); /* borrowed */
if (dict_str == NULL)
return NULL;
descr = _PyType_Lookup(type, dict_str);
Py_DECREF(dict_str);
if (descr == NULL || !PyDescr_IsData(descr))
return NULL;

View file

@ -1723,7 +1723,6 @@ _PyUnicode_FromId(_Py_Identifier *id)
id->next = static_strings;
static_strings = id;
}
Py_INCREF(id->object);
return id->object;
}