summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_builtin.py11
-rw-r--r--Python/pythonrun.c7
2 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 111090c..7244aff 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -448,6 +448,17 @@ class BuiltinTest(unittest.TestCase):
del l['__builtins__']
self.assertEqual((g, l), ({'a': 1}, {'b': 2}))
+ def test_exec_redirected(self):
+ savestdout = sys.stdout
+ sys.stdout = None # Whatever that cannot flush()
+ try:
+ # Used to raise SystemError('error return without exception set')
+ exec('a')
+ except NameError:
+ pass
+ finally:
+ sys.stdout = savestdout
+
def test_filter(self):
self.assertEqual(list(filter(lambda c: 'a' <= c <= 'z', 'Hello World')), list('elloorld'))
self.assertEqual(list(filter(None, [1, 'hello', [], [3], '', None, 9, 0])), [1, 'hello', [3], 9])
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 74e3430..3207fb8 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1467,6 +1467,11 @@ static void
flush_io(void)
{
PyObject *f, *r;
+ PyObject *type, *value, *traceback;
+
+ /* Save the current exception */
+ PyErr_Fetch(&type, &value, &traceback);
+
f = PySys_GetObject("stderr");
if (f != NULL) {
r = PyObject_CallMethod(f, "flush", "");
@@ -1483,6 +1488,8 @@ flush_io(void)
else
PyErr_Clear();
}
+
+ PyErr_Restore(type, value, traceback);
}
static PyObject *