[pypy-commit] cffi default: issue #189: typedefs of function type (not function pointer)
arigo
noreply at buildbot.pypy.org
Wed Apr 15 09:44:42 CEST 2015
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r1710:44de16be9be5
Date: 2015-04-15 09:43 +0200
http://bitbucket.org/cffi/cffi/changeset/44de16be9be5/
Log: issue #189: typedefs of function type (not function pointer)
diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -266,7 +266,10 @@
#
if decl.name:
tp = self._get_type(node, partial_length_ok=True)
- if self._is_constant_globalvar(node):
+ if tp.is_raw_function:
+ tp = self._get_type_pointer(tp)
+ self._declare('function ' + decl.name, tp)
+ elif self._is_constant_globalvar(node):
self._declare('constant ' + decl.name, tp)
else:
self._declare('variable ' + decl.name, tp)
diff --git a/testing/test_function.py b/testing/test_function.py
--- a/testing/test_function.py
+++ b/testing/test_function.py
@@ -292,7 +292,6 @@
assert ffi.string(a) == b'4.4.4.4'
def test_function_typedef(self):
- py.test.skip("using really obscure C syntax")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
typedef double func_t(double);
diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -1197,6 +1197,15 @@
""")
assert lib.foo_func(lib.BB) == lib.BB == 2
+def test_function_typedef():
+ ffi = FFI()
+ ffi.cdef("""
+ typedef double func_t(double);
+ func_t sin;
+ """)
+ lib = ffi.verify('#include <math.h>', libraries=lib_m)
+ assert lib.sin(1.23) == math.sin(1.23)
+
def test_callback_calling_convention():
py.test.skip("later")
if sys.platform != 'win32':
More information about the pypy-commit
mailing list