mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
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.
This commit is contained in:
parent
e6f8abd500
commit
24ffe705c3
3 changed files with 146 additions and 83 deletions
|
@ -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()
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue