From d4864c61e3e27e337762dc45e504977299bd5b46 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 9 Jan 2018 21:54:52 +0200 Subject: [PATCH] bpo-24340: Fix estimation of the code stack size. (#5076) --- Lib/test/test_compile.py | 291 ++- Lib/test/test_dis.py | 16 +- .../2018-01-01-21-59-31.bpo-24340.hmKBvg.rst | 1 + Python/compile.c | 129 +- Python/importlib.h | 42 +- Python/importlib_external.h | 2192 ++++++++--------- 6 files changed, 1507 insertions(+), 1164 deletions(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2018-01-01-21-59-31.bpo-24340.hmKBvg.rst diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index ae3043af0bd..29aa362590f 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -672,7 +672,7 @@ if 1: compile("42", PathLike("test_compile_pathlike"), "single") -class TestStackSize(unittest.TestCase): +class TestExpressionStackSize(unittest.TestCase): # These tests check that the computed stack size for a code object # stays within reasonable bounds (see issue #21523 for an example # dysfunction). @@ -710,5 +710,294 @@ class TestStackSize(unittest.TestCase): self.check_stack_size(code) +class TestStackSizeStability(unittest.TestCase): + # Check that repeating certain snippets doesn't increase the stack size + # beyond what a single snippet requires. + + def check_stack_size(self, snippet, async_=False): + def compile_snippet(i): + ns = {} + script = """def func():\n""" + i * snippet + if async_: + script = "async " + script + code = compile(script, "