[pypy-svn] r80052 - pypy/trunk/pypy/interpreter

agaynor at codespeak.net agaynor at codespeak.net
Tue Dec 14 10:05:15 CET 2010


Author: agaynor
Date: Tue Dec 14 10:05:13 2010
New Revision: 80052

Modified:
   pypy/trunk/pypy/interpreter/baseobjspace.py
Log:
Make c_filedescriptor_w more closely mirror CPython's PyObject_AsFileDescriptor (in behavior and structure), which doesn't bother verifying the int fits in 32-bits.


Modified: pypy/trunk/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/trunk/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/trunk/pypy/interpreter/baseobjspace.py	Tue Dec 14 10:05:13 2010
@@ -797,8 +797,8 @@
 
     def call_obj_args(self, w_callable, w_obj, args):
         if not self.config.objspace.disable_call_speedhacks:
-            # XXX start of hack for performance            
-            from pypy.interpreter.function import Function        
+            # XXX start of hack for performance
+            from pypy.interpreter.function import Function
             if isinstance(w_callable, Function):
                 return w_callable.call_obj_args(w_obj, args)
             # XXX end of hack for performance
@@ -1184,24 +1184,27 @@
         return value
 
     def c_filedescriptor_w(self, w_fd):
-        try:
-            fd = self.c_int_w(w_fd)
-        except OperationError, e:
-            if not e.match(self, self.w_TypeError):
-                raise
+        if (not self.isinstance_w(w_fd, self.w_int) and
+            not self.isinstance_w(w_fd, self.w_long)):
             try:
-                w_fileno = self.getattr(w_fd, self.wrap('fileno'))
+                w_fileno = self.getattr(w_fd, self.wrap("fileno"))
             except OperationError, e:
                 if e.match(self, self.w_AttributeError):
                     raise OperationError(self.w_TypeError,
-                        self.wrap("argument must be an int, "
-                                  "or have a fileno() method."))
+                        self.wrap("argument must be an int, or have a fileno() "
+                            "method.")
+                    )
                 raise
             w_fd = self.call_function(w_fileno)
-            fd = self.c_int_w(w_fd)
+            if not self.isinstance_w(w_fd, self.w_int):
+                raise OperationError(self.w_TypeError,
+                    self.wrap("fileno() must return an integer")
+                )
+        fd = self.int_w(w_fd)
         if fd < 0:
             raise operationerrfmt(self.w_ValueError,
-                "file descriptor cannot be a negative integer (%d)", fd)
+                "file descriptor cannot be a negative integer (%d)", fd
+            )
         return fd
 
     def warn(self, msg, w_warningcls):
@@ -1403,4 +1406,3 @@
     'call_args',
     'marshal_w',
     ]
-



More information about the Pypy-commit mailing list