Author: Armin Rigo <[email protected]>
Branch:
Changeset: r879:b96cdee5a739
Date: 2012-08-23 15:45 +0200
http://bitbucket.org/cffi/cffi/changeset/b96cdee5a739/
Log: Add another test, passing a bigger struct to a function.
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -4204,6 +4204,21 @@
return ptr->a1 + ptr->a2;
}
+struct _testfunc21_s { int a, b, c, d, e, f, g, h, i, j; };
+static int _testfunc21(struct _testfunc21_s inlined)
+{
+ return ((inlined.a << 0) +
+ (inlined.b << 1) +
+ (inlined.c << 2) +
+ (inlined.d << 3) +
+ (inlined.e << 4) +
+ (inlined.f << 5) +
+ (inlined.g << 6) +
+ (inlined.h << 7) +
+ (inlined.i << 8) +
+ (inlined.j << 9));
+}
+
static PyObject *b__testfunc(PyObject *self, PyObject *args)
{
/* for testing only */
@@ -4233,6 +4248,7 @@
case 18: f = &_testfunc18; break;
case 19: f = &_testfunc19; break;
case 20: f = &_testfunc20; break;
+ case 21: f = &_testfunc21; break;
default:
PyErr_SetNone(PyExc_ValueError);
return NULL;
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -886,8 +886,8 @@
BStructPtr = new_pointer_type(BStruct)
complete_struct_or_union(BStruct, [('a1', BChar, -1),
('a2', BShort, -1)])
- BFunc18 = new_function_type((BStructPtr,), BShort, False)
- f = cast(BFunc18, _testfunc(20))
+ BFunc20 = new_function_type((BStructPtr,), BShort, False)
+ f = cast(BFunc20, _testfunc(20))
x = newp(BStructPtr, {'a1': b'A', 'a2': -4042})
# test the exception that allows us to pass a 'struct foo' where the
# function really expects a 'struct foo *'.
@@ -895,6 +895,25 @@
assert res == -4042 + ord(b'A')
assert res == f(x)
+def test_call_function_21():
+ BInt = new_primitive_type("int")
+ BStruct = new_struct_type("foo")
+ complete_struct_or_union(BStruct, [('a', BInt, -1),
+ ('b', BInt, -1),
+ ('c', BInt, -1),
+ ('d', BInt, -1),
+ ('e', BInt, -1),
+ ('f', BInt, -1),
+ ('g', BInt, -1),
+ ('h', BInt, -1),
+ ('i', BInt, -1),
+ ('j', BInt, -1)])
+ BFunc21 = new_function_type((BStruct,), BInt, False)
+ f = cast(BFunc21, _testfunc(21))
+ res = f(range(13, 3, -1))
+ lst = [(n << i) for (i, n) in enumerate(range(13, 3, -1))]
+ assert res == sum(lst)
+
def test_call_function_9():
BInt = new_primitive_type("int")
BFunc9 = new_function_type((BInt,), BInt, True) # vararg
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit