changeset: 83456:6297fcddf912 parent: 83454:c52d692d9176 parent: 83455:d18df4c90515 user: R David Murray date: Fri Apr 19 12:57:54 2013 -0400 files: Misc/ACKS Misc/NEWS Python/ceval.c description: Merge #17413: make sure settrace funcs get passed exception instances for 'value'. Patch by Ingrid Cheung and Brendan McLoughlin. diff -r c52d692d9176 -r 6297fcddf912 Lib/test/test_sys_settrace.py --- a/Lib/test/test_sys_settrace.py Fri Apr 19 11:32:54 2013 -0400 +++ b/Lib/test/test_sys_settrace.py Fri Apr 19 12:57:54 2013 -0400 @@ -458,6 +458,29 @@ 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"). diff -r c52d692d9176 -r 6297fcddf912 Misc/ACKS --- a/Misc/ACKS Fri Apr 19 11:32:54 2013 -0400 +++ b/Misc/ACKS Fri Apr 19 12:57:54 2013 -0400 @@ -211,6 +211,7 @@ Nicolas Chauvat Jerry Chen Michael Chermside +Ingrid Cheung Albert Chin-A-Young Adal Chiriliuc Matt Chisholm @@ -802,6 +803,7 @@ Greg McFarlane Alan McIntyre Michael McLay +Brendan McLoughlin Mark Mc Mahon Gordon McMillan Andrew McNamara diff -r c52d692d9176 -r 6297fcddf912 Misc/NEWS --- a/Misc/NEWS Fri Apr 19 11:32:54 2013 -0400 +++ b/Misc/NEWS Fri Apr 19 12:57:54 2013 -0400 @@ -10,6 +10,10 @@ 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 -r c52d692d9176 -r 6297fcddf912 Python/ceval.c --- a/Python/ceval.c Fri Apr 19 11:32:54 2013 -0400 +++ b/Python/ceval.c Fri Apr 19 12:57:54 2013 -0400 @@ -3793,6 +3793,7 @@ 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);