diff options
author | Chris Jerdonek <chris.jerdonek@gmail.com> | 2020-05-03 07:07:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-03 07:07:57 (GMT) |
commit | 21893fbb74e8fde2931fbed9b511e2a41362b1ab (patch) | |
tree | daa9478ff24df319924478b9de7a435aee101b04 /Lib/test/test_generators.py | |
parent | 0400a7f2f8abec8d441990e951cc25f69a2a4036 (diff) | |
download | cpython-21893fbb74e8fde2931fbed9b511e2a41362b1ab.zip cpython-21893fbb74e8fde2931fbed9b511e2a41362b1ab.tar.gz cpython-21893fbb74e8fde2931fbed9b511e2a41362b1ab.tar.bz2 |
bpo-29587: allow chaining NULL exceptions in _gen_throw() (GH-19877)
This is a follow-up to GH-19823 that removes the check that the
exception value isn't NULL, prior to calling _PyErr_ChainExceptions().
This enables implicit exception chaining for gen.throw() in more
circumstances.
The commit also adds a test that a particular code snippet involving
gen.throw() doesn't crash. The test shows why the new
`gi_exc_state.exc_type != Py_None` check that was added is necessary.
Without the new check, the code snippet (as well as a number of other
tests) crashes on certain platforms (e.g. Fedora but not Mac).
Diffstat (limited to 'Lib/test/test_generators.py')
-rw-r--r-- | Lib/test/test_generators.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py index 4d96f44..5824ecd 100644 --- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -332,6 +332,26 @@ class GeneratorThrowTest(unittest.TestCase): 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: + # Without the `gi_exc_state.exc_type != Py_None` in + # _gen_throw(), this line was causing 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): |