Author: Armin Rigo <[email protected]>
Branch: static-callback
Changeset: r2382:414c0306b311
Date: 2015-11-13 13:30 +0100
http://bitbucket.org/cffi/cffi/changeset/414c0306b311/
Log: Pass and return structs
diff --git a/cffi/recompiler.py b/cffi/recompiler.py
--- a/cffi/recompiler.py
+++ b/cffi/recompiler.py
@@ -1163,12 +1163,21 @@
# Write the implementation of the functions declared above
for j in range(len(self._callpy)):
tp, name = self._callpy[j]
+ size_of_a = max(len(tp.args), 1)
+ if isinstance(tp.result, model.StructOrUnion):
+ size_of_a = 'sizeof(%s) > %d ? (sizeof(%s) + 7) / 8 : %d' % (
+ tp.result.get_c_name(''), 8 * size_of_a,
+ tp.result.get_c_name(''), size_of_a)
prnt('static %s' % function_sigs[j])
prnt('{')
- prnt(' uint64_t a[%d];' % max(len(tp.args), 1))
+ prnt(' uint64_t a[%s];' % size_of_a)
prnt(' char *p = (char *)a;')
for i, type in enumerate(tp.args):
- prnt(' *(%s)(p + %d) = a%d;' % (type.get_c_name('*'), i*8, i))
+ arg = 'a%d' % i
+ if isinstance(type, model.StructOrUnion):
+ arg = '&' + arg
+ type = model.PointerType(type)
+ prnt(' *(%s)(p + %d) = %s;' % (type.get_c_name('*'), i*8,
arg))
prnt(' _cffi_call_python(_cffi_callpys + %d, p);' % j)
if not isinstance(tp.result, model.VoidType):
prnt(' return *(%s)p;' % (tp.result.get_c_name('*'),))
diff --git a/testing/cffi1/test_recompiler.py b/testing/cffi1/test_recompiler.py
--- a/testing/cffi1/test_recompiler.py
+++ b/testing/cffi1/test_recompiler.py
@@ -1495,3 +1495,15 @@
""")
lib = verify(ffi, 'test_call_python_1', "")
XXX
+
+def test_call_python_2():
+ ffi = FFI()
+ ffi.cdef("""
+ struct foo_s { int a, b, c; };
+ CFFI_CALL_PYTHON int bar(int, struct foo_s, int);
+ CFFI_CALL_PYTHON struct foo_s baz(int, int);
+ CFFI_CALL_PYTHON struct foo_s bok(void);
+ """)
+ lib = verify(ffi, 'test_call_python_2',
+ "struct foo_s { int a, b, c; };")
+ XXX
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit