summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-09-02 18:24:44 (GMT)
committerBenjamin Peterson <benjamin@python.org>2012-09-02 18:24:44 (GMT)
commitc7f447c89fdef7106089f16ea46d5f9341fa0858 (patch)
tree42cf788e63fdfae5f3442dde269b963473c5d611
parenta3b84fb2f9d555e9efac556ea24f4ad75a54b4c8 (diff)
parent2e2c903700991aa9f7e96d7a7fdaed3628dc7e1e (diff)
downloadcpython-c7f447c89fdef7106089f16ea46d5f9341fa0858.zip
cpython-c7f447c89fdef7106089f16ea46d5f9341fa0858.tar.gz
cpython-c7f447c89fdef7106089f16ea46d5f9341fa0858.tar.bz2
merge 3.2 (#15846)
-rw-r--r--Lib/test/test_ast.py6
-rw-r--r--Misc/NEWS3
-rw-r--r--Python/ast.c8
3 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index aa08166..413613f 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -407,6 +407,12 @@ class ASTHelpers_Test(unittest.TestCase):
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
index 2af87ee..41732ef 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ Core and Builtins
- Issue #15839: Convert SystemErrors in super() to RuntimeErrors.
+- Issue #15846: Fix SystemError which happened when using ast.parse in an
+ exception handler on code with syntax errors.
+
- Issue #15801: Make sure mappings passed to '%' formatting are actually
subscriptable.
diff --git a/Python/ast.c b/Python/ast.c
index fc6c565..5366dda 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -588,7 +588,15 @@ ast_error(const node *n, const char *errstr)
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;
}