[Python-bugs-list] [Bug #131239] -x flag is ignored on non pyc files

noreply@sourceforge.net noreply@sourceforge.net
Sat, 10 Feb 2001 20:37:52 -0800


Bug #131239, was updated on 2001-Feb-06 02:30
Here is a current snapshot of the bug.

Project: Python
Category: Python Interpreter Core
Status: Closed
Resolution: Fixed
Bug Group: None
Priority: 8
Submitted by: mpmak
Assigned to : tim_one
Summary: -x flag is ignored on non pyc files

Details: 
simple script x.bat will raise syntax error in line 1
@python -x "%~f0" %* & goto :EOF
print 'ok'

maybe_pyc_file in pythonrun.c does not save/restore file position when
reading non pyc file which was given as argument on command line.


Follow-Ups:

Date: 2001-Feb-10 20:37
By: tim_one

Comment:
Closed and Fixed, reassigned to me.  Ugly but std-conforming fix checked in
to pythonrun.c rev 2.122.

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

Date: 2001-Feb-10 20:03
By: tim_one

Comment:
Boosted priority, cuz -x must be broken everywhere.  Unclear how to fix
it.

Saving/restoring the file pointer in maybe_pyc_file won't do the trick,
because in case of -x an ungetc() is used to push the first newline back
onto the stream; an ftell/fseek pair would blow that away, reintroducing
the bug (off-by-one line numbers in tracebacks) that ungetc() was
introduced to fix.  fseek()ing to "one before" the current fp position
isn't any good either, because the input file was opened in text mode, and
arithmetic on ftell() results doesn't work x-platform due to line-end
translations.  (Strictly speaking, the stream position is undefined after
an ungetc() for streams opened in text mode.)

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

Date: 2001-Feb-09 15:48
By: tim_one

Comment:
Assigned to Guido.  Guido, can you reproduce?  This requires cmd.exe, not
the command.com Win9X uses for a shell (i.e., I can't try it; but you can
under your Win2000).  Hmm.  Under Win98SE, I can put this in x.bat and get
(almost certainly) the same problem (via running x.bat):

python -x x.bat
print "hi"

Nothing special about .bat files!  Have to suspect -x is plain busted.
-------------------------------------------------------

Date: 2001-Feb-09 15:37
By: jhylton

Comment:
No clue what the .bat file is trying to do.

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

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=131239&group_id=5470