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

Function module_reset_capabilities

python/stringzilla.c:7713–7746  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7711 "Side effects: updates stringzilla.__capabilities__ and __capabilities_str__.";
7712
7713static PyObject *module_reset_capabilities(PyObject *self, PyObject *args) {
7714 PyObject *caps_obj = NULL;
7715 if (!PyArg_ParseTuple(args, "O", &caps_obj)) return NULL;
7716
7717 sz_capability_t caps = 0;
7718 if (parse_and_intersect_capabilities(caps_obj, &caps) != 0) return NULL;
7719
7720 // Update the dispatch table
7721 sz_dispatch_table_update(caps);
7722
7723 // Recompute and set module-level capability exports
7724 sz_cptr_t cap_strings[SZ_CAPABILITIES_COUNT];
7725 sz_size_t cap_count = sz_capabilities_to_strings_implementation_(caps, cap_strings, SZ_CAPABILITIES_COUNT);
7726 PyObject *caps_tuple = PyTuple_New(cap_count);
7727 if (!caps_tuple) return NULL;
7728 for (sz_size_t i = 0; i < cap_count; i++) {
7729 PyObject *cap_str = PyUnicode_FromString(cap_strings[i]);
7730 if (!cap_str) {
7731 Py_DECREF(caps_tuple);
7732 return NULL;
7733 }
7734 PyTuple_SET_ITEM(caps_tuple, i, cap_str);
7735 }
7736 if (PyObject_SetAttrString(self, "__capabilities__", caps_tuple) != 0) {
7737 Py_DECREF(caps_tuple);
7738 return NULL;
7739 }
7740 Py_DECREF(caps_tuple);
7741
7742 sz_cptr_t caps_str = sz_capabilities_to_string(caps);
7743 if (PyObject_SetAttrString(self, "__capabilities_str__", PyUnicode_FromString(caps_str)) != 0) { return NULL; }
7744
7745 Py_RETURN_NONE;
7746}
7747
7748static void stringzilla_cleanup(PyObject *m) { sz_unused_(m); }
7749

Callers

nothing calls this directly

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…