[pypy-commit] pypy disable_merge_different_int_types: (bivab, cfbolz): be more consistent about unsignedness in rsocket

cfbolz noreply at buildbot.pypy.org
Fri Nov 25 12:37:16 CET 2011


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: disable_merge_different_int_types
Changeset: r49783:97c82160cdd7
Date: 2011-11-25 12:36 +0100
http://bitbucket.org/pypy/pypy/changeset/97c82160cdd7/

Log:	(bivab, cfbolz): be more consistent about unsignedness in rsocket

diff --git a/pypy/rlib/rsocket.py b/pypy/rlib/rsocket.py
--- a/pypy/rlib/rsocket.py
+++ b/pypy/rlib/rsocket.py
@@ -131,11 +131,12 @@
     from_object = staticmethod(from_object)
 
     @staticmethod
-    def _check_port(space, port):
+    def make_ushort_port(space, port):
         from pypy.interpreter.error import OperationError
         if port < 0 or port > 0xffff:
             raise OperationError(space.w_ValueError, space.wrap(
                 "port must be 0-65535."))
+        return rffi.cast(rffi.USHORT, port)
 
     def fill_from_object(self, space, w_address):
         """ Purely abstract
@@ -309,7 +310,7 @@
             raise TypeError("AF_INET address must be a tuple of length 2")
         host = space.str_w(w_host)
         port = space.int_w(w_port)
-        Address._check_port(space, port)
+        port = Address.make_ushort_port(space, port)
         return INETAddress(host, port)
     from_object = staticmethod(from_object)
 
@@ -318,7 +319,7 @@
         from pypy.interpreter.error import OperationError
         _, w_port = space.unpackiterable(w_address, 2)
         port = space.int_w(w_port)
-        self._check_port(space, port)
+        port = self.make_ushort_port(space, port)
         a = self.lock(_c.sockaddr_in)
         rffi.setintfield(a, 'c_sin_port', htons(port))
         self.unlock()
@@ -403,7 +404,7 @@
                                "to 4, not %d" % len(pieces_w))
         host = space.str_w(pieces_w[0])
         port = space.int_w(pieces_w[1])
-        Address._check_port(space, port)
+        port = Address.make_ushort_port(space, port)
         if len(pieces_w) > 2: flowinfo = space.uint_w(pieces_w[2])
         else:                 flowinfo = 0
         if len(pieces_w) > 3: scope_id = space.uint_w(pieces_w[3])
@@ -419,7 +420,7 @@
             raise RSocketError("AF_INET6 address must be a tuple of length 2 "
                                "to 4, not %d" % len(pieces_w))
         port = space.int_w(pieces_w[1])
-        self._check_port(space, port)
+        port = self.make_ushort_port(space, port)
         if len(pieces_w) > 2: flowinfo = space.uint_w(pieces_w[2])
         else:                 flowinfo = 0
         if len(pieces_w) > 3: scope_id = space.uint_w(pieces_w[3])


More information about the pypy-commit mailing list