[ python-Bugs-1512814 ] Incorrect lineno's in code objects

SourceForge.net noreply at sourceforge.net
Thu Jul 13 11:58:52 CEST 2006


Bugs item #1512814, was opened at 2006-06-26 18:01
Message generated for change (Comment added) made by twouters
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1512814&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Parser/Compiler
Group: Python 2.5
Status: Open
Resolution: None
Priority: 7
Submitted By: Thomas Wouters (twouters)
>Assigned to: Neal Norwitz (nnorwitz)
Summary: Incorrect lineno's in code objects

Initial Comment:
The 2.5 compiler forgets how to count linenumbers in
certain situations:

>>> s255 = "".join(["\n"] * 255 + ["spam"])
>>> s256 = "".join(["\n"] * 256 + ["spam"])

>>> exec s255
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 256, in <module>
NameError: name 'spam' is not defined

>>> exec s256
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1, in <module>
NameError: name 'spam' is not defined

Notice the 'line 1' linenumber in the case of 256 blank
lines. The same happens for 'pass' statements or 'if 0'
blocks instead of blank lines. The problem is in the
actual code objects created:

>>> dis.disco(compile(s255, "", "exec"))
256           0 LOAD_NAME                0 (spam)
              3 POP_TOP             
              4 LOAD_CONST               0 (None)
              7 RETURN_VALUE        
>>> dis.disco(compile(s256, "", "exec"))
  1           0 LOAD_NAME                0 (spam)
              3 POP_TOP             
              4 LOAD_CONST               0 (None)
              7 RETURN_VALUE        



----------------------------------------------------------------------

>Comment By: Thomas Wouters (twouters)
Date: 2006-07-13 11:58

Message:
Logged In: YES 
user_id=34209

Yep, the patch seems to work, also for the other case
someone pointed out to me, that was still broken after the
last fix:

>>> exec "import os\ns='''" + "\n"*256 + "'''\n1/0\n"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1, in <module>
ZeroDivisionError: integer division or modulo by zero

I tried a couple of other ways to get large linenumbers and
complex(er) parsing structures, and they all seem to work right.

----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2006-07-13 07:59

Message:
Logged In: YES 
user_id=33168

Try the attached patch on for size.  Let me know if you can
find any other holes.

----------------------------------------------------------------------

Comment By: Thomas Wouters (twouters)
Date: 2006-07-12 15:11

Message:
Logged In: YES 
user_id=34209

Unfortunately, it isn't quite fixed. It's fixed for code in
the global scope, but not for functions:

>>> s255 = "def foo():\n " + "".join(["\n "] * 254 + ["
spam\n"])
>>> exec s255
>>> dis.dis(foo)
.256           0 LOAD_GLOBAL              0 (spam)
.              3 POP_TOP             
.              4 LOAD_CONST               0 (None)
.              7 RETURN_VALUE        

>>> s256 = "def foo():\n " + "".join(["\n "] * 255 + ["
spam\n"])
>>> exec s256
>>> dis.dis(foo)
.  1           0 LOAD_GLOBAL              0 (spam)
.              3 POP_TOP             
.              4 LOAD_CONST               0 (None)
.              7 RETURN_VALUE        

I haven't tried figuring out for what else it's broken like
this, sorry :)


----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2006-07-10 02:04

Message:
Logged In: YES 
user_id=33168

Committed revision 50500.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1512814&group_id=5470


More information about the Python-bugs-list mailing list