]> granicus.if.org Git - python/commitdiff
#17413: make sure settrace funcs get passed exception instances for 'value'.
authorR David Murray <rdmurray@bitdance.com>
Fri, 19 Apr 2013 16:56:57 +0000 (12:56 -0400)
committerR David Murray <rdmurray@bitdance.com>
Fri, 19 Apr 2013 16:56:57 +0000 (12:56 -0400)
Patch by Ingrid Cheung and Brendan McLoughlin.

Lib/test/test_sys_settrace.py
Misc/ACKS
Misc/NEWS
Python/ceval.c

index 63ae1b7180f18fd289a052d634215c27a5513add..f0b0b8290af72cfd7b5a6959a0f153087fd3ffae 100644 (file)
@@ -458,6 +458,29 @@ class RaisingTraceFuncTestCase(unittest.TestCase):
             self.fail("exception not propagated")
 
 
+    def test_exception_arguments(self):
+        def f():
+            x = 0
+            # this should raise an error
+            x.no_such_attr
+        def g(frame, event, arg):
+            if (event == 'exception'):
+                type, exception, trace = arg
+                self.assertIsInstance(exception, Exception)
+            return g
+
+        existing = sys.gettrace()
+        try:
+            sys.settrace(g)
+            try:
+                f()
+            except AttributeError:
+                # this is expected
+                pass
+        finally:
+            sys.settrace(existing)
+
+
 # 'Jump' tests: assigning to frame.f_lineno within a trace function
 # moves the execution position - it's how debuggers implement a Jump
 # command (aka. "Set next statement").
index a7837a4dd8c5449850fbbcfbf400b5e18639400f..fe279949c853eac9fa0f727e991e81d1de5dc3b0 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -208,6 +208,7 @@ David Chaum
 Nicolas Chauvat
 Jerry Chen
 Michael Chermside
+Ingrid Cheung
 Albert Chin-A-Young
 Adal Chiriliuc
 Matt Chisholm
@@ -786,6 +787,7 @@ Chris McDonough
 Greg McFarlane
 Alan McIntyre
 Michael McLay
+Brendan McLoughlin
 Mark Mc Mahon
 Gordon McMillan
 Andrew McNamara
index a67ce0becb66e0b590eb7016009f9d2539f73f47..dde410f615cc3c4a24b92d368d6cd52a672c70ab 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,10 @@ What's New in Python 3.3.2?
 Core and Builtins
 -----------------
 
+- Issue #17413: sys.settrace callbacks were being passed a string instead of an
+  exception instance for the 'value' element of the arg tuple if the exception
+  originated from C code; now an exception instance is always provided.
+
 - Issue #17782: Fix undefined behaviour on platforms where
   ``struct timespec``'s "tv_nsec" member is not a C long.
 
index 82bfcc612856b99caf378198e0f6e6d13e519e3f..f42784141d7f58a2bb651888f267122cea352e42 100644 (file)
@@ -3712,6 +3712,7 @@ call_exc_trace(Py_tracefunc func, PyObject *self, PyFrameObject *f)
         value = Py_None;
         Py_INCREF(value);
     }
+    PyErr_NormalizeException(&type, &value, &traceback);
     arg = PyTuple_Pack(3, type, value, traceback);
     if (arg == NULL) {
         PyErr_Restore(type, value, traceback);