[pypy-svn] r73459 - in pypy/branch/cpython-extension/pypy/rpython/lltypesystem: . test
afa at codespeak.net
afa at codespeak.net
Tue Apr 6 17:26:53 CEST 2010
Author: afa
Date: Tue Apr 6 17:26:51 2010
New Revision: 73459
Modified:
pypy/branch/cpython-extension/pypy/rpython/lltypesystem/ll2ctypes.py
pypy/branch/cpython-extension/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
Log:
ll2ctypes should accept all arguments passed to the call.
This is needed by METH_KEYWORDS functions, which take 3 PyObjects*,
but are cast to a PyCFunction taking 2 PyObjects*.
Modified: pypy/branch/cpython-extension/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/lltypesystem/ll2ctypes.py (original)
+++ pypy/branch/cpython-extension/pypy/rpython/lltypesystem/ll2ctypes.py Tue Apr 6 17:26:51 2010
@@ -964,7 +964,7 @@
def invoke_via_ctypes(*argvalues):
global _callback_exc_info
cargs = []
- for i in range(len(FUNCTYPE.ARGS)):
+ for i in range(len(argvalues)):
if i not in void_arguments:
cvalue = lltype2ctypes(argvalues[i])
if i in container_arguments:
Modified: pypy/branch/cpython-extension/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/lltypesystem/test/test_ll2ctypes.py (original)
+++ pypy/branch/cpython-extension/pypy/rpython/lltypesystem/test/test_ll2ctypes.py Tue Apr 6 17:26:51 2010
@@ -432,6 +432,29 @@
rffi.free_charp(p)
assert not ALLOCATED # detects memory leaks in the test
+ def test_funcptr_cast(self):
+ eci = ExternalCompilationInfo(
+ separate_module_sources=["""
+ long mul(long x, long y) { return x*y; }
+ long(*get_mul(long x)) () { return &mul; }
+ """],
+ export_symbols=['get_mul'])
+ get_mul = rffi.llexternal(
+ 'get_mul', [],
+ lltype.Ptr(lltype.FuncType([lltype.Signed], lltype.Signed)),
+ compilation_info=eci)
+ # This call returns a pointer to a function taking one argument
+ funcptr = get_mul()
+ # cast it to the "real" function type
+ FUNCTYPE2 = lltype.FuncType([lltype.Signed, lltype.Signed],
+ lltype.Signed)
+ cmul = rffi.cast(lltype.Ptr(FUNCTYPE2), funcptr)
+ # and it can be called with the expected number of arguments
+ res = cmul(41, 42)
+ assert res == 41 * 42
+ raises(TypeError, cmul, 41)
+ raises(TypeError, cmul, 41, 42, 43)
+
def test_qsort(self):
CMPFUNC = lltype.FuncType([rffi.VOIDP, rffi.VOIDP], rffi.INT)
qsort = rffi.llexternal('qsort', [rffi.VOIDP,
More information about the Pypy-commit
mailing list