[pypy-svn] r20856 - in pypy/dist/pypy: module/_socket module/_socket/test translator/c/src translator/c/test

ale at codespeak.net ale at codespeak.net
Wed Dec 7 18:32:54 CET 2005


Author: ale
Date: Wed Dec  7 18:32:52 2005
New Revision: 20856

Modified:
   pypy/dist/pypy/module/_socket/interp_socket.py
   pypy/dist/pypy/module/_socket/test/test_socket2.py
   pypy/dist/pypy/translator/c/src/ll__socket.h
   pypy/dist/pypy/translator/c/test/test_ext__socket.py
Log:
(nik,ale)  Intermediate checkin - caring about errors


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 18:32:52 2005
@@ -992,4 +992,5 @@
 
  [*] not available on all platforms!""",
     __new__ = descr_socket_new,
+    ** socketmethods
     )

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	Wed Dec  7 18:32:52 2005
@@ -286,7 +286,17 @@
             else:
                 assert False
 
-
     def test_newsocket(self):
         import socket
         s = socket.socket()
+
+    def test_newsocket_error(self):
+        import socket
+        import errno
+        try:
+            s = socket.socket(1001,socket.SOCK_STREAM,0)
+        except socket.error, ex:
+            print ex,ex.args[0]
+            assert ex.args[0] == errno.EAFNOSUPPORT
+        else:
+            assert 0

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	Wed Dec  7 18:32:52 2005
@@ -78,7 +78,18 @@
 
 int LL__socket_newsocket(int family, int type, int protocol)
 {
-    return socket(family, type, protocol);
+    int fd;
+
+    fd = socket(family, type, protocol);
+
+#ifdef MS_WINDOWS
+    if (fd == INVALID_SOCKET)
+#else
+    if (fd < 0)
+#endif
+    {
+      return -1; 
+    }
 }
 /* ____________________________________________________________________________ */
 

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 18:32:52 2005
@@ -77,3 +77,12 @@
     f1 = compile(does_stuff, [])
     res = f1()
     assert isinstance(res, int)
+
+def test_newsocket_error():
+    from pypy.module._socket.rpython import rsocket
+    def does_stuff():
+        return rsocket.newsocket(1001, _socket.SOCK_STREAM, 0)
+    f1 = compile(does_stuff, [])
+    res = f1()
+    assert res == -1
+



More information about the Pypy-commit mailing list