mirror of
https://github.com/python/cpython.git
synced 2025-07-12 22:05:16 +00:00
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:
parent
b285974c00
commit
a710b331da
4 changed files with 31 additions and 0 deletions
|
@ -223,6 +223,10 @@ builtin_filter(PyObject *self, PyObject *args)
|
|||
/* Guess a result list size. */
|
||||
len = PyObject_Size(seq);
|
||||
if (len < 0) {
|
||||
if (!PyErr_ExceptionMatches(PyExc_TypeError) &&
|
||||
!PyErr_ExceptionMatches(PyExc_AttributeError)) {
|
||||
goto Fail_it;
|
||||
}
|
||||
PyErr_Clear();
|
||||
len = 8; /* arbitrary */
|
||||
}
|
||||
|
@ -864,6 +868,10 @@ builtin_map(PyObject *self, PyObject *args)
|
|||
/* Update len. */
|
||||
curlen = PyObject_Size(curseq);
|
||||
if (curlen < 0) {
|
||||
if (!PyErr_ExceptionMatches(PyExc_TypeError) &&
|
||||
!PyErr_ExceptionMatches(PyExc_AttributeError)) {
|
||||
goto Fail_2;
|
||||
}
|
||||
PyErr_Clear();
|
||||
curlen = 8; /* arbitrary */
|
||||
}
|
||||
|
@ -2097,6 +2105,10 @@ builtin_zip(PyObject *self, PyObject *args)
|
|||
PyObject *item = PyTuple_GET_ITEM(args, i);
|
||||
int thislen = PyObject_Size(item);
|
||||
if (thislen < 0) {
|
||||
if (!PyErr_ExceptionMatches(PyExc_TypeError) &&
|
||||
!PyErr_ExceptionMatches(PyExc_AttributeError)) {
|
||||
return NULL;
|
||||
}
|
||||
PyErr_Clear();
|
||||
len = -1;
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue