Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Remove the exc_value NULL check and add a failing test.
  • Loading branch information
cjerdonek committed May 3, 2020
commit 66aa6453d641cfce82108825f9e9e29654851cb8
19 changes: 19 additions & 0 deletions Lib/test/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,25 @@ def f():
context = cm.exception.__context__
self.assertEqual((type(context), context.args), (KeyError, ('a',)))

def test_throw_after_none_exc_type(self):
def g():
try:
raise KeyError
except KeyError:
pass

try:
yield
except Exception:
# This line causes a crash ("Segmentation fault (core dumped)")
# on e.g. Fedora 32.
raise RuntimeError

gen = g()
gen.send(None)
with self.assertRaises(RuntimeError) as cm:
gen.throw(ValueError)


class YieldFromTests(unittest.TestCase):
def test_generator_gi_yieldfrom(self):
Expand Down
6 changes: 2 additions & 4 deletions Objects/genobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,11 +512,9 @@ _gen_throw(PyGenObject *gen, int close_on_genexit,
}

PyErr_Restore(typ, val, tb);
/* XXX Should we also handle the case where exc_type is true and
exc_value is false? */
if (gen->gi_exc_state.exc_type && gen->gi_exc_state.exc_value) {
if (gen->gi_exc_state.exc_type) {
Py_INCREF(gen->gi_exc_state.exc_type);
Py_INCREF(gen->gi_exc_state.exc_value);
Py_XINCREF(gen->gi_exc_state.exc_value);
Py_XINCREF(gen->gi_exc_state.exc_traceback);
_PyErr_ChainExceptions(gen->gi_exc_state.exc_type,
gen->gi_exc_state.exc_value, gen->gi_exc_state.exc_traceback);
Expand Down