[pypy-svn] r46769 - in pypy/dist/pypy: rlib rlib/test rpython/lltypesystem
arigo at codespeak.net
arigo at codespeak.net
Thu Sep 20 16:46:50 CEST 2007
Author: arigo
Date: Thu Sep 20 16:46:49 2007
New Revision: 46769
Modified:
pypy/dist/pypy/rlib/_rsocket_rffi.py
pypy/dist/pypy/rlib/rsocket_rffi.py
pypy/dist/pypy/rlib/test/test_rsocket_rffi.py
pypy/dist/pypy/rpython/lltypesystem/rffi.py
Log:
gethostbyname_ex() test and fix.
Modified: pypy/dist/pypy/rlib/_rsocket_rffi.py
==============================================================================
--- pypy/dist/pypy/rlib/_rsocket_rffi.py (original)
+++ pypy/dist/pypy/rlib/_rsocket_rffi.py Thu Sep 20 16:46:49 2007
@@ -236,7 +236,7 @@
('h_aliases', rffi.CCHARPP),
('h_addrtype', rffi.INT),
('h_length', rffi.INT),
- ('h_addr_list', rffi.VOIDP),
+ ('h_addr_list', rffi.CCHARPP),
])
Modified: pypy/dist/pypy/rlib/rsocket_rffi.py
==============================================================================
--- pypy/dist/pypy/rlib/rsocket_rffi.py (original)
+++ pypy/dist/pypy/rlib/rsocket_rffi.py Thu Sep 20 16:46:49 2007
@@ -981,37 +981,33 @@
def gethost_common(hostname, hostent, addr=None):
if not hostent:
raise HSocketError(hostname)
- family = hostent.contents.h_addrtype
+ family = hostent.c_h_addrtype
if addr is not None and addr.family != family:
raise CSocketError(_c.EAFNOSUPPORT)
- aliases = []
- h_aliases = hostent.contents.h_aliases
+ h_aliases = hostent.c_h_aliases
if h_aliases: # h_aliases can be NULL, according to SF #1511317
- i = 0
- alias = h_aliases[0]
- while alias is not None:
- aliases.append(alias)
- i += 1
- alias = h_aliases[i]
+ aliases = rffi.charpp2liststr(h_aliases)
+ else:
+ aliases = []
address_list = []
- h_addr_list = hostent.contents.h_addr_list
+ h_addr_list = hostent.c_h_addr_list
i = 0
paddr = h_addr_list[0]
while paddr:
if family == AF_INET:
- p = cast(paddr, POINTER(_c.in_addr))
- addr = INETAddress.from_in_addr(p.contents)
+ p = rffi.cast(lltype.Ptr(_c.in_addr), paddr)
+ addr = INETAddress.from_in_addr(p)
elif AF_INET6 is not None and family == AF_INET6:
- p = cast(paddr, POINTER(_c.in6_addr))
- addr = INET6Address.from_in6_addr(p.contents)
+ p = cast(lltype.Ptr(_c.in6_addr), paddr)
+ addr = INET6Address.from_in6_addr(p)
else:
raise RSocketError("unknown address family")
address_list.append(addr)
i += 1
paddr = h_addr_list[i]
- return (hostent.contents.h_name, aliases, address_list)
+ return (rffi.charp2str(hostent.c_h_name), aliases, address_list)
def gethostbyname_ex(name):
# XXX use gethostbyname_r() if available, and/or use locks if not
Modified: pypy/dist/pypy/rlib/test/test_rsocket_rffi.py
==============================================================================
--- pypy/dist/pypy/rlib/test/test_rsocket_rffi.py (original)
+++ pypy/dist/pypy/rlib/test/test_rsocket_rffi.py Thu Sep 20 16:46:49 2007
@@ -43,6 +43,19 @@
assert isinstance(a, INETAddress)
assert a.get_host() == "127.0.0.1"
+def test_gethostbyname_ex():
+ name, aliases, address_list = gethostbyname_ex('localhost')
+ allnames = [name] + aliases
+ for n in allnames:
+ assert isinstance(n, str)
+ assert 'localhost' in allnames
+ for a in address_list:
+ if isinstance(a, INETAddress) and a.get_host() == "127.0.0.1":
+ break # ok
+ else:
+ py.test.fail("could not find the 127.0.0.1 IPv4 address in %r"
+ % (address_list,))
+
def test_socketpair():
if sys.platform == "win32":
py.test.skip('No socketpair on Windows')
Modified: pypy/dist/pypy/rpython/lltypesystem/rffi.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rffi.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/rffi.py Thu Sep 20 16:46:49 2007
@@ -321,6 +321,16 @@
i += 1
lltype.free(ref, flavor='raw')
+def charpp2liststr(p):
+ """ char** NULL terminated -> list[str]. No freeing is done.
+ """
+ result = []
+ i = 0
+ while p[i]:
+ result.append(charp2str(p[i]))
+ i += 1
+ return result
+
cast = ll2ctypes.force_cast # a forced, no-checking cast
More information about the Pypy-commit
mailing list