summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-11-29 07:54:17 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-11-29 07:54:17 (GMT)
commit9ec07721f459d14131d6453ccb6d2a1a0b0c1959 (patch)
treeed40463ef4cdc4a7beb4142860dafddf48105692 /Objects
parent27ec5bfdcbc646c0598834e7500790f0938c5557 (diff)
downloadcpython-9ec07721f459d14131d6453ccb6d2a1a0b0c1959.zip
cpython-9ec07721f459d14131d6453ccb6d2a1a0b0c1959.tar.gz
cpython-9ec07721f459d14131d6453ccb6d2a1a0b0c1959.tar.bz2
Issue #28797: Modifying the class __dict__ inside the __set_name__ method of
a descriptor that is used inside that class no longer prevents calling the __set_name__ method of other descriptors.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 606e08e..04da32b 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -7004,10 +7004,14 @@ update_all_slots(PyTypeObject* type)
static int
set_names(PyTypeObject *type)
{
- PyObject *key, *value, *set_name, *tmp;
+ PyObject *names_to_set, *key, *value, *set_name, *tmp;
Py_ssize_t i = 0;
- while (PyDict_Next(type->tp_dict, &i, &key, &value)) {
+ names_to_set = PyDict_Copy(type->tp_dict);
+ if (names_to_set == NULL)
+ return -1;
+
+ while (PyDict_Next(names_to_set, &i, &key, &value)) {
set_name = lookup_maybe(value, &PyId___set_name__);
if (set_name != NULL) {
tmp = PyObject_CallFunctionObjArgs(set_name, type, key, NULL);
@@ -7017,15 +7021,19 @@ set_names(PyTypeObject *type)
"Error calling __set_name__ on '%.100s' instance %R "
"in '%.100s'",
value->ob_type->tp_name, key, type->tp_name);
+ Py_DECREF(names_to_set);
return -1;
}
else
Py_DECREF(tmp);
}
- else if (PyErr_Occurred())
+ else if (PyErr_Occurred()) {
+ Py_DECREF(names_to_set);
return -1;
+ }
}
+ Py_DECREF(names_to_set);
return 0;
}