diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-12 08:44:06 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-12 08:44:06 (GMT) |
commit | 179f960d47dc9f2c18e5b535db63fb70b21fc3ea (patch) | |
tree | aa4988b55963881faaab7671a4bd0609cd5dc32b /Modules | |
parent | cbe6142135667f045a21264619a61d74a9a1ff67 (diff) | |
download | cpython-179f960d47dc9f2c18e5b535db63fb70b21fc3ea.zip cpython-179f960d47dc9f2c18e5b535db63fb70b21fc3ea.tar.gz cpython-179f960d47dc9f2c18e5b535db63fb70b21fc3ea.tar.bz2 |
Issue #25455: Fixed a crash in repr of recursive functools.partial objects.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_functoolsmodule.c | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index 1aa4571..d785c49 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -203,40 +203,45 @@ static PyGetSetDef partial_getsetlist[] = { static PyObject * partial_repr(partialobject *pto) { - PyObject *result; + PyObject *result = NULL; PyObject *arglist; - PyObject *tmp; Py_ssize_t i, n; PyObject *key, *value; + int status; - arglist = PyUnicode_FromString(""); - if (arglist == NULL) { - return NULL; + status = Py_ReprEnter((PyObject *)pto); + if (status != 0) { + if (status < 0) + return NULL; + return PyUnicode_FromFormat("%s(...)", Py_TYPE(pto)->tp_name); } + + arglist = PyUnicode_FromString(""); + if (arglist == NULL) + goto done; /* Pack positional arguments */ assert (PyTuple_Check(pto->args)); n = PyTuple_GET_SIZE(pto->args); for (i = 0; i < n; i++) { - tmp = PyUnicode_FromFormat("%U, %R", arglist, - PyTuple_GET_ITEM(pto->args, i)); - Py_DECREF(arglist); - if (tmp == NULL) - return NULL; - arglist = tmp; + Py_SETREF(arglist, PyUnicode_FromFormat("%U, %R", arglist, + PyTuple_GET_ITEM(pto->args, i))); + if (arglist == NULL) + goto done; } /* Pack keyword arguments */ assert (PyDict_Check(pto->kw)); for (i = 0; PyDict_Next(pto->kw, &i, &key, &value);) { - tmp = PyUnicode_FromFormat("%U, %U=%R", arglist, - key, value); - Py_DECREF(arglist); - if (tmp == NULL) - return NULL; - arglist = tmp; + Py_SETREF(arglist, PyUnicode_FromFormat("%U, %U=%R", arglist, + key, value)); + if (arglist == NULL) + goto done; } result = PyUnicode_FromFormat("%s(%R%U)", Py_TYPE(pto)->tp_name, pto->fn, arglist); Py_DECREF(arglist); + + done: + Py_ReprLeave((PyObject *)pto); return result; } |