diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-08-15 21:16:51 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-08-15 21:16:51 (GMT) |
commit | c5bef75c77af414c2f6c5901b6838d3071313bc7 (patch) | |
tree | ec54e539c09e4c9b6fc8963258fef4c6484e5573 /Objects | |
parent | 4ffe9a064022b973ab152d108b13c470af486a74 (diff) | |
download | cpython-c5bef75c77af414c2f6c5901b6838d3071313bc7.zip cpython-c5bef75c77af414c2f6c5901b6838d3071313bc7.tar.gz cpython-c5bef75c77af414c2f6c5901b6838d3071313bc7.tar.bz2 |
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Patch by Serhiy Storchaka.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/typeobject.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 3bb0459..77cba70 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -327,11 +327,15 @@ 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; + int abstract, res; if (value != NULL) { + abstract = PyObject_IsTrue(value); + if (abstract < 0) + return -1; res = PyDict_SetItemString(type->tp_dict, "__abstractmethods__", value); } else { + abstract = 0; res = PyDict_DelItemString(type->tp_dict, "__abstractmethods__"); if (res && PyErr_ExceptionMatches(PyExc_KeyError)) { PyErr_SetString(PyExc_AttributeError, "__abstractmethods__"); @@ -340,12 +344,10 @@ type_set_abstractmethods(PyTypeObject *type, PyObject *value, void *context) } if (res == 0) { PyType_Modified(type); - if (value && PyObject_IsTrue(value)) { + if (abstract) type->tp_flags |= Py_TPFLAGS_IS_ABSTRACT; - } - else { + else type->tp_flags &= ~Py_TPFLAGS_IS_ABSTRACT; - } } return res; } |