[pypy-commit] pypy win32-cleanup2: be more conservative in failure of _validate_fd

mattip noreply at buildbot.pypy.org
Mon Apr 23 00:58:24 CEST 2012


Author: Matti Picus <matti.picus at gmail.com>
Branch: win32-cleanup2
Changeset: r54636:c97ac5d5d8b3
Date: 2012-04-23 01:57 +0300
http://bitbucket.org/pypy/pypy/changeset/c97ac5d5d8b3/

Log:	be more conservative in failure of _validate_fd

diff --git a/pypy/module/_file/interp_file.py b/pypy/module/_file/interp_file.py
--- a/pypy/module/_file/interp_file.py
+++ b/pypy/module/_file/interp_file.py
@@ -5,7 +5,6 @@
 from pypy.rlib import streamio
 from pypy.rlib.rarithmetic import r_longlong
 from pypy.rlib.rstring import StringBuilder
-from pypy.rlib.rposix import validate_fd
 from pypy.module._file.interp_stream import W_AbstractStream, StreamErrors
 from pypy.module.posix.interp_posix import dispatch_filename
 from pypy.interpreter.error import OperationError, operationerrfmt
@@ -272,15 +271,6 @@
 
     def file_fdopen(self, fd, mode="r", buffering=-1):
         try:
-            # Catch invalid fd early to get an OSError rather than an
-            # IOError from streamio
-            validate_fd(fd)
-        except OSError, e:
-            w_error = self.space.call_function(self.space.w_OSError,
-                    self.space.wrap(e.errno), self.space.wrap(e.strerror),
-                    self.space.wrap(e.filename))
-            raise OperationError(self.space.w_OSError, w_error)
-        try:
             self.direct_fdopen(fd, mode, buffering)
         except StreamErrors, e:
             raise wrap_streamerror(self.space, e, self.w_name)
diff --git a/pypy/module/_file/test/test_file.py b/pypy/module/_file/test/test_file.py
--- a/pypy/module/_file/test/test_file.py
+++ b/pypy/module/_file/test/test_file.py
@@ -265,14 +265,10 @@
 
         if option.runappdirect:
             py.test.skip("works with internals of _file impl on py.py")
-        import platform
-        if platform.system() == 'Windows':
-            # XXX This test crashes until someone implements something like
-            # XXX verify_fd from
-            # XXX http://hg.python.org/cpython/file/80ddbd822227/Modules/posixmodule.c#l434
-            # XXX and adds it to fopen
-            assert False
-
+        if os.name=='nt':
+            mode = 'rb'
+        else:
+            mode = 'r'
         state = [0]
         def read(fd, n=None):
             if fd != 42:
@@ -286,7 +282,7 @@
             return ''
         os.read = read
         stdin = W_File(cls.space)
-        stdin.file_fdopen(42, "r", 1)
+        stdin.file_fdopen(42, mode, 1)
         stdin.name = '<stdin>'
         cls.w_stream = stdin
 
diff --git a/pypy/rlib/streamio.py b/pypy/rlib/streamio.py
--- a/pypy/rlib/streamio.py
+++ b/pypy/rlib/streamio.py
@@ -93,7 +93,6 @@
     # XXX XXX XXX you want do check whether the modes are compatible
     # otherwise you get funny results
     os_flags, universal, reading, writing, basemode, binary = decode_mode(mode)
-    rposix.validate_fd(fd)
     _setfd_binary(fd)
     stream = DiskFile(fd)
     return construct_stream_tower(stream, buffering, universal, reading,
@@ -190,7 +189,9 @@
     # When generating on CLI or JVM, these are patched out.
     # See PyPyTarget.target() in targetpypystandalone.py
     def _setfd_binary(fd):
-        _setmode(fd, os.O_BINARY)
+        #Allow this to succeed on invalid fd's
+        if rposix._validate_fd(fd):
+            _setmode(fd, os.O_BINARY)
 
     def ftruncate_win32(fd, size):
         curpos = os.lseek(fd, 0, 1)


More information about the pypy-commit mailing list