[pypy-svn] r59952 - in pypy/branch/oo-jit/pypy/rpython/lltypesystem: . test
arigo at codespeak.net
arigo at codespeak.net
Mon Nov 17 11:38:28 CET 2008
Author: arigo
Date: Mon Nov 17 11:38:26 2008
New Revision: 59952
Modified:
pypy/branch/oo-jit/pypy/rpython/lltypesystem/ll2ctypes.py
pypy/branch/oo-jit/pypy/rpython/lltypesystem/lltype.py
pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
Log:
lltypesystem hack: ll2ctypes...
Modified: pypy/branch/oo-jit/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/branch/oo-jit/pypy/rpython/lltypesystem/ll2ctypes.py (original)
+++ pypy/branch/oo-jit/pypy/rpython/lltypesystem/ll2ctypes.py Mon Nov 17 11:38:26 2008
@@ -442,16 +442,21 @@
raise NotImplementedError("ctypes wrapper for ll function "
"without a _callable")
else:
- v1list = [i for i in range(len(T.TO.ARGS))
- if T.TO.ARGS[i] is lltype.Void]
+ v1voidlist = [(i, getattr(container, '_void' + str(i), None))
+ for i in range(len(T.TO.ARGS))
+ if T.TO.ARGS[i] is lltype.Void]
ctypes_func_type = get_ctypes_type(T)
def callback(*cargs):
cargs = list(cargs)
- for v1 in v1list:
- cargs.insert(v1, None)
+ for v1 in v1voidlist:
+ cargs.insert(v1[0], v1[1])
assert len(cargs) == len(T.TO.ARGS)
- llargs = [ctypes2lltype(ARG, carg)
- for ARG, carg in zip(T.TO.ARGS, cargs)]
+ llargs = []
+ for ARG, carg in zip(T.TO.ARGS, cargs):
+ if ARG is lltype.Void:
+ llargs.append(carg)
+ else:
+ llargs.append(ctypes2lltype(ARG, carg))
llres = container._callable(*llargs)
assert lltype.typeOf(llres) == T.TO.RESULT
if T.TO.RESULT is lltype.Void:
@@ -672,7 +677,7 @@
container_arguments.append(i)
void_arguments = []
for i in range(len(FUNCTYPE.ARGS)):
- if FUNCTYPE.ARGS[i] == lltype.Void:
+ if FUNCTYPE.ARGS[i] is lltype.Void:
void_arguments.append(i)
def invoke_via_ctypes(*argvalues):
cargs = []
Modified: pypy/branch/oo-jit/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/branch/oo-jit/pypy/rpython/lltypesystem/lltype.py (original)
+++ pypy/branch/oo-jit/pypy/rpython/lltypesystem/lltype.py Mon Nov 17 11:38:26 2008
@@ -1083,12 +1083,20 @@
if isinstance(self._T, FuncType):
if len(args) != len(self._T.ARGS):
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 and ARG != Void:
+ for i, a, ARG in zip(range(len(self._T.ARGS)), args, self._T.ARGS):
+ if typeOf(a) != ARG:
+ # ARG could be Void
+ if ARG == Void:
+ try:
+ value = getattr(self._obj, '_void' + str(i))
+ except AttributeError:
+ pass
+ else:
+ assert a == value
# 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)
+ elif not (isinstance(ARG, ContainerType)
and typeOf(a) == Ptr(ARG)):
args_repr = [typeOf(arg) for arg in args]
raise TypeError, ("calling %r with wrong argument "
Modified: pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
==============================================================================
--- pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py (original)
+++ pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py Mon Nov 17 11:38:26 2008
@@ -870,9 +870,12 @@
def f(x):
ftest.append(x)
F = lltype.FuncType([lltype.Void], lltype.Void)
- fn = lltype.functionptr(F, 'askjh', _callable=f)
+ fn = lltype.functionptr(F, 'askjh', _callable=f, _void0=-5)
fn(-5)
assert ftest == [-5]
fn2 = lltype2ctypes(fn)
fn2()
- assert ftest == [-5, None]
+ assert ftest == [-5, -5]
+ fn3 = ctypes2lltype(lltype.Ptr(F), fn2)
+ fn3(-5)
+ assert ftest == [-5, -5, -5]
More information about the Pypy-commit
mailing list