Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Checkins

cpython (3.2): prevert ast errors from being normalized before ast error finish is called

 

 

Python checkins RSS feed   Index | Next | Previous | View Threaded


python-checkins at python

Sep 2, 2012, 11:25 AM

Post #1 of 1 (42 views)
Permalink
cpython (3.2): prevert ast errors from being normalized before ast error finish is called

http://hg.python.org/cpython/rev/0db75a55145a
changeset: 78835:0db75a55145a
branch: 3.2
parent: 78825:aef4a2ba3210
user: Benjamin Peterson <benjamin [at] python>
date: Sun Sep 02 14:23:15 2012 -0400
summary:
prevert ast errors from being normalized before ast_error_finish is called (closes #15846)

files:
Lib/test/test_ast.py | 6 ++++++
Misc/NEWS | 3 +++
Python/ast.c | 8 ++++++++
3 files changed, 17 insertions(+), 0 deletions(-)


diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -386,6 +386,12 @@
b = compile('foo(1 + 1)', '<unknown>', 'exec', ast.PyCF_ONLY_AST)
self.assertEqual(ast.dump(a), ast.dump(b))

+ def test_parse_in_error(self):
+ try:
+ 1/0
+ except Exception:
+ self.assertRaises(SyntaxError, ast.parse, r"'\U'")
+
def test_dump(self):
node = ast.parse('spam(eggs, "and cheese")')
self.assertEqual(ast.dump(node),
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
Core and Builtins
-----------------

+- Issue #15846: Fix SystemError which happened when using ast.parse in an
+ exception handler on code with syntax errors.
+
- Issue #15761: Fix crash when PYTHONEXECUTABLE is set on Mac OS X.

- Issue #15801: Make sure mappings passed to '%' formatting are actually
diff --git a/Python/ast.c b/Python/ast.c
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -92,7 +92,15 @@
PyObject *u = Py_BuildValue("zii", errstr, LINENO(n), n->n_col_offset);
if (!u)
return 0;
+ /*
+ * Prevent the error from being chained. PyErr_SetObject will normalize the
+ * exception in order to chain it. ast_error_finish, however, requires the
+ * error not to be normalized.
+ */
+ PyObject *save = PyThreadState_GET()->exc_value;
+ PyThreadState_GET()->exc_value = NULL;
PyErr_SetObject(PyExc_SyntaxError, u);
+ PyThreadState_GET()->exc_value = save;
Py_DECREF(u);
return 0;
}

--
Repository URL: http://hg.python.org/cpython

Python checkins RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.