diff options
author | Lysandros Nikolaou <lisandrosnik@gmail.com> | 2020-04-24 13:51:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-24 13:51:09 (GMT) |
commit | 24ffe705c30e36c82940d75fd1454256634d0b3c (patch) | |
tree | 2efffce48d5a72d5d1e522427d31a0ebd88e36c1 /Tools | |
parent | e6f8abd500751a834b6fff4f107ecbd29f2184fe (diff) | |
download | cpython-24ffe705c30e36c82940d75fd1454256634d0b3c.zip cpython-24ffe705c30e36c82940d75fd1454256634d0b3c.tar.gz cpython-24ffe705c30e36c82940d75fd1454256634d0b3c.tar.bz2 |
bpo-40334: Rewrite test_c_parser to avoid memory leaks (GH-19694)
Previously every test was building an extension module and
loading it into sys.modules. The tearDown function was thus
not able to clean up correctly, resulting in memory leaks.
With this commit, every test function now builds the extension
module and runs the actual test code in a new process
(using assert_python_ok), so that sys.modules stays intact
and no memory gets leaked.
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/peg_generator/pegen/build.py | 1 | ||||
-rw-r--r-- | Tools/peg_generator/pegen/testutil.py | 4 |
2 files changed, 2 insertions, 3 deletions
diff --git a/Tools/peg_generator/pegen/build.py b/Tools/peg_generator/pegen/build.py index 0ecb370..0f5d73e 100644 --- a/Tools/peg_generator/pegen/build.py +++ b/Tools/peg_generator/pegen/build.py @@ -83,6 +83,7 @@ def compile_c_extension( cmd.inplace = True if build_dir: cmd.build_temp = build_dir + cmd.build_lib = build_dir cmd.ensure_finalized() cmd.run() diff --git a/Tools/peg_generator/pegen/testutil.py b/Tools/peg_generator/pegen/testutil.py index 3616eff..5a91862 100644 --- a/Tools/peg_generator/pegen/testutil.py +++ b/Tools/peg_generator/pegen/testutil.py @@ -92,9 +92,7 @@ def generate_parser_c_extension( with open(source, "w") as file: genr = CParserGenerator(grammar, file, debug=debug) genr.generate("parse.c") - extension_path = compile_c_extension(str(source), build_dir=str(path / "build")) - extension = import_file("parse", extension_path) - return extension + compile_c_extension(str(source), build_dir=str(path)) def print_memstats() -> bool: |