[pypy-svn] r46766 - in pypy/dist/pypy: rlib rlib/test rpython/lltypesystem rpython/lltypesystem/test
arigo at codespeak.net
arigo at codespeak.net
Thu Sep 20 15:47:17 CEST 2007
Author: arigo
Date: Thu Sep 20 15:47:16 2007
New Revision: 46766
Modified:
pypy/dist/pypy/rlib/rsocket_rffi.py
pypy/dist/pypy/rlib/test/test_rsocket_rffi.py
pypy/dist/pypy/rpython/lltypesystem/ll2ctypes.py
pypy/dist/pypy/rpython/lltypesystem/lltype.py
pypy/dist/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
pypy/dist/pypy/rpython/lltypesystem/test/test_rffi.py
Log:
Test and fix inet_ntoa().
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:47:16 2007
@@ -1130,7 +1130,7 @@
try:
for i in range(sizeof(_c.in_addr)):
rffi.cast(rffi.CCHARP, buf)[i] = packed[i]
- return _c.inet_ntoa(buf)
+ return rffi.charp2str(_c.inet_ntoa(buf))
finally:
lltype.free(buf, flavor='raw')
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:47:16 2007
@@ -272,7 +272,10 @@
assert inet_aton(ip) == aton
except SocketError:
pass
-
+
+def test_inet_ntoa():
+ assert inet_ntoa('\x01\x02\x03\x04') == '1.2.3.4'
+
class TestTCP:
PORT = 50007
HOST = 'localhost'
Modified: pypy/dist/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/ll2ctypes.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/ll2ctypes.py Thu Sep 20 15:47:16 2007
@@ -533,8 +533,14 @@
def get_ctypes_trampoline(FUNCTYPE, cfunc):
RESULT = FUNCTYPE.RESULT
+ container_arguments = []
+ for i in range(len(FUNCTYPE.ARGS)):
+ if isinstance(FUNCTYPE.ARGS[i], lltype.ContainerType):
+ container_arguments.append(i)
def invoke_via_ctypes(*argvalues):
cargs = [lltype2ctypes(value) for value in argvalues]
+ for i in container_arguments:
+ cargs[i] = cargs[i].contents
_restore_c_errno()
cres = cfunc(*cargs)
_save_c_errno()
Modified: pypy/dist/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/lltype.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/lltype.py Thu Sep 20 15:47:16 2007
@@ -1100,8 +1100,14 @@
raise TypeError,"calling %r with wrong argument number: %r" % (self._T, args)
for a, ARG in zip(args, self._T.ARGS):
if typeOf(a) != ARG:
- args_repr = [typeOf(arg) for arg in args]
- raise TypeError,"calling %r with wrong argument types: %r" % (self._T, args_repr)
+ # special case: ARG can be a container type, in which
+ # case a should be a pointer to it. This must also be
+ # special-cased in the backends.
+ if not (isinstance(ARG, ContainerType)
+ and typeOf(a) == Ptr(ARG)):
+ args_repr = [typeOf(arg) for arg in args]
+ raise TypeError, ("calling %r with wrong argument "
+ "types: %r" % (self._T, args_repr))
callb = self._obj._callable
if callb is None:
raise RuntimeError,"calling undefined function"
Modified: pypy/dist/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/test/test_ll2ctypes.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/test/test_ll2ctypes.py Thu Sep 20 15:47:16 2007
@@ -537,3 +537,15 @@
err = rffi.get_errno()
import errno
assert err == errno.EBADF
+
+ def test_call_with_struct_argument(self):
+ # XXX is there such a function in the standard C headers?
+ from pypy.rlib import _rsocket_rffi
+ buf = rffi.make(_rsocket_rffi.in_addr)
+ rffi.cast(rffi.CCHARP, buf)[0] = '\x01'
+ rffi.cast(rffi.CCHARP, buf)[1] = '\x02'
+ rffi.cast(rffi.CCHARP, buf)[2] = '\x03'
+ rffi.cast(rffi.CCHARP, buf)[3] = '\x04'
+ p = _rsocket_rffi.inet_ntoa(buf)
+ assert rffi.charp2str(p) == '1.2.3.4'
+ lltype.free(buf, flavor='raw')
Modified: pypy/dist/pypy/rpython/lltypesystem/test/test_rffi.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/test/test_rffi.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/test/test_rffi.py Thu Sep 20 15:47:16 2007
@@ -124,9 +124,9 @@
return (z->one + z->three);
}
"""
- TP = CStructPtr('xx', ('one', Signed), ('two', Char), ('three', Signed))
+ TP = CStructPtr('xx', ('one', INT), ('two', Char), ('three', INT))
- z = llexternal('f', [TP], Signed, sources=[c_source],
+ z = llexternal('f', [TP], INT, sources=[c_source],
includes=[str(h_file)], include_dirs=[udir])
def f():
More information about the Pypy-commit
mailing list