| 7832 | }; |
| 7833 | |
| 7834 | PyMODINIT_FUNC PyInit_stringzilla(void) { |
| 7835 | PyObject *m; |
| 7836 | |
| 7837 | if (PyType_Ready(&StrType) < 0) return NULL; |
| 7838 | if (PyType_Ready(&FileType) < 0) return NULL; |
| 7839 | if (PyType_Ready(&StrsType) < 0) return NULL; |
| 7840 | if (PyType_Ready(&SplitIteratorType) < 0) return NULL; |
| 7841 | if (PyType_Ready(&Utf8SplitLinesIteratorType) < 0) return NULL; |
| 7842 | if (PyType_Ready(&Utf8SplitWhitespaceIteratorType) < 0) return NULL; |
| 7843 | if (PyType_Ready(&Utf8WordBoundaryIteratorType) < 0) return NULL; |
| 7844 | if (PyType_Ready(&Utf8CaseInsensitiveFindIteratorType) < 0) return NULL; |
| 7845 | if (PyType_Ready(&HasherType) < 0) return NULL; |
| 7846 | if (PyType_Ready(&Sha256Type) < 0) return NULL; |
| 7847 | |
| 7848 | m = PyModule_Create(&stringzilla_module); |
| 7849 | if (m == NULL) return NULL; |
| 7850 | |
| 7851 | #ifdef Py_GIL_DISABLED |
| 7852 | // Declare that this module is safe for free-threaded Python |
| 7853 | PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED); |
| 7854 | #endif |
| 7855 | |
| 7856 | // Add version metadata |
| 7857 | { |
| 7858 | char version_str[50]; |
| 7859 | sprintf(version_str, "%d.%d.%d", sz_version_major(), sz_version_minor(), sz_version_patch()); |
| 7860 | PyModule_AddStringConstant(m, "__version__", version_str); |
| 7861 | } |
| 7862 | |
| 7863 | // Define SIMD capabilities as a tuple |
| 7864 | { |
| 7865 | sz_capability_t caps = sz_capabilities(); |
| 7866 | |
| 7867 | // Get capability strings using the new function |
| 7868 | sz_cptr_t cap_strings[SZ_CAPABILITIES_COUNT]; |
| 7869 | sz_size_t cap_count = sz_capabilities_to_strings_implementation_(caps, cap_strings, SZ_CAPABILITIES_COUNT); |
| 7870 | |
| 7871 | // Create a Python tuple with the capabilities |
| 7872 | PyObject *caps_tuple = PyTuple_New(cap_count); |
| 7873 | if (!caps_tuple) { |
| 7874 | Py_XDECREF(m); |
| 7875 | return NULL; |
| 7876 | } |
| 7877 | |
| 7878 | for (sz_size_t i = 0; i < cap_count; i++) { |
| 7879 | PyObject *cap_str = PyUnicode_FromString(cap_strings[i]); |
| 7880 | if (!cap_str) { |
| 7881 | Py_DECREF(caps_tuple); |
| 7882 | Py_XDECREF(m); |
| 7883 | return NULL; |
| 7884 | } |
| 7885 | PyTuple_SET_ITEM(caps_tuple, i, cap_str); |
| 7886 | } |
| 7887 | |
| 7888 | if (PyModule_AddObject(m, "__capabilities__", caps_tuple) < 0) { |
| 7889 | Py_DECREF(caps_tuple); |
| 7890 | Py_XDECREF(m); |
| 7891 | return NULL; |
nothing calls this directly
no test coverage detected
searching dependent graphs…