[pypy-svn] r26313 - in pypy/dist/pypy: module/_socket rpython/rctypes/socketmodule rpython/rctypes/tool

ac at codespeak.net ac at codespeak.net
Tue Apr 25 11:13:36 CEST 2006


Author: ac
Date: Tue Apr 25 11:13:31 2006
New Revision: 26313

Modified:
   pypy/dist/pypy/module/_socket/__init__.py
   pypy/dist/pypy/module/_socket/app_socket.py
   pypy/dist/pypy/module/_socket/interp_socket.py
   pypy/dist/pypy/rpython/rctypes/socketmodule/ctypes_socket.py
   pypy/dist/pypy/rpython/rctypes/tool/ctypes_platform.py
Log:
(aleale, arre)
Fix gethostbyname{,_ex}.



Modified: pypy/dist/pypy/module/_socket/__init__.py
==============================================================================
--- pypy/dist/pypy/module/_socket/__init__.py	(original)
+++ pypy/dist/pypy/module/_socket/__init__.py	Tue Apr 25 11:13:31 2006
@@ -9,6 +9,7 @@
         'herror'     : 'app_socket.herror',
         'gaierror'   : 'app_socket.gaierror',
         'timeout'    : 'app_socket.timeout',
+        'gethostbyname': 'app_socket.gethostbyname',
     }
 
     interpleveldefs = {
@@ -17,7 +18,7 @@
     }
 
 for name in """
-    gethostbyname gethostbyname_ex gethostbyaddr gethostname
+    gethostbyname_ex gethostbyaddr gethostname
     getservbyname getservbyport getprotobyname
     fromfd socketpair
     ntohs ntohl htons htonl inet_aton inet_ntoa inet_pton inet_ntop

Modified: pypy/dist/pypy/module/_socket/app_socket.py
==============================================================================
--- pypy/dist/pypy/module/_socket/app_socket.py	(original)
+++ pypy/dist/pypy/module/_socket/app_socket.py	Tue Apr 25 11:13:31 2006
@@ -2,6 +2,8 @@
 
 See the socket module for documentation."""
 
+import _socket
+
 class error(Exception):
     pass
 
@@ -19,4 +21,5 @@
 
 socket = SocketType
 
-
+def gethostbyname(name):
+    return _socket.gethostbyname_ex(name)[2][0]

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	Tue Apr 25 11:13:31 2006
@@ -126,7 +126,7 @@
 		
 def w_makesockaddr(space, caddr, caddrlen, proto):
     if caddr.contents.sa_family == _c.AF_INET:
-        a = cast(caddr, POINTER(_c.sockaddr_in))
+        a = _c.cast(caddr, ctypes.POINTER(_c.sockaddr_in))
         return space.newtuple([space.wrap(_c.inet_ntoa(a.contents.sin_addr)),
                                 space.wrap(_c.ntohs(a.contents.sin_port))])
     else:
@@ -154,7 +154,7 @@
     hostent = _c.gethostbyname(name)
     if not hostent:
         raise  w_get_socketherror(_c.h_errno.value)
-    return space.wrap(hostent.contents.h_name)
+    return space.wrap(hostent.contents.h_addr)
 gethostbyname.unwrap_spec = [ObjSpace, str]
 
 def gethostbyname_ex(space, name):
@@ -172,12 +172,13 @@
              break
          aliases.append(space.wrap(alias))
     address_list = []
-    for addr in hostent.contents.h_addr_list:
-         if addr is None:
+    h_addr_list = ctypes.cast(hostent.contents.h_addr_list, ctypes.POINTER(ctypes.POINTER(_c.in_addr)))
+    for addr in h_addr_list:
+         if not addr:
              break
-         address_list.append(space.wrap(addr))
+         address_list.append(space.wrap(_c.inet_ntoa(addr.contents)))
 
-    return space.newtuple([space.wrap(name), space.newlist(aliases), 
+    return space.newtuple([space.wrap(hostent.contents.h_name), space.newlist(aliases), 
                             space.newlist(address_list)])
 gethostbyname_ex.unwrap_spec = [ObjSpace, str]
     
@@ -566,13 +567,13 @@
         raise OperationError(space.w_TypeError,
                              space.wrap("Int or String expected"))
 
-    res = addrinfo_ptr
-    hints = _c.addrinfo
+    res = _c.addrinfo_ptr()
+    hints = _c.addrinfo()
     hints.ai_flags = flags
     hints.ai_family = family
     hints.ai_socktype = socktype
     hints.ai_protocol = proto
-    retval = _c.getaddrinfo(host, port, pointer(hints), pointer(res))
+    retval = _c.getaddrinfo(host, port, ctypes.pointer(hints), ctypes.pointer(res))
     if retval < 0:
         raise w_get_socketgaierror(_c.gai_strerror(_c.errno), _c.errno.value)
 
@@ -582,14 +583,18 @@
         while next:
             info = next.contents
             next = info.ai_next
-            w_family = space.wrap(info.ai_family.value)
-            w_socktype = space.wrap(info.ai_socktype.value)
-            w_proto = space.wrap(info.ai_protocol.value)
-            w_canonname = space.wrap(info.ai_canonname.value)
-            w_addr = w_makesockaddr(sapce, info.ai_canonname, info.ai_addrlen.value)
-            results.append(space.newtuple([w_family, w_socktype, w_proto,
+            w_family = space.wrap(info.ai_family)
+            w_socktype = space.wrap(info.ai_socktype)
+            w_proto = space.wrap(info.ai_protocol)
+            if info.ai_canonname:
+                w_canonname = space.wrap(info.ai_canonname)
+            else:
+                w_canonname = space.wrap('')
+            w_addr = w_makesockaddr(space, info.ai_addr, info.ai_addrlen,
+                                    info.ai_protocol)
+            result.append(space.newtuple([w_family, w_socktype, w_proto,
                                            w_canonname, w_addr]))
-            return space.newlist(result)
+        return space.newlist(result)
     finally:
         _c.freeaddrinfo(res)
 getaddrinfo.unwrap_spec = [ObjSpace, W_Root, W_Root, int, int, int, int]

Modified: pypy/dist/pypy/rpython/rctypes/socketmodule/ctypes_socket.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/socketmodule/ctypes_socket.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/socketmodule/ctypes_socket.py	Tue Apr 25 11:13:31 2006
@@ -118,7 +118,7 @@
                                       ('h_aliases', POINTER(c_char_p)),
                                       ('h_addrtype', c_int),
                                       ('h_length', c_int),
-                                      ('h_addr_list', POINTER(c_char_p))
+                                      ('h_addr_list', POINTER(POINTER(c_char)))
                                       ])
 
 
@@ -219,6 +219,10 @@
 inet_aton.argtypes = [c_char_p, POINTER(in_addr)]
 inet_aton.restype = c_int
 
+inet_ntoa = socketdll.inet_ntoa
+inet_ntoa.argtypes = [in_addr]
+inet_ntoa.restype = c_char_p
+
 close = socketdll.close
 close.argtypes = [c_int]
 close.restype = c_int

Modified: pypy/dist/pypy/rpython/rctypes/tool/ctypes_platform.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/tool/ctypes_platform.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/tool/ctypes_platform.py	Tue Apr 25 11:13:31 2006
@@ -1,10 +1,12 @@
 #! /usr/bin/env python
 
-import os, py
+import os, py, sys
 import ctypes
 from pypy.translator.tool.cbuild import build_executable
 from pypy.tool.udir import udir
 
+del sys.modules['pypy.tool.udir'] # Don't expose udir
+
 # ____________________________________________________________
 #
 # Helpers for simple cases



More information about the Pypy-commit mailing list