[Python-checkins] r50673 - in python/trunk: Lib/test/test_dis.py Misc/NEWS Python/compile.c
neal.norwitz
python-checkins at python.org
Sun Jul 16 03:50:40 CEST 2006
Author: neal.norwitz
Date: Sun Jul 16 03:50:38 2006
New Revision: 50673
Modified:
python/trunk/Lib/test/test_dis.py
python/trunk/Misc/NEWS
python/trunk/Python/compile.c
Log:
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.
Modified: python/trunk/Lib/test/test_dis.py
==============================================================================
--- python/trunk/Lib/test/test_dis.py (original)
+++ python/trunk/Lib/test/test_dis.py Sun Jul 16 03:50:38 2006
@@ -81,6 +81,13 @@
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 @@
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)
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Sun Jul 16 03:50:38 2006
@@ -12,6 +12,9 @@
Core and builtins
-----------------
+- Bug #1512814, Fix incorrect lineno's when code within a function
+ had more than 255 blank lines.
+
- Patch #1521179: Python now accepts the standard options ``--help`` and
``--version`` as well as ``/?`` on Windows.
Modified: python/trunk/Python/compile.c
==============================================================================
--- python/trunk/Python/compile.c (original)
+++ python/trunk/Python/compile.c Sun Jul 16 03:50:38 2006
@@ -4098,9 +4098,10 @@
In order for this to work, when the addr field increments by more than 255,
the line # increment in each pair generated must be 0 until the remaining addr
-increment is < 256. So, in the example above, com_set_lineno should not (as
-was actually done until 2.2) expand 300, 300 to 255, 255, 45, 45, but to
-255, 0, 45, 255, 0, 45.
+increment is < 256. So, in the example above, assemble_lnotab (it used
+to be called com_set_lineno) should not (as was actually done until 2.2)
+expand 300, 300 to 255, 255, 45, 45,
+ but to 255, 0, 45, 255, 0, 45.
*/
static int
@@ -4155,12 +4156,12 @@
}
lnotab = (unsigned char *)
PyString_AS_STRING(a->a_lnotab) + a->a_lnotab_off;
- *lnotab++ = 255;
*lnotab++ = d_bytecode;
+ *lnotab++ = 255;
d_bytecode = 0;
for (j = 1; j < ncodes; j++) {
- *lnotab++ = 255;
*lnotab++ = 0;
+ *lnotab++ = 255;
}
d_lineno -= ncodes * 255;
a->a_lnotab_off += ncodes * 2;
More information about the Python-checkins
mailing list