Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r78249:e8bd7b84971b Date: 2015-06-23 09:28 +0200 http://bitbucket.org/pypy/pypy/changeset/e8bd7b84971b/
Log: Test and fix: ffi.addressof(lib, 'func-with-struct-args') would return a badly typed cdata object diff --git a/pypy/module/_cffi_backend/lib_obj.py b/pypy/module/_cffi_backend/lib_obj.py --- a/pypy/module/_cffi_backend/lib_obj.py +++ b/pypy/module/_cffi_backend/lib_obj.py @@ -237,7 +237,7 @@ if isinstance(w_value, W_FunctionWrapper): # '&func' returns a regular cdata pointer-to-function if w_value.directfnptr: - ctype = w_value.rawfunctype.nostruct_ctype + ctype = w_value.typeof(self.ffi) return W_CData(space, w_value.directfnptr, ctype) else: return w_value # backward compatibility diff --git a/pypy/module/_cffi_backend/test/test_recompiler.py b/pypy/module/_cffi_backend/test/test_recompiler.py --- a/pypy/module/_cffi_backend/test/test_recompiler.py +++ b/pypy/module/_cffi_backend/test/test_recompiler.py @@ -828,6 +828,22 @@ assert isinstance(addr, ffi.CData) assert ffi.typeof(addr) == ffi.typeof("long(*)(long)") + def test_address_of_function_with_struct(self): + ffi, lib = self.prepare( + "struct foo_s { int x; }; long myfunc(struct foo_s);", + "test_addressof_function_with_struct", """ + struct foo_s { int x; }; + char myfunc(struct foo_s input) { return (char)(input.x + 42); } + """) + s = ffi.new("struct foo_s *", [5])[0] + assert lib.myfunc(s) == 47 + assert not isinstance(lib.myfunc, ffi.CData) + assert ffi.typeof(lib.myfunc) == ffi.typeof("long(*)(struct foo_s)") + addr = ffi.addressof(lib, 'myfunc') + assert addr(s) == 47 + assert isinstance(addr, ffi.CData) + assert ffi.typeof(addr) == ffi.typeof("long(*)(struct foo_s)") + def test_issue198(self): ffi, lib = self.prepare(""" typedef struct{...;} opaque_t; _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit