bpo-29800: Fix crashes in partial.__repr__ if the keys of partial.keywords are not strings (#649)

This commit is contained in:
Michael Seifert 2017-03-15 06:26:33 +01:00 committed by Serhiy Storchaka
parent 024b4fdc4a
commit 6c3d527468
4 changed files with 34 additions and 1 deletions

View file

@ -297,8 +297,11 @@ partial_repr(partialobject *pto)
/* Pack keyword arguments */
assert (PyDict_Check(pto->kw));
for (i = 0; PyDict_Next(pto->kw, &i, &key, &value);) {
Py_SETREF(arglist, PyUnicode_FromFormat("%U, %U=%R", arglist,
/* Prevent key.__str__ from deleting the value. */
Py_INCREF(value);
Py_SETREF(arglist, PyUnicode_FromFormat("%U, %S=%R", arglist,
key, value));
Py_DECREF(value);
if (arglist == NULL)
goto done;
}