[pypy-svn] r31266 - in pypy/dist/pypy/rpython/rctypes: . test
arigo at codespeak.net
arigo at codespeak.net
Fri Aug 11 19:30:34 CEST 2006
Author: arigo
Date: Fri Aug 11 19:30:32 2006
New Revision: 31266
Modified:
pypy/dist/pypy/rpython/rctypes/rfunc.py
pypy/dist/pypy/rpython/rctypes/test/_rctypes_test.c
pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py
Log:
Bug and fix for indirect calls to functions with no return value.
Modified: pypy/dist/pypy/rpython/rctypes/rfunc.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/rfunc.py (original)
+++ pypy/dist/pypy/rpython/rctypes/rfunc.py Fri Aug 11 19:30:32 2006
@@ -32,8 +32,11 @@
r = rtyper.getrepr(SomeCTypesObject(arg_ctype,
ownsmemory=False))
args_r.append(r)
- r_result = rtyper.getrepr(SomeCTypesObject(self.restype,
- ownsmemory=True))
+ if self.restype is not None:
+ r_result = rtyper.getrepr(SomeCTypesObject(self.restype,
+ ownsmemory=True))
+ else:
+ r_result = None
if isinstance(self.ll_type.TO, lltype.ForwardReference):
FUNCTYPE = get_funcptr_type(args_r, r_result)
self.ll_type.TO.become(FUNCTYPE)
Modified: pypy/dist/pypy/rpython/rctypes/test/_rctypes_test.c
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/test/_rctypes_test.c (original)
+++ pypy/dist/pypy/rpython/rctypes/test/_rctypes_test.c Fri Aug 11 19:30:32 2006
@@ -38,6 +38,14 @@
p->_z++;
}
+EXPORT(void) _testfunc_swap2(point *p)
+{
+ int tmp = p->x;
+ p->x = p->y;
+ p->y = tmp;
+ p->_z += 2;
+}
+
EXPORT(int) _testfunc_struct(point in)
{
return in.x + in.y;
Modified: pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py (original)
+++ pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py Fri Aug 11 19:30:32 2006
@@ -98,6 +98,17 @@
testfunc_swap.llinterp_friendly_version = ll_testfunc_swap
testfunc_swap.includes = includes
+# _testfunc_swap2
+testfunc_swap2 = _rctypes_test._testfunc_swap2
+testfunc_swap2.restype = None
+testfunc_swap2.argtypes = [tagpointptr]
+
+def ll_testfunc_swap2(p):
+ p.c_x, p.c_y = p.c_y, p.c_x
+ p.c__z += 2
+testfunc_swap2.llinterp_friendly_version = ll_testfunc_swap2
+testfunc_swap2.includes = includes
+
# _testfunc_erase_type
testfunc_erase_type = _rctypes_test._testfunc_erase_type
testfunc_erase_type.restype = c_void_p
@@ -199,6 +210,25 @@
res = interpret(test_testfunc_swap, [])
assert res == 4
+ def test_specialize_indirect_call(self):
+ def f(n):
+ pt = tagpoint()
+ pt.x = 5
+ pt.y = 9
+ pt._z = 99
+ if n > 0:
+ f = testfunc_swap
+ else:
+ f = testfunc_swap2
+ f(pointer(pt))
+ assert pt.x == 9
+ assert pt.y == 5
+ return pt._z
+ res = interpret(f, [42])
+ assert res == 100
+ res = interpret(f, [-42])
+ assert res == 101
+
class Test_compile:
def test_compile_byval(self):
fn = compile(test_testfunc_byval, [])
More information about the Pypy-commit
mailing list