diff options
author | R David Murray <rdmurray@bitdance.com> | 2013-04-19 16:57:54 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2013-04-19 16:57:54 (GMT) |
commit | f097f175dd3385e6e43842680932b32cbc50365d (patch) | |
tree | 9f0792a864e03c4e1ed58bb4f0819bfb40be2d0f | |
parent | 24aa15959b0f8b540dc4c2eacf31755e506ab3b5 (diff) | |
parent | 3583761bcd3ebc85207f555017e06f2007cd0db0 (diff) | |
download | cpython-f097f175dd3385e6e43842680932b32cbc50365d.zip cpython-f097f175dd3385e6e43842680932b32cbc50365d.tar.gz cpython-f097f175dd3385e6e43842680932b32cbc50365d.tar.bz2 |
Merge #17413: make sure settrace funcs get passed exception instances for 'value'.
Patch by Ingrid Cheung and Brendan McLoughlin.
-rw-r--r-- | Lib/test/test_sys_settrace.py | 23 | ||||
-rw-r--r-- | Misc/ACKS | 2 | ||||
-rw-r--r-- | Misc/NEWS | 4 | ||||
-rw-r--r-- | Python/ceval.c | 1 |
4 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py index 63ae1b7..f0b0b82 100644 --- a/Lib/test/test_sys_settrace.py +++ b/Lib/test/test_sys_settrace.py @@ -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"). @@ -211,6 +211,7 @@ David Chaum Nicolas Chauvat Jerry Chen Michael Chermside +Ingrid Cheung Albert Chin-A-Young Adal Chiriliuc Matt Chisholm @@ -802,6 +803,7 @@ Chris McDonough Greg McFarlane Alan McIntyre Michael McLay +Brendan McLoughlin Mark Mc Mahon Gordon McMillan Andrew McNamara @@ -10,6 +10,10 @@ What's New in Python 3.4.0 Alpha 1? 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. diff --git a/Python/ceval.c b/Python/ceval.c index 6132e16..138c75d 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -3793,6 +3793,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); |