diff options
author | Larry Hastings <larry@hastings.org> | 2016-06-13 03:26:28 (GMT) |
---|---|---|
committer | Larry Hastings <larry@hastings.org> | 2016-06-13 03:26:28 (GMT) |
commit | 29f963732166260420ffbdebe9eb8b98a009dc8c (patch) | |
tree | 17ad6530ee3b66b53647ab70bac08145dcd69783 /Modules/_functoolsmodule.c | |
parent | 6e9a96be9e24265638df8aa600e566b306a23a2b (diff) | |
parent | 1003b34c71d53ccb88ae2768aaba503ae6b5bc16 (diff) | |
download | cpython-29f963732166260420ffbdebe9eb8b98a009dc8c.zip cpython-29f963732166260420ffbdebe9eb8b98a009dc8c.tar.gz cpython-29f963732166260420ffbdebe9eb8b98a009dc8c.tar.bz2 |
Merge 3.5.2rc1 with current 3.5 branch.
Diffstat (limited to 'Modules/_functoolsmodule.c')
-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; } |