summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-01-12 15:34:01 (GMT)
committerBenjamin Peterson <benjamin@python.org>2011-01-12 15:34:01 (GMT)
commit477ba919c158ba6e7a4b85d15f2e2b8820272cd9 (patch)
tree9134a7531c5ef7fddc917adb8a15d21ced72a586 /Objects
parent5e8dada4918e9baa023b9262127d60a6f9067818 (diff)
downloadcpython-477ba919c158ba6e7a4b85d15f2e2b8820272cd9.zip
cpython-477ba919c158ba6e7a4b85d15f2e2b8820272cd9.tar.gz
cpython-477ba919c158ba6e7a4b85d15f2e2b8820272cd9.tar.bz2
don't segfault on deleting __abstractmethods__ #10892
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 1fefe84..930297a 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -340,8 +340,17 @@ type_set_abstractmethods(PyTypeObject *type, PyObject *value, void *context)
abc.ABCMeta.__new__, so this function doesn't do anything
special to update subclasses.
*/
- int res = PyDict_SetItemString(type->tp_dict,
- "__abstractmethods__", value);
+ int res;
+ if (value != NULL) {
+ res = PyDict_SetItemString(type->tp_dict, "__abstractmethods__", value);
+ }
+ else {
+ res = PyDict_DelItemString(type->tp_dict, "__abstractmethods__");
+ if (res && PyErr_ExceptionMatches(PyExc_KeyError)) {
+ PyErr_Format(PyExc_AttributeError, "__abstractmethods__", value);
+ return -1;
+ }
+ }
if (res == 0) {
PyType_Modified(type);
if (value && PyObject_IsTrue(value)) {