Parse distributions.h located in inc_dir for CFFI, filling in the ffi.cdef Read the function declarations without the "#define ..." macros that will be filled in when loading the library.
(ffi, inc_dir)
| 2 | |
| 3 | |
| 4 | def parse_distributions_h(ffi, inc_dir): |
| 5 | """ |
| 6 | Parse distributions.h located in inc_dir for CFFI, filling in the ffi.cdef |
| 7 | |
| 8 | Read the function declarations without the "#define ..." macros that will |
| 9 | be filled in when loading the library. |
| 10 | """ |
| 11 | |
| 12 | with open(os.path.join(inc_dir, 'random', 'bitgen.h')) as fid: |
| 13 | s = [] |
| 14 | for line in fid: |
| 15 | # massage the include file |
| 16 | if line.strip().startswith('#'): |
| 17 | continue |
| 18 | s.append(line) |
| 19 | ffi.cdef('\n'.join(s)) |
| 20 | |
| 21 | with open(os.path.join(inc_dir, 'random', 'distributions.h')) as fid: |
| 22 | s = [] |
| 23 | in_skip = 0 |
| 24 | ignoring = False |
| 25 | for line in fid: |
| 26 | # check for and remove extern "C" guards |
| 27 | if ignoring: |
| 28 | if line.strip().startswith('#endif'): |
| 29 | ignoring = False |
| 30 | continue |
| 31 | if line.strip().startswith('#ifdef __cplusplus'): |
| 32 | ignoring = True |
| 33 | |
| 34 | # massage the include file |
| 35 | if line.strip().startswith('#'): |
| 36 | continue |
| 37 | |
| 38 | # skip any inlined function definition |
| 39 | # which starts with 'static inline xxx(...) {' |
| 40 | # and ends with a closing '}' |
| 41 | if line.strip().startswith('static inline'): |
| 42 | in_skip += line.count('{') |
| 43 | continue |
| 44 | elif in_skip > 0: |
| 45 | in_skip += line.count('{') |
| 46 | in_skip -= line.count('}') |
| 47 | continue |
| 48 | |
| 49 | # replace defines with their value or remove them |
| 50 | line = line.replace('DECLDIR', '') |
| 51 | line = line.replace('RAND_INT_TYPE', 'int64_t') |
| 52 | s.append(line) |
| 53 | ffi.cdef('\n'.join(s)) |
no test coverage detected
searching dependent graphs…