MCPcopy Create free account
hub / github.com/DreamSourceLab/DSView / py_import_by_name

Function py_import_by_name

libsigrokdecode4DSL/util.c:37–56  ·  view source on GitHub ↗

* Import a Python module by name. * * This function is implemented in terms of PyImport_Import() rather than * PyImport_ImportModule(), so that the import hooks are not bypassed. * * @param[in] name The name of the module to load as UTF-8 string. * @return The Python module object, or NULL if an exception occurred. The * caller is responsible for evaluating and clearing the Python error st

Source from the content-addressed store, hash-verified

35 * @private
36 */
37SRD_PRIV PyObject *py_import_by_name(const char *name)
38{
39 PyObject *py_mod, *py_modname;
40 PyGILState_STATE gstate;
41
42 gstate = PyGILState_Ensure();
43
44 py_modname = PyUnicode_FromString(name);
45 if (!py_modname) {
46 PyGILState_Release(gstate);
47 return NULL;
48 }
49
50 py_mod = PyImport_Import(py_modname);
51 Py_DECREF(py_modname);
52
53 PyGILState_Release(gstate);
54
55 return py_mod;
56}
57
58/**
59 * Get the value of a Python object's attribute, returned as a newly

Callers 3

srd_exception_catchFunction · 0.85
srd_decoder_loadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected