[Python-Dev] off-by-one on ftell on wine, but no regression test to catch it (original) (raw)

Luke Kenneth Casson Leighton lkcl at lkcl.net
Sat Jan 17 21:46:40 CET 2009


folks, hi, http://bugs.winehq.org/show_bug.cgi?id=16982 related to this:

from array import array

TESTFN = "testfile.txt"

def fail(x): print x

testlines = [ "spam, spam and eggs\n", "eggs, spam, ham and spam\n", "saussages, spam, spam and eggs\n", "spam, ham, spam and eggs\n", "spam, spam, spam, spam, spam, ham, spam\n", "wonderful spaaaaaam.\n" ]

try: # Prepare the testfile bag = open(TESTFN, "w") bag.writelines(testlines) bag.close()

f = open(TESTFN)
testline = testlines.pop(0)
line = f.readline()
testline = testlines.pop(0)
buf = array("c", "\x00" * len(testline))
f.readinto(buf)
testline = testlines.pop(0)
print "length of testline:", len(testline)
line = f.read(len(testline))

if line != testline:
    fail("read() after next() with empty buffer "
              "failed. Got %r, expected %r" % (line, testline))

lines = f.readlines()

if lines != testlines:
    fail("readlines() after next() with empty buffer "
              "failed. Got %r, expected %r" % (line, testline))
f.close()

finally: os.unlink(TESTFN)

which is a reduced version of Lib/test/test_file.py

running under wine, ftell() has an off-by-one bug, where the file position accidentally doesn't include the fact that the CR of the CRLF has been skipped. but, now with the fgets() bug fixed, the regression tests pass, but there's still the off-by-one bug which isn't caught.

this really should be added as a windows test. actually, it should be added as a test for everything: it's not always reasonable to assume that OSes get their file positions right :)

l.



More information about the Python-Dev mailing list