(mod, metadata, f, internal_h)
| 2269 | |
| 2270 | |
| 2271 | def generate_module_def(mod, metadata, f, internal_h): |
| 2272 | # Gather all the data needed for ModuleSpec |
| 2273 | state_strings = { |
| 2274 | "ast", |
| 2275 | "_fields", |
| 2276 | "__match_args__", |
| 2277 | "__doc__", |
| 2278 | "__dict__", |
| 2279 | "__module__", |
| 2280 | "_attributes", |
| 2281 | *metadata.identifiers |
| 2282 | } |
| 2283 | |
| 2284 | module_state = state_strings.copy() |
| 2285 | module_state.update( |
| 2286 | "%s_singleton" % singleton |
| 2287 | for singleton in metadata.singletons |
| 2288 | ) |
| 2289 | module_state.update( |
| 2290 | "%s_type" % type |
| 2291 | for type in metadata.types |
| 2292 | ) |
| 2293 | |
| 2294 | state_strings = sorted(state_strings) |
| 2295 | module_state = sorted(module_state) |
| 2296 | |
| 2297 | generate_ast_state(module_state, internal_h) |
| 2298 | |
| 2299 | print(textwrap.dedent(""" |
| 2300 | #include "Python.h" |
| 2301 | #include "pycore_ast.h" |
| 2302 | #include "pycore_ast_state.h" // struct ast_state |
| 2303 | #include "pycore_ceval.h" // _Py_EnterRecursiveCall() |
| 2304 | #include "pycore_lock.h" // _PyOnceFlag |
| 2305 | #include "pycore_modsupport.h" // _PyArg_NoPositional() |
| 2306 | #include "pycore_pystate.h" // _PyInterpreterState_GET() |
| 2307 | #include "pycore_runtime.h" // _Py_ID() |
| 2308 | #include "pycore_setobject.h" // _PySet_NextEntry() |
| 2309 | #include "pycore_unionobject.h" // _Py_union_type_or |
| 2310 | |
| 2311 | #include <stddef.h> // offsetof() |
| 2312 | |
| 2313 | |
| 2314 | // Forward declaration |
| 2315 | static int init_types(void *arg); |
| 2316 | |
| 2317 | static struct ast_state* |
| 2318 | get_ast_state(void) |
| 2319 | { |
| 2320 | PyInterpreterState *interp = _PyInterpreterState_GET(); |
| 2321 | struct ast_state *state = &interp->ast; |
| 2322 | assert(!state->finalized); |
| 2323 | if (_PyOnceFlag_CallOnce(&state->once, (_Py_once_fn_t *)&init_types, state) < 0) { |
| 2324 | return NULL; |
| 2325 | } |
| 2326 | return state; |
| 2327 | } |
| 2328 | """).strip(), file=f) |
no test coverage detected
searching dependent graphs…