summaryrefslogtreecommitdiffstats
path: root/Modules/_functoolsmodule.c
diff options
context:
space:
mode:
authorLarry Hastings <larry@hastings.org>2016-06-27 02:53:18 (GMT)
committerLarry Hastings <larry@hastings.org>2016-06-27 02:53:18 (GMT)
commit1b329e791ae3a3a2989f05e8c2019b67b4e1a7df (patch)
tree91e137c00f35f21a2c17b385f9746492b8347558 /Modules/_functoolsmodule.c
parent9bb200545970bb920c83124658cb89c7d295166d (diff)
parent1e957d145fa1fc05ca1fbb9f135ab162c939ae14 (diff)
downloadcpython-1b329e791ae3a3a2989f05e8c2019b67b4e1a7df.zip
cpython-1b329e791ae3a3a2989f05e8c2019b67b4e1a7df.tar.gz
cpython-1b329e791ae3a3a2989f05e8c2019b67b4e1a7df.tar.bz2
Merge.
Diffstat (limited to 'Modules/_functoolsmodule.c')
-rw-r--r--Modules/_functoolsmodule.c39
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;
}