[pypy-svn] r18668 - in pypy/dist/pypy: doc/tool interpreter/pyparser/test module/_socket module/_socket/rpython module/_socket/rpython/test module/_socket/test rpython/l3interp rpython/l3interp/test rpython/module rpython/ootypesystem/test rpython/test translator/asm/ppc translator/c translator/c/src translator/c/test translator/goal/win32 translator/js translator/js/test translator/llvm/backendopt translator/test translator/tool

dialtone at codespeak.net dialtone at codespeak.net
Sun Oct 16 10:48:44 CEST 2005


Author: dialtone
Date: Sun Oct 16 10:48:23 2005
New Revision: 18668

Modified:
   pypy/dist/pypy/doc/tool/mydot.py   (props changed)
   pypy/dist/pypy/interpreter/pyparser/test/stdlib_testall.py   (props changed)
   pypy/dist/pypy/module/_socket/interp_socket.py
   pypy/dist/pypy/module/_socket/rpython/   (props changed)
   pypy/dist/pypy/module/_socket/rpython/__init__.py   (props changed)
   pypy/dist/pypy/module/_socket/rpython/exttable.py   (contents, props changed)
   pypy/dist/pypy/module/_socket/rpython/ll__socket.py   (contents, props changed)
   pypy/dist/pypy/module/_socket/rpython/test/   (props changed)
   pypy/dist/pypy/module/_socket/rpython/test/__init__.py   (props changed)
   pypy/dist/pypy/module/_socket/rpython/test/test_ll__socket.py   (props changed)
   pypy/dist/pypy/module/_socket/test/test_socket2.py
   pypy/dist/pypy/rpython/l3interp/   (props changed)
   pypy/dist/pypy/rpython/l3interp/l3interp.py   (props changed)
   pypy/dist/pypy/rpython/l3interp/model.py   (props changed)
   pypy/dist/pypy/rpython/l3interp/test/   (props changed)
   pypy/dist/pypy/rpython/l3interp/test/__init__.py   (props changed)
   pypy/dist/pypy/rpython/l3interp/test/test_l3interp.py   (props changed)
   pypy/dist/pypy/rpython/module/ll_stack.py   (props changed)
   pypy/dist/pypy/rpython/ootypesystem/test/test_ooann.py   (props changed)
   pypy/dist/pypy/rpython/ootypesystem/test/test_ooclean.py   (props changed)
   pypy/dist/pypy/rpython/test/test_ootype_llinterp.py   (props changed)
   pypy/dist/pypy/translator/asm/ppc/   (props changed)
   pypy/dist/pypy/translator/asm/ppc/__init__.py   (props changed)
   pypy/dist/pypy/translator/asm/ppc/codegen.py   (props changed)
   pypy/dist/pypy/translator/c/extfunc.py
   pypy/dist/pypy/translator/c/src/g_include.h
   pypy/dist/pypy/translator/c/src/ll__socket.h
   pypy/dist/pypy/translator/c/test/test_extfunc.py
   pypy/dist/pypy/translator/goal/win32/   (props changed)
   pypy/dist/pypy/translator/js/   (props changed)
   pypy/dist/pypy/translator/js/test/   (props changed)
   pypy/dist/pypy/translator/llvm/backendopt/support.py   (props changed)
   pypy/dist/pypy/translator/test/test_simplify.py   (props changed)
   pypy/dist/pypy/translator/test/test_unsimplify.py   (props changed)
   pypy/dist/pypy/translator/tool/pdbplus.py   (props changed)
   pypy/dist/pypy/translator/tool/util.py   (props changed)
Log:
FIXEOL

first _socket functions are translated and pass the tests


Modified: pypy/dist/pypy/module/_socket/interp_socket.py
==============================================================================
--- pypy/dist/pypy/module/_socket/interp_socket.py	(original)
+++ pypy/dist/pypy/module/_socket/interp_socket.py	Sun Oct 16 10:48:23 2005
@@ -1,4 +1,3 @@
-
 import socket, errno, sys
 from pypy.interpreter.typedef import TypeDef
 from pypy.interpreter.baseobjspace import Wrappable
@@ -71,13 +70,16 @@
 else:
     import os
     def socket_strerror(errno):
-        return os.strerror(errno)
+        try:
+            return os.strerror(errno)
+        except TypeError:
+            return errno
 
 def wrap_socketerror(space, e):
     assert isinstance(e, socket.error)
     errno = e.args[0]
     msg = socket_strerror(errno)
-    
+
     w_module = space.getbuiltinmodule('_socket')
     if isinstance(e, socket.gaierror):
         w_errortype = space.getattr(w_module, space.wrap('gaierror'))
@@ -85,16 +87,16 @@
         w_errortype = space.getattr(w_module, space.wrap('herror'))
     else:
         w_errortype = space.getattr(w_module, space.wrap('error'))
-        
+
     return OperationError(w_errortype,
                           space.wrap(errno),
                           space.wrap(msg))
 
 def wrap_timeouterror(space):
-    
+
     w_module = space.getbuiltinmodule('_socket')
     w_error = space.getattr(w_module, space.wrap('timeout'))
-        
+
     w_error = space.call_function(w_error,
                                   space.wrap("timed out"))
     return w_error
@@ -248,10 +250,10 @@
         raise OperationError(space.w_TypeError,
                              space.wrap("expected int/long, %s found" %
                                         (space.type(w_x).getname(space, "?"))))
-    
+
     return space.wrap(socket.ntohl(x))
 ntohl.unwrap_spec = [ObjSpace, W_Root]
-    
+
 def htons(space, x):
     """htons(integer) -> integer
 
@@ -259,7 +261,7 @@
     """
     return space.wrap(socket.htons(x))
 htons.unwrap_spec = [ObjSpace, int]
-    
+
 def htonl(space, w_x):
     """htonl(integer) -> integer
 
@@ -273,7 +275,7 @@
         raise OperationError(space.w_TypeError,
                              space.wrap("expected int/long, %s found" %
                                         (space.type(w_x).getname(space, "?"))))
-    
+
     return space.wrap(socket.htonl(x))
 htonl.unwrap_spec = [ObjSpace, W_Root]
 
@@ -337,7 +339,7 @@
         port = str(space.int_w(w_port))
     else:
         port = space.str_w(w_port)
-    
+
     try:
         return space.wrap(socket.getaddrinfo(host, port, family, socktype, proto, flags))
     except socket.error, e:
@@ -359,13 +361,13 @@
 #
 # Timeout management
 
-class State: 
+class State:
     def __init__(self, space):
         self.space = space
-        
+
         self.defaulttimeout = -1 # Default timeout for new sockets
-        
-def getstate(space): 
+
+def getstate(space):
     return space.fromcache(State)
 
 def setdefaulttimeout(space, w_timeout):
@@ -404,7 +406,7 @@
         socket.setdefaulttimeout(None)
     else:
         socket.setdefaulttimeout(timeout)
-            
+
     try:
         fd = socket.socket(family, type, proto)
     except socket.error, e:
@@ -414,7 +416,7 @@
     return space.wrap(sock)
 descr_socket_new = interp2app(newsocket,
                                unwrap_spec=[ObjSpace, W_Root, int, int, int])
-    
+
 class Socket(Wrappable):
     "A wrappable box around an interp-level socket object."
 
@@ -439,7 +441,7 @@
         newsock = Socket(newfd, self.family, self.type, self.proto)
         return space.wrap((newsock, address))
     accept.unwrap_spec = ['self', ObjSpace]
-        
+
     def bind(self, space, w_addr):
         """bind(address)
         
@@ -453,7 +455,7 @@
         except socket.error, e:
             raise wrap_socketerror(space, e)
     bind.unwrap_spec = ['self', ObjSpace, W_Root]
-        
+
     def close(self, space):
         """close()
 
@@ -479,7 +481,7 @@
         except socket.error, e:
             raise wrap_socketerror(space, e)
     connect.unwrap_spec = ['self', ObjSpace, W_Root]
-        
+
     def connect_ex(self, space, w_addr):
         """connect_ex(address) -> errno
         
@@ -492,7 +494,7 @@
         except socket.error, e:
             return space.wrap(e.errno)
     connect_ex.unwrap_spec = ['self', ObjSpace, W_Root]
-        
+
     def dup(self, space):
         """dup() -> socket object
 
@@ -537,7 +539,7 @@
         except socket.error, e:
             raise wrap_socketerror(space, e)
     getsockname.unwrap_spec = ['self', ObjSpace]
-        
+
     def getsockopt(self, space, level, option, w_buffersize=NoneNotWrapped):
         """getsockopt(level, option[, buffersize]) -> value
 
@@ -554,7 +556,7 @@
         except socket.error, e:
             raise wrap_socketerror(space, e)
     getsockopt.unwrap_spec = ['self', ObjSpace, int, int, W_Root]
-        
+
     def listen(self, space, backlog):
         """listen(backlog)
 
@@ -567,7 +569,7 @@
         except socket.error, e:
             raise wrap_socketerror(space, e)
     listen.unwrap_spec = ['self', ObjSpace, int]
-        
+
     def makefile(self, space, mode="r", buffersize=-1):
         """makefile([mode[, buffersize]]) -> file object
 
@@ -618,7 +620,7 @@
         except socket.error, e:
             raise wrap_socketerror(space, e)
     send.unwrap_spec = ['self', ObjSpace, str, int]
-        
+
     def sendall(self, space, data, flags=0):
         """sendall(data[, flags])
 
@@ -632,7 +634,7 @@
         except socket.error, e:
             raise wrap_socketerror(space, e)
     sendall.unwrap_spec = ['self', ObjSpace, str, int]
-    
+
     def sendto(self, space, data, w_param2, w_param3=NoneNotWrapped):
         """sendto(data[, flags], address) -> count
 
@@ -652,7 +654,7 @@
         except socket.error, e:
             raise wrap_socketerror(space, e)
     sendto.unwrap_spec = ['self', ObjSpace, str, W_Root, W_Root]
-    
+
     def setblocking(self, space, flag):
         """setblocking(flag)
 
@@ -672,7 +674,7 @@
         Set a socket option.  See the Unix manual for level and option.
         The value argument can either be an integer or a string.
         """
-        
+
         if space.is_true(space.isinstance(w_value, space.w_str)):
             strvalue = space.str_w(w_value)
             self.fd.setsockopt(level, option, strvalue)

Modified: pypy/dist/pypy/module/_socket/rpython/exttable.py
==============================================================================
--- pypy/dist/pypy/module/_socket/rpython/exttable.py	(original)
+++ pypy/dist/pypy/module/_socket/rpython/exttable.py	Sun Oct 16 10:48:23 2005
@@ -11,3 +11,6 @@
 # Built-in functions needed in the rtyper
 
 declare(_socket.ntohs, int, '%s/ntohs' % module)
+declare(_socket.htons, int, '%s/ntohs' % module)
+declare(_socket.ntohl, int, '%s/ntohl' % module)
+declare(_socket.htonl, int, '%s/htonl' % module)

Modified: pypy/dist/pypy/module/_socket/rpython/ll__socket.py
==============================================================================
--- pypy/dist/pypy/module/_socket/rpython/ll__socket.py	(original)
+++ pypy/dist/pypy/module/_socket/rpython/ll__socket.py	Sun Oct 16 10:48:23 2005
@@ -3,3 +3,15 @@
 def ll__socket_ntohs(htons):
     return _socket.ntohs(htons)
 ll__socket_ntohs.suggested_primitive = True
+
+def ll__socket_htons(ntohs):
+    return _socket.ntohs(htons)
+ll__socket_htons.suggested_primitive = True
+
+def ll__socket_htonl(ntohl):
+    return _socket.htonl(ntohl)
+ll__socket_htonl.suggested_primitive = True
+
+def ll__socket_ntohl(htonl):
+    return _socket.ntohl(htonl)
+ll__socket_ntohl.suggested_primitive = True

Modified: pypy/dist/pypy/module/_socket/test/test_socket2.py
==============================================================================
--- pypy/dist/pypy/module/_socket/test/test_socket2.py	(original)
+++ pypy/dist/pypy/module/_socket/test/test_socket2.py	Sun Oct 16 10:48:23 2005
@@ -152,9 +152,9 @@
     w_l = space.appexec([w_socket, space.wrap(unicode(host)), space.wrap(port)],
                         "(_socket, host, port): return _socket.getaddrinfo(host, port)")
     assert space.unwrap(w_l) == info
-    
+
 def test_getnameinfo():
-    host = "localhost"
+    host = "127.0.0.1"
     port = 25
     info = socket.getnameinfo((host, port), 0)
     w_l = space.appexec([w_socket, space.wrap(host), space.wrap(port)],

Modified: pypy/dist/pypy/translator/c/extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/extfunc.py	(original)
+++ pypy/dist/pypy/translator/c/extfunc.py	Sun Oct 16 10:48:23 2005
@@ -55,6 +55,9 @@
     ll_stack.ll_stack_unwind: 'LL_stack_unwind',
     ll_stack.ll_stack_too_big: 'LL_stack_too_big',
     ll__socket.ll__socket_ntohs: 'LL__socket_ntohs',
+    ll__socket.ll__socket_htons: 'LL__socket_htons',
+    ll__socket.ll__socket_htonl: 'LL__socket_htonl',
+    ll__socket.ll__socket_ntohl: 'LL__socket_htonl',
     }
 
 #______________________________________________________

Modified: pypy/dist/pypy/translator/c/src/g_include.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/g_include.h	(original)
+++ pypy/dist/pypy/translator/c/src/g_include.h	Sun Oct 16 10:48:23 2005
@@ -39,6 +39,7 @@
 #  include "src/ll_strtod.h"
 #  include "src/ll_thread.h"
 #  include "src/ll_stackless.h"
+#  include "src/ll__socket.h"
 #endif
 
 #include "src/stack.h"

Modified: pypy/dist/pypy/translator/c/src/ll__socket.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/ll__socket.h	(original)
+++ pypy/dist/pypy/translator/c/src/ll__socket.h	Sun Oct 16 10:48:23 2005
@@ -7,7 +7,9 @@
 #endif
 
 int LL__socket_ntohs(int htons);
-
+int LL__socket_htons(int ntohs);
+long LL__socket_ntohl(long htonl);
+long LL__socket_htonl(long ntohl);
 
 #ifndef PYPY_NOT_MAIN_FILE
 
@@ -18,4 +20,25 @@
 
 }
 
+int LL__socket_htons(int ntohs)
+{
+
+    return (int)htons((short) ntohs);
+
+}
+
+long LL__socket_ntohl(long htonl)
+{
+
+    return ntohl(htonl);
+
+}
+
+long LL__socket_htonl(long ntohl)
+{
+
+    return htonl(ntohl);
+
+}
+
 #endif

Modified: pypy/dist/pypy/translator/c/test/test_extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_extfunc.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_extfunc.py	Sun Oct 16 10:48:23 2005
@@ -169,7 +169,7 @@
     assert f(2.3, -1.0) == math.pow(2.3, -1.0)
     assert f(2.3, -2.0) == math.pow(2.3, -2.0)
     assert f(2.3, 0.5) == math.pow(2.3, 0.5)
-    assert f(4.0, 0.5) == math.pow(4.0, 0.5)    
+    assert f(4.0, 0.5) == math.pow(4.0, 0.5)
 
 def test_math_frexp():
     from math import frexp
@@ -201,7 +201,7 @@
     import random
     import math
     mathfn = getattr(math, funcname)
-    print funcname, 
+    print funcname,
     def fn(x):
         return mathfn(x)
     f = compile(fn, [float])
@@ -235,7 +235,7 @@
                 #print mathf, v, r
                 u = f(v)
                 assert u == r
-                
+
     check(math.log, f, -1.0)
     check(math.log, f, 0.0)
 
@@ -284,7 +284,7 @@
         return parts_to_float(sign, beforept, afterpt, exponent)
 
     f = compile(fn, [str, str, str, str])
-    
+
     data = [
     (("","1","","")     , 1.0),
     (("-","1","","")    , -1.0),
@@ -498,11 +498,50 @@
         f()
         assert _real_getenv('ABCDEF') is None
 
-def INPROGRESStest_socket():
+def test_socket():
     import _socket
     import pypy.module._socket.rpython.exttable   # for declare()/declaretype()
     def fn():
-        print _socket.ntohs(123)
+        return _socket.ntohs(123)
+    f = compile(fn, [])
+    assert f() == _socket.ntohs(123)
+    def fn():
+        return _socket.htons(123)
+    f = compile(fn, [])
+    assert f() == _socket.htons(123)
+    def fn():
+        return _socket.ntohl(123)
     f = compile(fn, [])
-    f()
+    assert f() == _socket.ntohl(123)
+    def fn():
+        return _socket.htonl(123)
+    f = compile(fn, [])
+    assert f() == _socket.htonl(123)
+
+def INPROGRESStest_NtoH():
+    import _socket
+    # This just checks that htons etc. are their own inverse,
+    # when looking at the lower 16 or 32 bits.
+    def fn1(n):
+        return _socket.htonl(n)
+    def fn2(n):
+        return _socket.ntohl(n)
+    def fn3(n):
+        return _socket.ntohs(n)
+    def fn4(n):
+        return _socket.htons(n)
+    sizes = {compile(fn1, [int]): 32, compile(fn2, [int]): 32,
+             compile(fn4, [int]): 16, compile(fn3, [int]): 16}
+    for func, size in sizes.items():
+        mask = (1L<<size) - 1
+        for i in (0, 1, 0xffff, ~0xffff, 2, 0x01234567, 0x76543210):
+            assert i & mask == func(func(i&mask)) & mask
 
+        swapped = func(mask)
+        assert swapped & mask == mask
+        try:
+            func(1L<<34)
+        except OverflowError:
+            pass
+        else:
+            assert False



More information about the Pypy-commit mailing list