diff options
author | Eli Bendersky <eliben@gmail.com> | 2013-04-24 12:34:07 (GMT) |
---|---|---|
committer | Eli Bendersky <eliben@gmail.com> | 2013-04-24 12:34:07 (GMT) |
commit | 45f3d2fff08af8b13a52f72d2342934253e3690d (patch) | |
tree | 936d6fa116ba17021efd9895e0b5b6d2f0cba720 /Modules | |
parent | 06d3abbff3fee303e99ef4bd01cb66a505d291ba (diff) | |
download | cpython-45f3d2fff08af8b13a52f72d2342934253e3690d.zip cpython-45f3d2fff08af8b13a52f72d2342934253e3690d.tar.gz cpython-45f3d2fff08af8b13a52f72d2342934253e3690d.tar.bz2 |
Revert c9674421d78e, leaving an additional comment
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_elementtree.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 5a1ed8c..f5b0914 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -278,25 +278,30 @@ element_new(PyTypeObject *type, PyObject *args, PyObject *kwds) static PyObject* get_attrib_from_keywords(PyObject *kwds) { - const char* ATTRIB_KEY = "attrib"; - PyObject *attrib = PyDict_GetItemString(kwds, ATTRIB_KEY); + PyObject *attrib_str = PyUnicode_FromString("attrib"); + PyObject *attrib = PyDict_GetItem(kwds, attrib_str); if (attrib) { /* If attrib was found in kwds, copy its value and remove it from * kwds */ if (!PyDict_Check(attrib)) { + Py_DECREF(attrib_str); PyErr_Format(PyExc_TypeError, "attrib must be dict, not %.100s", Py_TYPE(attrib)->tp_name); return NULL; } attrib = PyDict_Copy(attrib); - PyDict_DelItemString(kwds, ATTRIB_KEY); + PyDict_DelItem(kwds, attrib_str); } else { attrib = PyDict_New(); } - assert(attrib); - PyDict_Update(attrib, kwds); + + Py_DECREF(attrib_str); + + /* attrib can be NULL if PyDict_New failed */ + if (attrib) + PyDict_Update(attrib, kwds); return attrib; } |