]> granicus.if.org Git - python/commitdiff
Fix SystemError in "raise" statement
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 18 Aug 2016 16:13:10 +0000 (18:13 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Thu, 18 Aug 2016 16:13:10 +0000 (18:13 +0200)
Issue #27558: Fix a SystemError in the implementation of "raise" statement.
In a brand new thread, raise a RuntimeError since there is no active
exception to reraise.

Patch written by Xiang Zhang.

Lib/test/test_threading.py
Misc/NEWS
Python/ceval.c

index 1c9c1ea534e76fd307dc763f60a2342365d3ad89..b63050982ab694e4ad8f7dbf53fd21c907dc6c0c 100644 (file)
@@ -1043,6 +1043,24 @@ class ThreadingExceptionTests(BaseTestCase):
         self.assertEqual(out, b'')
         self.assertNotIn("Unhandled exception", err.decode())
 
+    def test_bare_raise_in_brand_new_thread(self):
+        def bare_raise():
+            raise
+
+        class Issue27558(threading.Thread):
+            exc = None
+
+            def run(self):
+                try:
+                    bare_raise()
+                except Exception as exc:
+                    self.exc = exc
+
+        thread = Issue27558()
+        thread.start()
+        thread.join()
+        self.assertIsNotNone(thread.exc)
+        self.assertIsInstance(thread.exc, RuntimeError)
 
 class TimerTests(BaseTestCase):
 
index 0946553db70dd2e194a1cef5c31b0d7c5c5f3f5c..6c78a191e24675848d3a01fae2323a343a909562 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@ Release date: TBA
 Core and Builtins
 -----------------
 
+- Issue #27558: Fix a SystemError in the implementation of "raise" statement.
+  In a brand new thread, raise a RuntimeError since there is no active
+  exception to reraise. Patch written by Xiang Zhang.
+
 - Issue #27419: Standard __import__() no longer look up "__import__" in globals
   or builtins for importing submodules or "from import".  Fixed handling an
   error of non-string package name.
index c632488ec2c623048588aeea7439c8c8734f8b74..8e396fd2bc6adfa163b6f2796f5a4dec9b2f9b86 100644 (file)
@@ -4123,7 +4123,7 @@ do_raise(PyObject *exc, PyObject *cause)
         type = tstate->exc_type;
         value = tstate->exc_value;
         tb = tstate->exc_traceback;
-        if (type == Py_None) {
+        if (type == Py_None || type == NULL) {
             PyErr_SetString(PyExc_RuntimeError,
                             "No active exception to reraise");
             return 0;