mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Make _PyUnicode_FromId return borrowed references.
http://mail.python.org/pipermail/python-dev/2011-November/114347.html
This commit is contained in:
parent
e9b11c1cd8
commit
d10759f6ed
5 changed files with 5 additions and 12 deletions
|
@ -2024,7 +2024,7 @@ PyAPI_FUNC(int) _PyUnicode_CheckConsistency(
|
||||||
shutdown, all strings are released (through _PyUnicode_ClearStaticStrings).
|
shutdown, all strings are released (through _PyUnicode_ClearStaticStrings).
|
||||||
|
|
||||||
Alternatively, _Py_static_string allows to choose the variable name.
|
Alternatively, _Py_static_string allows to choose the variable name.
|
||||||
_PyUnicode_FromId returns a new reference to the interned string.
|
_PyUnicode_FromId returns a borrowed reference to the interned string.
|
||||||
_PyObject_{Get,Set,Has}AttrId are __getattr__ versions using _Py_Identifier*.
|
_PyObject_{Get,Set,Has}AttrId are __getattr__ versions using _Py_Identifier*.
|
||||||
*/
|
*/
|
||||||
typedef struct _Py_Identifier {
|
typedef struct _Py_Identifier {
|
||||||
|
|
|
@ -814,11 +814,10 @@ PyObject *
|
||||||
_PyObject_GetAttrId(PyObject *v, _Py_Identifier *name)
|
_PyObject_GetAttrId(PyObject *v, _Py_Identifier *name)
|
||||||
{
|
{
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
PyObject *oname = _PyUnicode_FromId(name);
|
PyObject *oname = _PyUnicode_FromId(name); /* borrowed */
|
||||||
if (!oname)
|
if (!oname)
|
||||||
return NULL;
|
return NULL;
|
||||||
result = PyObject_GetAttr(v, oname);
|
result = PyObject_GetAttr(v, oname);
|
||||||
Py_DECREF(oname);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -826,11 +825,10 @@ int
|
||||||
_PyObject_HasAttrId(PyObject *v, _Py_Identifier *name)
|
_PyObject_HasAttrId(PyObject *v, _Py_Identifier *name)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
PyObject *oname = _PyUnicode_FromId(name);
|
PyObject *oname = _PyUnicode_FromId(name); /* borrowed */
|
||||||
if (!oname)
|
if (!oname)
|
||||||
return -1;
|
return -1;
|
||||||
result = PyObject_HasAttr(v, oname);
|
result = PyObject_HasAttr(v, oname);
|
||||||
Py_DECREF(oname);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -838,11 +836,10 @@ int
|
||||||
_PyObject_SetAttrId(PyObject *v, _Py_Identifier *name, PyObject *w)
|
_PyObject_SetAttrId(PyObject *v, _Py_Identifier *name, PyObject *w)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
PyObject *oname = _PyUnicode_FromId(name);
|
PyObject *oname = _PyUnicode_FromId(name); /* borrowed */
|
||||||
if (!oname)
|
if (!oname)
|
||||||
return -1;
|
return -1;
|
||||||
result = PyObject_SetAttr(v, oname, w);
|
result = PyObject_SetAttr(v, oname, w);
|
||||||
Py_DECREF(oname);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1716,11 +1716,10 @@ get_dict_descriptor(PyTypeObject *type)
|
||||||
PyObject *dict_str;
|
PyObject *dict_str;
|
||||||
PyObject *descr;
|
PyObject *descr;
|
||||||
|
|
||||||
dict_str = _PyUnicode_FromId(&PyId___dict__);
|
dict_str = _PyUnicode_FromId(&PyId___dict__); /* borrowed */
|
||||||
if (dict_str == NULL)
|
if (dict_str == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
descr = _PyType_Lookup(type, dict_str);
|
descr = _PyType_Lookup(type, dict_str);
|
||||||
Py_DECREF(dict_str);
|
|
||||||
if (descr == NULL || !PyDescr_IsData(descr))
|
if (descr == NULL || !PyDescr_IsData(descr))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
|
@ -1723,7 +1723,6 @@ _PyUnicode_FromId(_Py_Identifier *id)
|
||||||
id->next = static_strings;
|
id->next = static_strings;
|
||||||
static_strings = id;
|
static_strings = id;
|
||||||
}
|
}
|
||||||
Py_INCREF(id->object);
|
|
||||||
return id->object;
|
return id->object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -666,10 +666,8 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)
|
||||||
|
|
||||||
if ((tmp = _PyUnicode_FromId(&PyId_get_source)) == NULL)
|
if ((tmp = _PyUnicode_FromId(&PyId_get_source)) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
Py_DECREF(tmp);
|
|
||||||
if ((tmp = _PyUnicode_FromId(&PyId_splitlines)) == NULL)
|
if ((tmp = _PyUnicode_FromId(&PyId_splitlines)) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
Py_DECREF(tmp);
|
|
||||||
|
|
||||||
/* Check/get the requisite pieces needed for the loader. */
|
/* Check/get the requisite pieces needed for the loader. */
|
||||||
loader = PyDict_GetItemString(module_globals, "__loader__");
|
loader = PyDict_GetItemString(module_globals, "__loader__");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue