[pypy-svn] r20837 - in pypy/dist/pypy: module/_socket module/_socket/rpython module/_socket/rpython/test translator/c/test

nik at codespeak.net nik at codespeak.net
Wed Dec 7 16:13:11 CET 2005


Author: nik
Date: Wed Dec  7 16:13:08 2005
New Revision: 20837

Modified:
   pypy/dist/pypy/module/_socket/interp_socket.py
   pypy/dist/pypy/module/_socket/rpython/exttable.py
   pypy/dist/pypy/module/_socket/rpython/ll__socket.py
   pypy/dist/pypy/module/_socket/rpython/rsocket.py
   pypy/dist/pypy/module/_socket/rpython/test/test_ll__socket.py
   pypy/dist/pypy/translator/c/test/test_ext__socket.py
Log:
(ale, nik)

first tentative steps towards creating socket objects. doesn't translate,
yet.


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	Wed Dec  7 16:13:08 2005
@@ -618,12 +618,16 @@
         socket.setdefaulttimeout(timeout)
 
     try:
-        fd = socket.socket(family, type, proto)
+        fd = rsocket.newsocket(family, type, proto)
     except socket.error, e:
         raise wrap_socketerror(space, e)
-    sock = space.allocate_instance(Socket, w_subtype)
-    Socket.__init__(sock, space, fd, family, type, proto)
-    return space.wrap(sock)
+    # XXX If we want to support subclassing the socket type we will need
+    # something along these lines. But allocate_instance is only defined
+    # on the standard object space, so this is not really correct.
+    #sock = space.allocate_instance(Socket, w_subtype)
+    #Socket.__init__(sock, space, fd, family, type, proto)
+    #return space.wrap(sock)
+    return space.wrap(Socket(space, fd, family, type, proto))
 descr_socket_new = interp2app(newsocket,
                                unwrap_spec=[ObjSpace, W_Root, int, int, int])
 

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	Wed Dec  7 16:13:08 2005
@@ -41,6 +41,8 @@
 declare(_socket.ntohl, int, '%s/ntohl' % module)
 declare(_socket.htonl, int, '%s/htonl' % module)
 
+declare(rsocket.newsocket, int, '%s/newsocket' % module)
+
 # ____________________________________________________________
 # _socket.error can be raised by the above
 

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	Wed Dec  7 16:13:08 2005
@@ -73,3 +73,7 @@
     return _socket.ntohl(htonl)
 ll__socket_ntohl.suggested_primitive = True
 
+def ll__socket_newsocket(family, type, protocol):
+    return _socket.socket(family, type, protocol).fileno()
+ll__socket_newsocket.suggested_primitive = True
+

Modified: pypy/dist/pypy/module/_socket/rpython/rsocket.py
==============================================================================
--- pypy/dist/pypy/module/_socket/rpython/rsocket.py	(original)
+++ pypy/dist/pypy/module/_socket/rpython/rsocket.py	Wed Dec  7 16:13:08 2005
@@ -25,3 +25,6 @@
 
 def getaddrinfo(host, port, family, socktype, proto, flags):
     return ADDRINFO(host, port, family, socktype, proto, flags)
+
+def newsocket(family, type, protocol):
+    return socket.socket(family, type, protocol).fileno()

Modified: pypy/dist/pypy/module/_socket/rpython/test/test_ll__socket.py
==============================================================================
--- pypy/dist/pypy/module/_socket/rpython/test/test_ll__socket.py	(original)
+++ pypy/dist/pypy/module/_socket/rpython/test/test_ll__socket.py	Wed Dec  7 16:13:08 2005
@@ -29,3 +29,7 @@
     info = ll__socket_nextaddrinfo(addr)
     info = info[:4] + (info[4:],)
     assert info == _socket.getaddrinfo(host, port)[0]
+
+def test_newsocket():
+    fd = ll__socket_newsocket(_socket.AF_INET, _socket.SOCK_STREAM, 0)
+    assert isinstance(fd, int)

Modified: pypy/dist/pypy/translator/c/test/test_ext__socket.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_ext__socket.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_ext__socket.py	Wed Dec  7 16:13:08 2005
@@ -2,6 +2,7 @@
 import py
 import _socket
 from pypy.translator.c.test.test_genc import compile
+from pypy.translator.translator import Translator
 
 def setup_module(mod):
     import pypy.module._socket.rpython.exttable   # for declare()/declaretype()
@@ -60,3 +61,19 @@
     f1 = compile(does_stuff, [str, str])
     res = f1("localhost", "25")
     assert eval(res) == _socket.getaddrinfo("localhost", "25")
+
+def test_newsocket_annotation():
+    from pypy.module._socket.rpython import rsocket
+    def does_stuff():
+        return rsocket.newsocket(_socket.AF_INET, _socket.SOCK_STREAM, 0)
+    t = Translator(does_stuff)
+    a = t.annotate([])
+    assert a.gettype(t.graphs[0].getreturnvar()) == int
+
+def DONOT_test_newsocket():
+    from pypy.module._socket.rpython import rsocket
+    def does_stuff():
+        return rsocket.newsocket(_socket.AF_INET, _socket.SOCK_STREAM, 0)
+    f1 = compile(does_stuff, [])
+    res = f1()
+    assert isinstance(res, int)



More information about the Pypy-commit mailing list