Multi-phase initialization (PEP 489) for Python 3.5+. On 3.13+ this * path creates heap types and allocates per-module state so that each * interpreter gets its own copy; on 3.5-3.12 the type fields just point * at the statically-allocated PyTypeObjects and state lives in the * single _speedups_static_state instance. Either way, module_exec does * the work and get_speedups_state() gives unifo
| 3863 | * single _speedups_static_state instance. Either way, module_exec does |
| 3864 | * the work and get_speedups_state() gives uniform access. */ |
| 3865 | static int |
| 3866 | module_exec(PyObject *m) |
| 3867 | { |
| 3868 | _speedups_state *state = get_speedups_state(m); |
| 3869 | |
| 3870 | #if PY_VERSION_HEX >= 0x030D0000 |
| 3871 | /* Create heap types from specs, bound to this module */ |
| 3872 | state->PyScannerType = PyType_FromModuleAndSpec(m, &PyScannerType_spec, NULL); |
| 3873 | if (state->PyScannerType == NULL) |
| 3874 | return -1; |
| 3875 | state->PyEncoderType = PyType_FromModuleAndSpec(m, &PyEncoderType_spec, NULL); |
| 3876 | if (state->PyEncoderType == NULL) |
| 3877 | return -1; |
| 3878 | #else |
| 3879 | if (PyType_Ready(&PyScannerType) < 0) |
| 3880 | return -1; |
| 3881 | if (PyType_Ready(&PyEncoderType) < 0) |
| 3882 | return -1; |
| 3883 | /* Static types are eternal, so these are borrowed pointers kept |
| 3884 | * in the state struct for layout uniformity with the 3.13+ path. |
| 3885 | * There is nothing to refcount and no GC tracking here. */ |
| 3886 | state->PyScannerType = (PyObject *)&PyScannerType; |
| 3887 | state->PyEncoderType = (PyObject *)&PyEncoderType; |
| 3888 | /* Scanner/Encoder instance construction needs a borrowed reference |
| 3889 | * to the module to store in module_ref; capture it here, before |
| 3890 | * anything else that might trigger instance creation. */ |
| 3891 | _speedups_module = m; |
| 3892 | #endif |
| 3893 | |
| 3894 | #if PY_VERSION_HEX >= 0x030A0000 |
| 3895 | if (PyModule_AddObjectRef(m, "make_scanner", state->PyScannerType) < 0) |
| 3896 | return -1; |
| 3897 | if (PyModule_AddObjectRef(m, "make_encoder", state->PyEncoderType) < 0) |
| 3898 | return -1; |
| 3899 | #else |
| 3900 | Py_INCREF(state->PyScannerType); |
| 3901 | if (PyModule_AddObject(m, "make_scanner", state->PyScannerType) < 0) { |
| 3902 | Py_DECREF(state->PyScannerType); |
| 3903 | return -1; |
| 3904 | } |
| 3905 | Py_INCREF(state->PyEncoderType); |
| 3906 | if (PyModule_AddObject(m, "make_encoder", state->PyEncoderType) < 0) { |
| 3907 | Py_DECREF(state->PyEncoderType); |
| 3908 | return -1; |
| 3909 | } |
| 3910 | #endif |
| 3911 | |
| 3912 | return init_speedups_state(state, m); |
| 3913 | } |
| 3914 | |
| 3915 | #if PY_VERSION_HEX >= 0x030D0000 |
| 3916 | static int |
nothing calls this directly
no test coverage detected
searching dependent graphs…