File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ Release date: tba
1010Core and Builtins
1111-----------------
1212
13+ - Issue #23996: Avoid a crash when a delegated generator raises an
14+ unnormalized StopIteration exception. Patch by Stefan Behnel.
15+
1316- Issue #24022: Fix tokenizer crash when processing undecodable source code.
1417
1518- Issue #23309: Avoid a deadlock at shutdown if a daemon thread is aborted
Original file line number Diff line number Diff line change @@ -396,13 +396,30 @@ _PyGen_FetchStopIterationValue(PyObject **pvalue) {
396396
397397 if (PyErr_ExceptionMatches (PyExc_StopIteration )) {
398398 PyErr_Fetch (& et , & ev , & tb );
399- Py_XDECREF (et );
400- Py_XDECREF (tb );
401399 if (ev ) {
402- value = ((PyStopIterationObject * )ev )-> value ;
403- Py_INCREF (value );
404- Py_DECREF (ev );
400+ /* exception will usually be normalised already */
401+ if (Py_TYPE (ev ) == (PyTypeObject * ) et
402+ || PyObject_IsInstance (ev , PyExc_StopIteration )) {
403+ value = ((PyStopIterationObject * )ev )-> value ;
404+ Py_INCREF (value );
405+ Py_DECREF (ev );
406+ } else if (et == PyExc_StopIteration ) {
407+ /* avoid normalisation and take ev as value */
408+ value = ev ;
409+ } else {
410+ /* normalisation required */
411+ PyErr_NormalizeException (& et , & ev , & tb );
412+ if (!PyObject_IsInstance (ev , PyExc_StopIteration )) {
413+ PyErr_Restore (et , ev , tb );
414+ return -1 ;
415+ }
416+ value = ((PyStopIterationObject * )ev )-> value ;
417+ Py_INCREF (value );
418+ Py_DECREF (ev );
419+ }
405420 }
421+ Py_XDECREF (et );
422+ Py_XDECREF (tb );
406423 } else if (PyErr_Occurred ()) {
407424 return -1 ;
408425 }
You can’t perform that action at this time.
0 commit comments