Bugs item #1512814, was opened at 2006-06-26 09:01
Message generated for change (Comment added) made by nnorwitz
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: Thomas Wouters (twouters)
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: Neal Norwitz (nnorwitz)
Date: 2006-07-12 22: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 06: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-09 17: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
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to