[Python-checkins] cpython: Make _PyUnicode_FromId return borrowed references.
martin.v.loewis
python-checkins at python.org
Tue Nov 8 17:44:13 CET 2011
http://hg.python.org/cpython/rev/6ae8c68eb0c1
changeset: 73457:6ae8c68eb0c1
user: Martin v. Löwis <martin at v.loewis.de>
date: Mon Nov 07 13:00:05 2011 +0100
summary:
Make _PyUnicode_FromId return borrowed references.
http://mail.python.org/pipermail/python-dev/2011-November/114347.html
files:
Include/unicodeobject.h | 2 +-
Objects/object.c | 9 +++------
Objects/typeobject.c | 3 +--
Objects/unicodeobject.c | 1 -
Python/_warnings.c | 2 --
5 files changed, 5 insertions(+), 12 deletions(-)
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h
--- a/Include/unicodeobject.h
+++ b/Include/unicodeobject.h
@@ -2024,7 +2024,7 @@
shutdown, all strings are released (through _PyUnicode_ClearStaticStrings).
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*.
*/
typedef struct _Py_Identifier {
diff --git a/Objects/object.c b/Objects/object.c
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -814,11 +814,10 @@
_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 @@
_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 @@
_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;
}
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -1716,11 +1716,10 @@
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;
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -1723,7 +1723,6 @@
id->next = static_strings;
static_strings = id;
}
- Py_INCREF(id->object);
return id->object;
}
diff --git a/Python/_warnings.c b/Python/_warnings.c
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -666,10 +666,8 @@
if ((tmp = _PyUnicode_FromId(&PyId_get_source)) == NULL)
return NULL;
- Py_DECREF(tmp);
if ((tmp = _PyUnicode_FromId(&PyId_splitlines)) == NULL)
return NULL;
- Py_DECREF(tmp);
/* Check/get the requisite pieces needed for the loader. */
loader = PyDict_GetItemString(module_globals, "__loader__");
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list