[Python-checkins] cpython (3.3): #17413: make sure settrace funcs get passed exception instances for 'value'.
r.david.murray
python-checkins at python.org
Fri Apr 19 18:58:27 CEST 2013
http://hg.python.org/cpython/rev/d18df4c90515
changeset: 83455:d18df4c90515
branch: 3.3
parent: 83453:45e5b4df4e3e
user: R David Murray <rdmurray at bitdance.com>
date: Fri Apr 19 12:56:57 2013 -0400
summary:
#17413: make sure settrace funcs get passed exception instances for 'value'.
Patch by Ingrid Cheung and Brendan McLoughlin.
files:
Lib/test/test_sys_settrace.py | 23 +++++++++++++++++++++++
Misc/ACKS | 2 ++
Misc/NEWS | 4 ++++
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
--- a/Lib/test/test_sys_settrace.py
+++ b/Lib/test/test_sys_settrace.py
@@ -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 --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -208,6 +208,7 @@
Nicolas Chauvat
Jerry Chen
Michael Chermside
+Ingrid Cheung
Albert Chin-A-Young
Adal Chiriliuc
Matt Chisholm
@@ -786,6 +787,7 @@
Greg McFarlane
Alan McIntyre
Michael McLay
+Brendan McLoughlin
Mark Mc Mahon
Gordon McMillan
Andrew McNamara
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,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 --git a/Python/ceval.c b/Python/ceval.c
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -3712,6 +3712,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);
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list