Mercurial > cpython-lru_cache-weakref
diff Modules/_elementtree.c @ 83514:e022cc026afc
Revert c9674421d78e, leaving an additional comment
| author | Eli Bendersky <eliben@gmail.com> |
|---|---|
| date | Wed, 24 Apr 2013 05:34:07 -0700 |
| parents | c9674421d78e |
| children | b111ae4f83ef |
line wrap: on
line diff
--- a/Modules/_elementtree.c Wed Apr 24 01:51:42 2013 +0200 +++ b/Modules/_elementtree.c Wed Apr 24 05:34:07 2013 -0700 @@ -278,25 +278,30 @@ 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; }
