MCPcopy Create free account
hub / github.com/ashvardanian/StringZilla / capabilities_to_tuple

Function capabilities_to_tuple

python/stringzillas.c:74–90  ·  view source on GitHub ↗

* @brief Creates a Python tuple from capabilities mask. * @param[in] caps Capabilities mask * @return New reference to Python tuple, or NULL on error */

Source from the content-addressed store, hash-verified

72 * @return New reference to Python tuple, or NULL on error
73 */
74static PyObject *capabilities_to_tuple(sz_capability_t caps) {
75 char const *cap_strings[SZ_CAPABILITIES_COUNT];
76 sz_size_t cap_count = sz_capabilities_to_strings_implementation_(caps, cap_strings, SZ_CAPABILITIES_COUNT);
77
78 PyObject *caps_tuple = PyTuple_New(cap_count);
79 if (!caps_tuple) return NULL;
80
81 for (sz_size_t i = 0; i < cap_count; i++) {
82 PyObject *cap_str = PyUnicode_FromString(cap_strings[i]);
83 if (!cap_str) {
84 Py_DECREF(caps_tuple);
85 return NULL;
86 }
87 PyTuple_SET_ITEM(caps_tuple, i, cap_str);
88 }
89 return caps_tuple;
90}
91
92// Try to import NumPy, and fail if it's not available
93static int numpy_available = 0;

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…