diff options
author | Hynek Schlawack <hs@ox.cx> | 2012-11-07 08:41:28 (GMT) |
---|---|---|
committer | Hynek Schlawack <hs@ox.cx> | 2012-11-07 08:41:28 (GMT) |
commit | b271b3e18820eaaf8f6a7a41f462451d98a0ad2c (patch) | |
tree | b196d40272ce896432ffac441fe774e3ff72fdb9 /Lib/test | |
parent | 6cad3712b316a9b3436e6ee455909f655404d236 (diff) | |
download | cpython-b271b3e18820eaaf8f6a7a41f462451d98a0ad2c.zip cpython-b271b3e18820eaaf8f6a7a41f462451d98a0ad2c.tar.gz cpython-b271b3e18820eaaf8f6a7a41f462451d98a0ad2c.tar.bz2 |
Issue #15001: fix segfault on "del sys.modules['__main__']"
Patch by Victor Stinner.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_cmd_line.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py index 05e29d4..d12caeb 100644 --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -2,9 +2,12 @@ # All tests are executed with environment variables ignored # See test_cmd_line_script.py for testing of script execution -import test.test_support, unittest +import test.test_support import sys -from test.script_helper import spawn_python, kill_python, python_exit_code +import unittest +from test.script_helper import ( + assert_python_ok, spawn_python, kill_python, python_exit_code +) class CmdLineTest(unittest.TestCase): @@ -101,6 +104,18 @@ class CmdLineTest(unittest.TestCase): data = self.start_python('-R', '-c', code) self.assertTrue('hash_randomization=1' in data) + def test_del___main__(self): + # Issue #15001: PyRun_SimpleFileExFlags() did crash because it kept a + # borrowed reference to the dict of __main__ module and later modify + # the dict whereas the module was destroyed + filename = test.test_support.TESTFN + self.addCleanup(test.test_support.unlink, filename) + with open(filename, "w") as script: + print >>script, "import sys" + print >>script, "del sys.modules['__main__']" + assert_python_ok(filename) + + def test_main(): test.test_support.run_unittest(CmdLineTest) test.test_support.reap_children() |