5454import_dict = {}
5555# gr_domains.rst lists functions that are in gr.h
5656doc_to_header = {'flint/gr_domains' : 'flint/gr' }
57+ void_parameter_list = re .compile (r"\(\s*void\s*\)$" )
58+ macro_declarations = {
59+ 'flint/arf' : {
60+ 'ARF_PREC_EXACT' : 'cdef const slong ARF_PREC_EXACT' ,
61+ },
62+ }
5763
5864
5965
@@ -115,6 +121,8 @@ def clean_types(function):
115121 ret = function .strip ()
116122 for old , new in rename_types :
117123 ret = re .sub (old , new , ret )
124+ # Cython expects zero-argument functions to use () rather than (void).
125+ ret = re .sub (void_parameter_list , "()" , ret )
118126 return ret
119127
120128
@@ -197,6 +205,12 @@ def generate_pxd_file(h_name, opts):
197205 with open (os .path .join (docdir , name + ".rst" )) as f :
198206 l , macros = get_functions (f )
199207 unknown_types = gen_imports (l )
208+ macro_defs = []
209+ declared_macros = macro_declarations .get (h_name , {})
210+ for macro in macros :
211+ macro_name = macro .split ("::" , 1 )[1 ].strip ()
212+ if macro_name in declared_macros :
213+ macro_defs .append (declared_macros [macro_name ])
200214 print ()
201215 for t in unknown_types :
202216 print ("# unknown type " + t )
@@ -205,6 +219,8 @@ def generate_pxd_file(h_name, opts):
205219 print ("# " + m )
206220 print ()
207221 print (r'cdef extern from "' + h_name + r'.h":' )
222+ for declaration in macro_defs :
223+ print (" " + declaration )
208224 for f in l :
209225 if has_types (f , unknown_types ):
210226 print (" # " + f )
0 commit comments