SF bug #1242657: list(obj) can swallow KeyboardInterrupt

Fix over-aggressive PyErr_Clear().  The same code fragment appears in
various guises in list.extend(), map(), filter(), zip(), and internally
in PySequence_Tuple().
This commit is contained in:
Raymond Hettinger 2005-08-21 11:03:59 +00:00
parent b285974c00
commit a710b331da
4 changed files with 31 additions and 0 deletions

View file

@ -1401,6 +1401,11 @@ PySequence_Tuple(PyObject *v)
/* Guess result size and allocate space. */
n = PyObject_Size(v);
if (n < 0) {
if (!PyErr_ExceptionMatches(PyExc_TypeError) &&
!PyErr_ExceptionMatches(PyExc_AttributeError)) {
Py_DECREF(it);
return NULL;
}
PyErr_Clear();
n = 10; /* arbitrary */
}

View file

@ -777,6 +777,11 @@ listextend(PyListObject *self, PyObject *b)
/* Guess a result list size. */
n = PyObject_Size(b);
if (n < 0) {
if (!PyErr_ExceptionMatches(PyExc_TypeError) &&
!PyErr_ExceptionMatches(PyExc_AttributeError)) {
Py_DECREF(it);
return NULL;
}
PyErr_Clear();
n = 8; /* arbitrary */
}