diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-12-15 12:11:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-15 12:11:43 (GMT) |
commit | 2e3f5701858d1fc04caedefdd9a8ea43810270d2 (patch) | |
tree | e1c92b967a8f0935f65139338f4b7c170609c46e /Lib | |
parent | a5552f023e1d8cbafee1e51d316cc581deb2295f (diff) | |
download | cpython-2e3f5701858d1fc04caedefdd9a8ea43810270d2.zip cpython-2e3f5701858d1fc04caedefdd9a8ea43810270d2.tar.gz cpython-2e3f5701858d1fc04caedefdd9a8ea43810270d2.tar.bz2 |
bpo-30416: Protect the optimizer during constant folding. (#4860)
It no longer spends much time doing complex calculations and no
longer consumes much memory for creating large constants that will
be dropped later.
This fixes also bpo-21074.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_memoryio.py | 3 | ||||
-rw-r--r-- | Lib/test/test_peepholer.py | 9 |
2 files changed, 10 insertions, 2 deletions
diff --git a/Lib/test/test_memoryio.py b/Lib/test/test_memoryio.py index e16c57e..cd2faba 100644 --- a/Lib/test/test_memoryio.py +++ b/Lib/test/test_memoryio.py @@ -759,7 +759,8 @@ class CBytesIOTest(PyBytesIOTest): check = self.check_sizeof self.assertEqual(object.__sizeof__(io.BytesIO()), basesize) check(io.BytesIO(), basesize ) - check(io.BytesIO(b'a' * 1000), basesize + sys.getsizeof(b'a' * 1000)) + n = 1000 # use a variable to prevent constant folding + check(io.BytesIO(b'a' * n), basesize + sys.getsizeof(b'a' * n)) # Various tests of copy-on-write behaviour for BytesIO. diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py index efc0afe..0cc1e92 100644 --- a/Lib/test/test_peepholer.py +++ b/Lib/test/test_peepholer.py @@ -175,8 +175,15 @@ class TestTranforms(BytecodeTestCase): self.assertInBytecode(code, 'LOAD_CONST', 'b') # Verify that large sequences do not result from folding - code = compile('a="x"*1000', '', 'single') + code = compile('a="x"*10000', '', 'single') + self.assertInBytecode(code, 'LOAD_CONST', 10000) + self.assertNotIn("x"*10000, code.co_consts) + code = compile('a=1<<1000', '', 'single') self.assertInBytecode(code, 'LOAD_CONST', 1000) + self.assertNotIn(1<<1000, code.co_consts) + code = compile('a=2**1000', '', 'single') + self.assertInBytecode(code, 'LOAD_CONST', 1000) + self.assertNotIn(2**1000, code.co_consts) def test_binary_subscr_on_unicode(self): # valid code get optimized |