cpython: 15c80f63ea1c (original) (raw)
Mercurial > cpython
changeset 95810:15c80f63ea1c 3.4
Issue #23996: Avoid a crash when a delegated generator raises an unnormalized StopIteration exception. Patch by Stefan Behnel. [#23996]
Antoine Pitrou solipsis@pitrou.net | |
---|---|
date | Sun, 26 Apr 2015 18:46:40 +0200 |
parents | bd8b99034121 |
children | 9d0c6c66b0ac ec6ed10d611e |
files | Misc/NEWS Objects/genobject.c |
diffstat | 2 files changed, 25 insertions(+), 5 deletions(-)[+] [-] Misc/NEWS 3 Objects/genobject.c 27 |
line wrap: on
line diff
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Release date: tba Core and Builtins ----------------- +- Issue #23996: Avoid a crash when a delegated generator raises an
- Issue #24022: Fix tokenizer crash when processing undecodable source code.
- Issue #23309: Avoid a deadlock at shutdown if a daemon thread is aborted
--- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -396,13 +396,30 @@ int if (PyErr_ExceptionMatches(PyExc_StopIteration)) { PyErr_Fetch(&et, &ev, &tb);
if (ev) {[](#l2.7)
/* exception will usually be normalised already */[](#l2.8)
if (Py_TYPE(ev) == (PyTypeObject *) et[](#l2.9)
|| PyObject_IsInstance(ev, PyExc_StopIteration)) {[](#l2.10)
value = ((PyStopIterationObject *)ev)->value;[](#l2.11)
Py_INCREF(value);[](#l2.12)
Py_DECREF(ev);[](#l2.13)
} else if (et == PyExc_StopIteration) {[](#l2.14)
/* avoid normalisation and take ev as value */[](#l2.15)
value = ev;[](#l2.16)
} else {[](#l2.17)
/* normalisation required */[](#l2.18)
PyErr_NormalizeException(&et, &ev, &tb);[](#l2.19)
if (!PyObject_IsInstance(ev, PyExc_StopIteration)) {[](#l2.20)
PyErr_Restore(et, ev, tb);[](#l2.21)
return -1;[](#l2.22)
}[](#l2.23)
value = ((PyStopIterationObject *)ev)->value;[](#l2.24)
Py_INCREF(value);[](#l2.25)
Py_DECREF(ev);[](#l2.26)
}[](#l2.27)
}[](#l2.28) Py_XDECREF(et);[](#l2.29) Py_XDECREF(tb);[](#l2.30)