MCPcopy Index your code
hub / github.com/numpy/numpy / parse_distributions_h

Function parse_distributions_h

numpy/random/_examples/cffi/parse.py:4–53  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

2
3
4def 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))

Callers 1

extending.pyFile · 0.85

Calls 6

openFunction · 0.85
joinMethod · 0.80
startswithMethod · 0.80
stripMethod · 0.80
replaceMethod · 0.80
countMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…