mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
Bug #1512814, Fix incorrect lineno's when code within a function
had more than 255 blank lines. Byte codes need to go first, line #s second.
This commit is contained in:
parent
ec5948aae2
commit
84be93b2db
3 changed files with 33 additions and 5 deletions
|
|
@ -81,6 +81,13 @@ dis_bug1333982 = """\
|
|||
bug1333982.func_code.co_firstlineno + 2,
|
||||
bug1333982.func_code.co_firstlineno + 3)
|
||||
|
||||
_BIG_LINENO_FORMAT = """\
|
||||
%3d 0 LOAD_GLOBAL 0 (spam)
|
||||
3 POP_TOP
|
||||
4 LOAD_CONST 0 (None)
|
||||
7 RETURN_VALUE
|
||||
"""
|
||||
|
||||
class DisTests(unittest.TestCase):
|
||||
def do_disassembly_test(self, func, expected):
|
||||
s = StringIO.StringIO()
|
||||
|
|
@ -124,6 +131,23 @@ class DisTests(unittest.TestCase):
|
|||
if __debug__:
|
||||
self.do_disassembly_test(bug1333982, dis_bug1333982)
|
||||
|
||||
def test_big_linenos(self):
|
||||
def func(count):
|
||||
namespace = {}
|
||||
func = "def foo():\n " + "".join(["\n "] * count + ["spam\n"])
|
||||
exec func in namespace
|
||||
return namespace['foo']
|
||||
|
||||
# Test all small ranges
|
||||
for i in xrange(1, 300):
|
||||
expected = _BIG_LINENO_FORMAT % (i + 2)
|
||||
self.do_disassembly_test(func(i), expected)
|
||||
|
||||
# Test some larger ranges too
|
||||
for i in xrange(300, 5000, 10):
|
||||
expected = _BIG_LINENO_FORMAT % (i + 2)
|
||||
self.do_disassembly_test(func(i), expected)
|
||||
|
||||
def test_main():
|
||||
run_unittest(DisTests)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue