[pypy-svn] r46765 - in pypy/dist/pypy: rlib rlib/test rpython/lltypesystem
arigo at codespeak.net
arigo at codespeak.net
Thu Sep 20 15:32:35 CEST 2007
Author: arigo
Date: Thu Sep 20 15:32:33 2007
New Revision: 46765
Modified:
pypy/dist/pypy/rlib/rsocket_rffi.py
pypy/dist/pypy/rlib/test/test_rsocket_rffi.py
pypy/dist/pypy/rpython/lltypesystem/rffi.py
Log:
inet_aton() and maybe inet_ntoa() but the latter is not tested
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 15:32:33 2007
@@ -1097,34 +1097,47 @@
if hasattr(_c, 'inet_aton'):
def inet_aton(ip):
"IPv4 dotted string -> packed 32-bits string"
- buf = create_string_buffer(sizeof(_c.in_addr))
- if _c.inet_aton(ip, cast(buf, POINTER(_c.in_addr))):
- return buf.raw
- else:
- raise RSocketError("illegal IP address string passed to inet_aton")
+ size = sizeof(_c.in_addr)
+ buf = mallocbuf(size)
+ try:
+ if _c.inet_aton(ip, rffi.cast(lltype.Ptr(_c.in_addr), buf)):
+ return ''.join([buf[i] for i in range(size)])
+ else:
+ raise RSocketError("illegal IP address string passed to inet_aton")
+ finally:
+ lltype.free(buf, flavor='raw')
else:
def inet_aton(ip):
"IPv4 dotted string -> packed 32-bits string"
if ip == "255.255.255.255":
return "\xff\xff\xff\xff"
packed_addr = _c.inet_addr(ip)
- if _c.c_long(packed_addr).value == INADDR_NONE:
+ if packed_addr == rffi.cast(rffi.UINT, INADDR_NONE):
raise RSocketError("illegal IP address string passed to inet_aton")
- buf = copy_buffer(cast(pointer(c_ulong(packed_addr)),
- POINTER(c_char)), 4)
- return buf.raw
+ size = sizeof(_c.in_addr)
+ buf = mallocbuf(size)
+ try:
+ rffi.cast(rffi.UINTP, buf)[0] = packed_addr
+ return ''.join([buf[i] for i in range(size)])
+ finally:
+ lltype.free(buf, flavor='raw')
def inet_ntoa(packed):
"packet 32-bits string -> IPv4 dotted string"
if len(packed) != sizeof(_c.in_addr):
raise RSocketError("packed IP wrong length for inet_ntoa")
- buf = create_string_buffer(sizeof(_c.in_addr))
- buf.raw = packed
- return _c.inet_ntoa(cast(buf, POINTER(_c.in_addr)).contents)
+ buf = rffi.make(_c.in_addr)
+ try:
+ for i in range(sizeof(_c.in_addr)):
+ rffi.cast(rffi.CCHARP, buf)[i] = packed[i]
+ return _c.inet_ntoa(buf)
+ finally:
+ lltype.free(buf, flavor='raw')
if hasattr(_c, 'inet_pton'):
def inet_pton(family, ip):
"human-readable string -> packed string"
+ XXX
if family == AF_INET:
size = sizeof(_c.in_addr)
elif AF_INET6 is not None and family == AF_INET6:
@@ -1143,6 +1156,7 @@
if hasattr(_c, 'inet_ntop'):
def inet_ntop(family, packed):
"packed string -> human-readable string"
+ XXX
if family == AF_INET:
srcsize = sizeof(_c.in_addr)
dstsize = _c.INET_ADDRSTRLEN
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 15:32:33 2007
@@ -258,7 +258,6 @@
assert s.getsockname().eq(s2.getsockname())
def test_inet_aton():
- py.test.skip("in-progress")
assert inet_aton('1.2.3.4') == '\x01\x02\x03\x04'
assert inet_aton('127.0.0.1') == '\x7f\x00\x00\x01'
tests = ["127.0.0.256", "127.0.0.255555555555555555", "127.2b.0.0",
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 15:32:33 2007
@@ -147,6 +147,8 @@
tp = platform.inttype(name.upper(), c_name, signed)
globals()['r_' + name] = platform.numbertype_to_rclass[tp]
globals()[name.upper()] = tp
+ tpp = lltype.Ptr(lltype.Array(tp, hints={'nolength': True}))
+ globals()[name.upper()+'P'] = tpp
result.append(tp)
return result
@@ -259,8 +261,8 @@
# char *
CCHARP = lltype.Ptr(lltype.Array(lltype.Char, hints={'nolength': True}))
-# int *
-INTP = lltype.Ptr(lltype.Array(lltype.Signed, hints={'nolength': True}))
+# int *, unsigned int *, etc.
+#INTP = ... see setup() above
# double *
DOUBLEP = lltype.Ptr(lltype.Array(DOUBLE, hints={'nolength': True}))
More information about the Pypy-commit
mailing list