Author: Antonio Cuni <anto.c...@gmail.com> Branch: reflex-support Changeset: r46886:7fcfab9f332d Date: 2011-08-29 15:46 +0200 http://bitbucket.org/pypy/pypy/changeset/7fcfab9f332d/
Log: test and fix for issue 850 diff --git a/lib_pypy/_ctypes/structure.py b/lib_pypy/_ctypes/structure.py --- a/lib_pypy/_ctypes/structure.py +++ b/lib_pypy/_ctypes/structure.py @@ -169,6 +169,8 @@ def from_address(self, address): instance = StructOrUnion.__new__(self) + if isinstance(address, _rawffi.StructureInstance): + address = address.buffer instance.__dict__['_buffer'] = self._ffistruct.fromaddress(address) return instance diff --git a/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c b/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c --- a/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c +++ b/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c @@ -481,6 +481,16 @@ int a, b, c, d, e, f, g, h; } S8I; + + +typedef int (*CALLBACK_RECT)(RECT rect); + +EXPORT(int) call_callback_with_rect(CALLBACK_RECT cb, RECT rect) +{ + return cb(rect); +} + + EXPORT(S8I) ret_8i_func(S8I inp) { inp.a *= 2; diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_callbacks.py b/pypy/module/test_lib_pypy/ctypes_tests/test_callbacks.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_callbacks.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_callbacks.py @@ -166,6 +166,28 @@ assert res == 1111 + def test_callback_from_c_with_struct_argument(self): + import conftest + _ctypes_test = str(conftest.sofile) + dll = CDLL(_ctypes_test) + + class RECT(Structure): + _fields_ = [("left", c_long), ("top", c_long), + ("right", c_long), ("bottom", c_long)] + + proto = CFUNCTYPE(c_int, RECT) + def callback(point): + return point.left+point.top+point.right+point.bottom + + cbp = proto(callback) + rect = RECT(1000,100,10,1) + + call_callback_with_rect = dll.call_callback_with_rect + call_callback_with_rect.restype = c_int + call_callback_with_rect.argtypes = [proto, RECT] + res = call_callback_with_rect(cbp, rect) + assert res == 1111 + def test_callback_unsupported_return_struct(self): class RECT(Structure): _fields_ = [("left", c_int), ("top", c_int), _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit