diff options
author | Raymond Hettinger <python@rcn.com> | 2003-11-28 21:43:02 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2003-11-28 21:43:02 (GMT) |
commit | 37e136373e0d9ab3bdf25ecd9c42b86281ed21d3 (patch) | |
tree | fc0caf815fcf3da64a1a031065f1ee3f9c3f27c4 /Objects/listobject.c | |
parent | b3105911697d57098e9770078d89475f83274344 (diff) | |
download | cpython-37e136373e0d9ab3bdf25ecd9c42b86281ed21d3.zip cpython-37e136373e0d9ab3bdf25ecd9c42b86281ed21d3.tar.gz cpython-37e136373e0d9ab3bdf25ecd9c42b86281ed21d3.tar.bz2 |
Make sure the list.sort's decorate step unwinds itself before returning
an exception raised by the key function.
(Suggested by Michael Hudson.)
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r-- | Objects/listobject.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index 3782c3b..95aa484 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -1876,8 +1876,15 @@ listsort(PyListObject *self, PyObject *args, PyObject *kwds) value = PyList_GET_ITEM(self, i); key = PyObject_CallFunctionObjArgs(keyfunc, value, NULL); - if (key == NULL) + if (key == NULL) { + for (i=i-1 ; i>=0 ; i--) { + kvpair = PyList_GET_ITEM(self, i); + value = sortwrapper_getvalue(kvpair); + PyList_SET_ITEM(self, i, value); + Py_DECREF(kvpair); + } goto dsu_fail; + } kvpair = build_sortwrapper(key, value); if (kvpair == NULL) goto dsu_fail; @@ -1885,7 +1892,7 @@ listsort(PyListObject *self, PyObject *args, PyObject *kwds) } } - /* Reverse sort stability achieved by initialially reversing the list, + /* Reverse sort stability achieved by initially reversing the list, applying a stable forward sort, then reversing the final result. */ if (reverse && self->ob_size > 1) reverse_slice(self->ob_item, self->ob_item + self->ob_size); |