@@ -62,8 +62,14 @@ def get_cython_struct_types(file):
6262 l = line .strip ()
6363 if l [:8 ] == "ctypedef" :
6464 if l [- 1 ] == ']' :
65+ # ctypedef foo foo_t[0]
6566 l = l [:l .rfind ('[' )]
67+ elif '(' in l :
68+ # ctypedef int (*foo_func)(...)
69+ l = l [l .index ('(' ):].lstrip ('(*' )
70+ l = l [:l .index (')' )]
6671 else :
72+ # ctypedef foo:
6773 l = l .strip (':' )
6874 ret .append (l .split ()[- 1 ])
6975 return ret
@@ -72,12 +78,14 @@ def fill_import_dict(pyflintlibdir):
7278 """
7379 Get a map from cython structs to the pxd that defines them
7480 """
75- with os .scandir (pyflintlibdir ) as entry :
81+ import_dict ['fmpq_struct' ] = 'types.fmpq'
82+
83+ with os .scandir (pyflintlibdir + '/types' ) as entry :
7684 for f in entry :
7785 if fnmatch .fnmatch (f .name , "*.pxd" ):
7886 with open (f .path ) as pxd :
7987 for t in get_cython_struct_types (pxd ):
80- import_dict [t ] = f .name .split ('.' )[0 ]
88+ import_dict [t ] = 'types.' + f .name .split ('.' )[0 ]
8189
8290def undecorate (str ):
8391 """
@@ -86,12 +94,13 @@ def undecorate(str):
8694 ret = str .strip ()
8795 if ' ' in ret :
8896 ret = ret [:ret .rfind (' ' )]
89- ret = re .sub (type_modifers , '' , ret )
90- return ret . strip ()
97+ ret = re .sub (type_modifers , '' , ret ). strip ()
98+ return ret
9199
92100def get_parameter_types (str ):
93101 params = str [str .find ("(" ) + 1 : str .rfind (")" )].split ("," )
94- params .append (str .split ()[0 ])
102+ ret_type = str .split ('(' )[0 ].rsplit (' ' , 1 )[0 ]
103+ params .append (ret_type )
95104 return [undecorate (s ) for s in params if s ]
96105
97106def clean_types (function ):
0 commit comments