Commit 45f3d2ff authored by Eli Bendersky's avatar Eli Bendersky

Revert c9674421d78e, leaving an additional comment

parent 06d3abbf
...@@ -278,25 +278,30 @@ element_new(PyTypeObject *type, PyObject *args, PyObject *kwds) ...@@ -278,25 +278,30 @@ element_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static PyObject* static PyObject*
get_attrib_from_keywords(PyObject *kwds) get_attrib_from_keywords(PyObject *kwds)
{ {
const char* ATTRIB_KEY = "attrib"; PyObject *attrib_str = PyUnicode_FromString("attrib");
PyObject *attrib = PyDict_GetItemString(kwds, ATTRIB_KEY); PyObject *attrib = PyDict_GetItem(kwds, attrib_str);
if (attrib) { if (attrib) {
/* If attrib was found in kwds, copy its value and remove it from /* If attrib was found in kwds, copy its value and remove it from
* kwds * kwds
*/ */
if (!PyDict_Check(attrib)) { if (!PyDict_Check(attrib)) {
Py_DECREF(attrib_str);
PyErr_Format(PyExc_TypeError, "attrib must be dict, not %.100s", PyErr_Format(PyExc_TypeError, "attrib must be dict, not %.100s",
Py_TYPE(attrib)->tp_name); Py_TYPE(attrib)->tp_name);
return NULL; return NULL;
} }
attrib = PyDict_Copy(attrib); attrib = PyDict_Copy(attrib);
PyDict_DelItemString(kwds, ATTRIB_KEY); PyDict_DelItem(kwds, attrib_str);
} else { } else {
attrib = PyDict_New(); 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; return attrib;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment