[pypy-svn] r74034 - in pypy/trunk: lib-python/modified-2.5.2/test pypy/module/_socket pypy/module/_socket/test

arigo at codespeak.net arigo at codespeak.net
Sat Apr 24 17:29:50 CEST 2010


Author: arigo
Date: Sat Apr 24 17:29:48 2010
New Revision: 74034

Modified:
   pypy/trunk/lib-python/modified-2.5.2/test/test_socket.py
   pypy/trunk/pypy/module/_socket/interp_func.py
   pypy/trunk/pypy/module/_socket/test/test_sock_app.py
Log:
A fix for 64-bit, including more corner cases that are wrong
in various versions of CPython.


Modified: pypy/trunk/lib-python/modified-2.5.2/test/test_socket.py
==============================================================================
--- pypy/trunk/lib-python/modified-2.5.2/test/test_socket.py	(original)
+++ pypy/trunk/lib-python/modified-2.5.2/test/test_socket.py	Sat Apr 24 17:29:48 2010
@@ -307,10 +307,23 @@
             mask = (1L<<size) - 1
             for i in (0, 1, 0xffff, ~0xffff, 2, 0x01234567, 0x76543210):
                 self.assertEqual(i & mask, func(func(i&mask)) & mask)
+                # should also accept ints, not only longs:
+                self.assertEqual(i & mask, func(func(int(i&mask))) & mask)
 
             swapped = func(mask)
             self.assertEqual(swapped & mask, mask)
             self.assertRaises(OverflowError, func, 1L<<34)
+            if test_support.check_impl_detail(cpython=False):
+                # XXX on 64-bit machines, it should also raise if it's an
+                # out-of-bound int, not just an out-of-bound long, but
+                # CPython 2.5/2.6 does not do it:
+                self.assertRaises(OverflowError, func, 1<<34)
+                # XXX the following check seems reasonable enough, but
+                # it does not work on CPython either; disabled for now:
+                #   self.assertRaises(OverflowError, func, 1<<size)
+                #   self.assertRaises(OverflowError, func, 1L<<size)
+                # the following was fixed on CPython >= 2.6:
+                self.assertRaises(OverflowError, func, -1)
 
     def testGetServBy(self):
         eq = self.assertEqual

Modified: pypy/trunk/pypy/module/_socket/interp_func.py
==============================================================================
--- pypy/trunk/pypy/module/_socket/interp_func.py	(original)
+++ pypy/trunk/pypy/module/_socket/interp_func.py	Sat Apr 24 17:29:48 2010
@@ -162,7 +162,7 @@
     Convert a 16-bit integer from network to host byte order.
     """
     return space.wrap(rsocket.ntohs(x))
-ntohs.unwrap_spec = [ObjSpace, r_uint]
+ntohs.unwrap_spec = [ObjSpace, "c_uint"]
 
 def ntohl(space, x):
     """ntohl(integer) -> integer
@@ -170,7 +170,7 @@
     Convert a 32-bit integer from network to host byte order.
     """
     return space.wrap(rsocket.ntohl(x))
-ntohl.unwrap_spec = [ObjSpace, r_uint]
+ntohl.unwrap_spec = [ObjSpace, "c_uint"]
 
 def htons(space, x):
     """htons(integer) -> integer
@@ -178,7 +178,7 @@
     Convert a 16-bit integer from host to network byte order.
     """
     return space.wrap(rsocket.htons(x))
-htons.unwrap_spec = [ObjSpace, r_uint]
+htons.unwrap_spec = [ObjSpace, "c_uint"]
 
 def htonl(space, x):
     """htonl(integer) -> integer
@@ -186,7 +186,7 @@
     Convert a 32-bit integer from host to network byte order.
     """
     return space.wrap(rsocket.htonl(x))
-htonl.unwrap_spec = [ObjSpace, r_uint]
+htonl.unwrap_spec = [ObjSpace, "c_uint"]
 
 def inet_aton(space, ip):
     """inet_aton(string) -> packed 32-bit IP representation

Modified: pypy/trunk/pypy/module/_socket/test/test_sock_app.py
==============================================================================
--- pypy/trunk/pypy/module/_socket/test/test_sock_app.py	(original)
+++ pypy/trunk/pypy/module/_socket/test/test_sock_app.py	Sat Apr 24 17:29:48 2010
@@ -115,6 +115,9 @@
     w_n = space.appexec([w_socket, space.wrap(0x89abcdef)],
                         "(_socket, x): return _socket.ntohl(x)")
     assert space.unwrap(w_n) in (0x89abcdef, 0xefcdab89)
+    space.raises_w(space.w_OverflowError, space.appexec,
+                   [w_socket, space.wrap(1<<32)],
+                   "(_socket, x): return _socket.ntohl(x)")
 
 def test_htons():
     w_n = space.appexec([w_socket, space.wrap(125)],
@@ -128,6 +131,9 @@
     w_n = space.appexec([w_socket, space.wrap(0x89abcdef)],
                         "(_socket, x): return _socket.htonl(x)")
     assert space.unwrap(w_n) in (0x89abcdef, 0xefcdab89)
+    space.raises_w(space.w_OverflowError, space.appexec,
+                   [w_socket, space.wrap(1<<32)],
+                   "(_socket, x): return _socket.htonl(x)")
 
 def test_aton_ntoa():
     ip = '123.45.67.89'



More information about the Pypy-commit mailing list