Commits

mattip committed 6a1d460

expose validate_fd via __pypy__ so posix.fdopen can use it

Comments (0)

Files changed (3)

pypy/module/__pypy__/__init__.py

 from pypy.interpreter.mixedmodule import MixedModule
 from pypy.module.imp.importing import get_pyc_magic
 
-
 class BuildersModule(MixedModule):
     appleveldefs = {}
 
         'lookup_special'            : 'interp_magic.lookup_special',
         'do_what_I_mean'            : 'interp_magic.do_what_I_mean',
         'list_strategy'             : 'interp_magic.list_strategy',
+        'validate_fd'               : 'interp_magic.validate_fd',
     }
 
     submodules = {

pypy/module/__pypy__/interp_magic.py

 from pypy.interpreter.baseobjspace import ObjSpace, W_Root
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, wrap_oserror
 from pypy.interpreter.gateway import unwrap_spec
 from pypy.rlib.objectmodel import we_are_translated
 from pypy.objspace.std.typeobject import MethodCache
 from pypy.objspace.std.mapdict import IndexCache
+from pypy.rlib import rposix
 
 def internal_repr(space, w_object):
     return space.wrap('%r' % (w_object,))
     else:
         w_msg = space.wrap("Can only get the list strategy of a list")
         raise OperationError(space.w_TypeError, w_msg)
+
+@unwrap_spec(fd='c_int')
+def validate_fd(space, fd):
+    try:
+        rposix.validate_fd(fd)
+    except OSError, e:
+        raise wrap_oserror(space, e)

pypy/module/posix/app_posix.py

 # NOT_RPYTHON
 
 from _structseq import structseqtype, structseqfield
+from __pypy__ import validate_fd
 
 # XXX we need a way to access the current module's globals more directly...
 import sys
         except IOError, e:
             raise OSError(e.errno, e.strerror, e.filename)
 else:
-    def _validate_fd(fd):
-        # XXX for the moment
-        return
+    _validate_fd = validate_fd
 
 # Capture file.fdopen at import time, as some code replaces
 # __builtins__.file with a custom function.