mirror of
https://gitlab.com/libvirt/libvirt-python.git
synced 2025-07-22 20:59:34 +03:00
Revert "Optimize callback lookup in event handlers"
This reverts commit 084729e269
.
The PyImport_ImportModuleNoBlock method does not exist in
python 2.4
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
@ -4921,26 +4921,39 @@ cleanup:
|
||||
* Helper functions to avoid importing modules
|
||||
* for every callback
|
||||
*******************************************/
|
||||
static PyObject *libvirt_module = NULL;
|
||||
static PyObject *libvirt_dict = NULL;
|
||||
|
||||
static PyObject *
|
||||
getLibvirtModuleObject(void) {
|
||||
if (libvirt_module)
|
||||
return libvirt_module;
|
||||
|
||||
// PyImport_ImportModule returns a new reference
|
||||
/* Bogus (char *) cast for RHEL-5 python API brokenness */
|
||||
libvirt_module = PyImport_ImportModule((char *)"libvirt");
|
||||
if (!libvirt_module) {
|
||||
DEBUG("%s Error importing libvirt module\n", __FUNCTION__);
|
||||
PyErr_Print();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return libvirt_module;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
getLibvirtDictObject(void) {
|
||||
PyObject *libvirt_mod;
|
||||
PyObject *libvirt_dict;
|
||||
if (libvirt_dict)
|
||||
return libvirt_dict;
|
||||
|
||||
libvirt_mod = PyImport_ImportModuleNoBlock("libvirt");
|
||||
if (!libvirt_mod) {
|
||||
DEBUG("%s Error finding libvirt in imports\n",
|
||||
__FUNCTION__);
|
||||
PyErr_Print();
|
||||
return NULL;
|
||||
}
|
||||
libvirt_dict = PyModule_GetDict(libvirt_mod);
|
||||
// PyModule_GetDict returns a borrowed reference
|
||||
libvirt_dict = PyModule_GetDict(getLibvirtModuleObject());
|
||||
if (!libvirt_dict) {
|
||||
DEBUG("%s Error finding libvirt dict\n",
|
||||
__FUNCTION__);
|
||||
DEBUG("%s Error importing libvirt dictionary\n", __FUNCTION__);
|
||||
PyErr_Print();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF(libvirt_dict);
|
||||
return libvirt_dict;
|
||||
}
|
||||
|
Reference in New Issue
Block a user