mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Fix SF bug # 561858 Assertion with very long lists
Write 4 bytes for co_stacksize, etc. to prevent writing out bad .pyc files which can cause a crash when read back in.
This commit is contained in:
parent
1f68fc7fa5
commit
7fdcb41131
3 changed files with 43 additions and 12 deletions
|
@ -3,6 +3,7 @@ from test_support import TESTFN, TestFailed
|
|||
import os
|
||||
import random
|
||||
import sys
|
||||
import py_compile
|
||||
|
||||
# Brief digression to test that import is case-sensitive: if we got this
|
||||
# far, we know for sure that "random" exists.
|
||||
|
@ -74,3 +75,33 @@ finally:
|
|||
import imp
|
||||
x = imp.find_module("os")
|
||||
os = imp.load_module("os", *x)
|
||||
|
||||
def test_module_with_large_stack(module):
|
||||
# create module w/list of 65000 elements to test bug #561858
|
||||
filename = module + '.py'
|
||||
|
||||
# create a file with a list of 65000 elements
|
||||
f = open(filename, 'w+')
|
||||
f.write('d = [\n')
|
||||
for i in range(65000):
|
||||
f.write('"",\n')
|
||||
f.write(']')
|
||||
f.close()
|
||||
|
||||
# compile & remove .py file, we only need .pyc
|
||||
f = open(filename, 'r')
|
||||
py_compile.compile(filename)
|
||||
os.unlink(filename)
|
||||
|
||||
# need to be able to load from current dir
|
||||
sys.path.append('')
|
||||
|
||||
# this used to crash
|
||||
exec 'import ' + module
|
||||
|
||||
# cleanup
|
||||
del sys.path[-1]
|
||||
os.unlink(module + '.pyc')
|
||||
|
||||
test_module_with_large_stack('longlist')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue