[pypy-commit] pypy use-file-star-for-file: test/fix truncate on win32
bdkearns
noreply at buildbot.pypy.org
Thu Sep 11 23:14:07 CEST 2014
Author: Brian Kearns <bdkearns at gmail.com>
Branch: use-file-star-for-file
Changeset: r73484:e8ce802885c3
Date: 2014-09-11 14:12 -0700
http://bitbucket.org/pypy/pypy/changeset/e8ce802885c3/
Log: test/fix truncate on win32
diff --git a/rpython/rlib/rfile.py b/rpython/rlib/rfile.py
--- a/rpython/rlib/rfile.py
+++ b/rpython/rlib/rfile.py
@@ -107,6 +107,7 @@
c_feof = llexternal('feof', [FILEP], rffi.INT, releasegil=False)
c_ferror = llexternal('ferror', [FILEP], rffi.INT, releasegil=False)
c_clearerr = llexternal('clearerr', [FILEP], lltype.Void, releasegil=False)
+
c_setvbuf = llexternal('setvbuf', [FILEP, rffi.CCHARP, rffi.INT, rffi.SIZE_T],
rffi.INT, releasegil=False)
@@ -568,13 +569,24 @@
def truncate(self, arg=-1):
self._check_closed()
self._check_writable()
+ pos = intmask(c_ftell(self._ll_file))
+ if pos == -1:
+ c_clearerr(self._ll_file)
+ raise _from_errno(IOError)
if arg == -1:
- arg = self.tell()
- self.flush()
+ arg = pos
+ res = c_fflush(self._ll_file)
+ if res != 0:
+ c_clearerr(self._ll_file)
+ raise _from_errno(IOError)
res = c_ftruncate(self.fileno(), arg)
if res != 0:
c_clearerr(self._ll_file)
raise _from_errno(IOError)
+ res = c_fseek(self._ll_file, pos, os.SEEK_SET)
+ if res != 0:
+ c_clearerr(self._ll_file)
+ raise _from_errno(IOError)
def flush(self):
self._check_closed()
diff --git a/rpython/rlib/test/test_rfile.py b/rpython/rlib/test/test_rfile.py
--- a/rpython/rlib/test/test_rfile.py
+++ b/rpython/rlib/test/test_rfile.py
@@ -365,11 +365,14 @@
def f():
f = open(fname, "w+b")
f.write("hello world")
- f.seek(7)
+ f.seek(6)
+ assert f.read(1) == 'w'
f.truncate()
+ assert f.read(1) == ''
+ f.write('w')
f.seek(0)
data = f.read()
- assert data == "hello w"
+ assert data == "hello ww"
f.close()
f = open(fname)
try:
More information about the pypy-commit
mailing list