File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -364,6 +364,17 @@ def pex(e):
364364 ])
365365
366366
367+ def test_exception_value_crash (self ):
368+ # There used to be a refcount error when the return value
369+ # stored in the StopIteration has a refcount of 1.
370+ def g1 ():
371+ yield from g2 ()
372+ def g2 ():
373+ yield "g2"
374+ return [42 ]
375+ self .assertEqual (list (g1 ()), ["g2" ])
376+
377+
367378 def test_generator_return_value (self ):
368379 """
369380 Test generator return value
Original file line number Diff line number Diff line change @@ -475,15 +475,16 @@ PyGen_FetchStopIterationValue(PyObject **pvalue) {
475475 Py_XDECREF (tb );
476476 if (ev ) {
477477 value = ((PyStopIterationObject * )ev )-> value ;
478+ Py_INCREF (value );
478479 Py_DECREF (ev );
479480 }
480481 } else if (PyErr_Occurred ()) {
481482 return -1 ;
482483 }
483484 if (value == NULL ) {
484485 value = Py_None ;
486+ Py_INCREF (value );
485487 }
486- Py_INCREF (value );
487488 * pvalue = value ;
488489 return 0 ;
489490}
You can’t perform that action at this time.
0 commit comments