* 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
| 35 | * @private |
| 36 | */ |
| 37 | SRD_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 |
no outgoing calls
no test coverage detected