mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
Issue #25455: Fixed a crash in repr of recursive functools.partial objects.
This commit is contained in:
parent
cbe6142135
commit
179f960d47
3 changed files with 61 additions and 18 deletions
|
|
@ -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;
|
||||
|
||||
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) {
|
||||
return NULL;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue