[pypy-commit] pypy stdlib-2.7.6: clean up fcntl overflow checking

bdkearns noreply at buildbot.pypy.org
Mon Mar 3 10:35:48 CET 2014


Author: Brian Kearns <bdkearns at gmail.com>
Branch: stdlib-2.7.6
Changeset: r69637:646404c7a0b2
Date: 2014-03-03 04:16 -0500
http://bitbucket.org/pypy/pypy/changeset/646404c7a0b2/

Log:	clean up fcntl overflow checking

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1546,11 +1546,16 @@
                 raise OperationError(self.w_TypeError,
                     self.wrap("fileno() returned a non-integer")
                 )
-        fd = self.int_w(w_fd)
-        if fd < 0 or fd > INT_MAX:
+        try:
+            fd = self.c_int_w(w_fd)
+        except OperationError, e:
+            if e.match(self, self.w_OverflowError):
+                fd = -1
+            else:
+                raise
+        if fd < 0:
             raise oefmt(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, w_msg, w_warningcls, stacklevel=2):
diff --git a/pypy/module/fcntl/test/test_fcntl.py b/pypy/module/fcntl/test/test_fcntl.py
--- a/pypy/module/fcntl/test/test_fcntl.py
+++ b/pypy/module/fcntl/test/test_fcntl.py
@@ -35,11 +35,16 @@
         fcntl.fcntl(F(long(f.fileno())), 1)
         raises(TypeError, fcntl.fcntl, "foo")
         raises(TypeError, fcntl.fcntl, f, "foo")
-        raises(TypeError, fcntl.fcntl, F("foo"), 1)
-        raises(ValueError, fcntl.fcntl, 2147483647 + 1, 1, 0)
-        raises(ValueError, fcntl.fcntl, F(2147483647 + 1), 1, 0)
-        raises(ValueError, fcntl.fcntl, -2147483648 - 1, 1, 0)
-        raises(ValueError, fcntl.fcntl, F(-2147483648 - 1), 1, 0)
+        exc = raises(TypeError, fcntl.fcntl, F("foo"), 1)
+        assert exc.value[0] == 'fileno() returned a non-integer'
+        exc = raises(ValueError, fcntl.fcntl, 2147483647 + 1, 1, 0)
+        assert exc.value[0] == 'file descriptor cannot be a negative integer (-1)'
+        exc = raises(ValueError, fcntl.fcntl, F(2147483647 + 1), 1, 0)
+        assert exc.value[0] == 'file descriptor cannot be a negative integer (-1)'
+        exc = raises(ValueError, fcntl.fcntl, -2147483648 - 1, 1, 0)
+        assert exc.value[0] == 'file descriptor cannot be a negative integer (-1)'
+        exc = raises(ValueError, fcntl.fcntl, F(-2147483648 - 1), 1, 0)
+        assert exc.value[0] == 'file descriptor cannot be a negative integer (-1)'
         raises(ValueError, fcntl.fcntl, -1, 1, 0)
         raises(ValueError, fcntl.fcntl, F(-1), 1, 0)
         raises(ValueError, fcntl.fcntl, F(long(-1)), 1, 0)


More information about the pypy-commit mailing list