Skip to content

Commit 829af94

Browse files
committed
Fix rst_to_pxd.py for (void) parameter and macros
1 parent 63a3480 commit 829af94

5 files changed

Lines changed: 37 additions & 21 deletions

File tree

bin/rst_to_pxd.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
import_dict = {}
5555
# gr_domains.rst lists functions that are in gr.h
5656
doc_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)

src/flint/flintlib/functions/flint.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ cdef extern from "flint/flint.h":
2929
void flint_rand_init(flint_rand_t state)
3030
void flint_rand_clear(flint_rand_t state)
3131
void flint_set_num_threads(int num_threads)
32-
# int flint_get_num_threads(void)
32+
int flint_get_num_threads()
3333
int flint_set_num_workers(int num_workers)
3434
void flint_reset_num_workers(int num_workers)
3535
# int flint_printf(const char * format, ...)
@@ -40,7 +40,7 @@ cdef extern from "flint/flint.h":
4040
# int flint_scanf(const char * str, ...)
4141
# int flint_fscanf(FILE * f, const char * str, ...)
4242
# int flint_sscanf(const char * s, const char * str, ...)
43-
# void flint_abort(void)
43+
void flint_abort()
4444
# void flint_throw(flint_err_t exc, const char * msg, ...)
4545
# void flint_set_abort(void (* func)(void))
4646
# void flint_set_throw(void (* func)(flint_err_t, const char *, va_list))

src/flint/flintlib/functions/fmpz.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ from flint.flintlib.types.fmpz cimport fmpz_factor_t, fmpz_preinvn_t
2020
cdef extern from "flint/fmpz.h":
2121
# fmpz_struct PTR_TO_COEFF(mpz_ptr ptr)
2222
# mpz_ptr COEFF_TO_PTR(fmpz_struct f)
23-
# mpz_ptr _fmpz_new_mpz(void)
23+
# mpz_ptr _fmpz_new_mpz()
2424
void _fmpz_clear_mpz(fmpz_struct f)
2525
void _fmpz_cleanup_mpz_content()
2626
void _fmpz_cleanup()

src/flint/flintlib/functions/gr_generic.pxd

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ from flint.flintlib.types.gr cimport gr_ctx_t, gr_ptr, gr_srcptr, gr_stream_t, g
88
# .. macro :: GR_PARSE_RING_EXPONENTS
99

1010
cdef extern from "flint/gr_generic.h":
11-
void gr_generic_init(void)
12-
void gr_generic_clear(void)
13-
void gr_generic_swap(void)
14-
void gr_generic_randtest(void)
15-
void gr_generic_write(void)
16-
void gr_generic_zero(void)
17-
void gr_generic_one(void)
18-
void gr_generic_equal(void)
19-
void gr_generic_set(void)
20-
void gr_generic_set_si(void)
21-
void gr_generic_set_ui(void)
22-
void gr_generic_set_fmpz(void)
23-
void gr_generic_neg(void)
24-
void gr_generic_add(void)
25-
void gr_generic_sub(void)
26-
void gr_generic_mul(void)
11+
void gr_generic_init()
12+
void gr_generic_clear()
13+
void gr_generic_swap()
14+
void gr_generic_randtest()
15+
void gr_generic_write()
16+
void gr_generic_zero()
17+
void gr_generic_one()
18+
void gr_generic_equal()
19+
void gr_generic_set()
20+
void gr_generic_set_si()
21+
void gr_generic_set_ui()
22+
void gr_generic_set_fmpz()
23+
void gr_generic_neg()
24+
void gr_generic_add()
25+
void gr_generic_sub()
26+
void gr_generic_mul()
2727
void gr_generic_ctx_clear(gr_ctx_t ctx)
2828
void gr_generic_set_shallow(gr_ptr res, gr_srcptr x, const gr_ctx_t ctx)
2929
int gr_generic_write_n(gr_stream_t out, gr_srcptr x, slong n, gr_ctx_t ctx)

src/flint/flintlib/functions/gr_implementing.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ from flint.flintlib.types.gr cimport gr_ctx_t, gr_funcptr, truth_t
66

77
cdef extern from "flint/gr_implementing.h":
88
# void gr_method_tab_init(gr_funcptr * methods, gr_method_tab_input * tab)
9-
int gr_not_implemented(void)
10-
int gr_not_in_domain(void)
9+
int gr_not_implemented()
10+
int gr_not_in_domain()
1111
truth_t gr_generic_ctx_predicate(gr_ctx_t ctx)
1212
truth_t gr_generic_ctx_predicate_true(gr_ctx_t ctx)
1313
truth_t gr_generic_ctx_predicate_false(gr_ctx_t ctx)

0 commit comments

Comments
 (0)