mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
python: move lvm_init
Only call lvm_init() when it's needed so that simply loading the lvm python code in another program doesn't make that program do lvm initialization. The version call doesn't need a handle. The garbage collection can just do lvm_quit to destroy the command. The next call that needs lvm_init will do it first.
This commit is contained in:
parent
57e9df7dc5
commit
7ef152c072
@ -93,6 +93,9 @@ static PyObject *_LibLVMError;
|
|||||||
|
|
||||||
#define LVM_VALID(ptr) \
|
#define LVM_VALID(ptr) \
|
||||||
do { \
|
do { \
|
||||||
|
if (!_libh) { \
|
||||||
|
_libh = lvm_init(NULL); \
|
||||||
|
} \
|
||||||
if (ptr && _libh) { \
|
if (ptr && _libh) { \
|
||||||
if (ptr != _libh) { \
|
if (ptr != _libh) { \
|
||||||
PyErr_SetString(PyExc_UnboundLocalError, "LVM handle reference stale"); \
|
PyErr_SetString(PyExc_UnboundLocalError, "LVM handle reference stale"); \
|
||||||
@ -175,8 +178,6 @@ static PyObject *_liblvm_get_last_error(void)
|
|||||||
|
|
||||||
static PyObject *_liblvm_library_get_version(void)
|
static PyObject *_liblvm_library_get_version(void)
|
||||||
{
|
{
|
||||||
LVM_VALID(NULL);
|
|
||||||
|
|
||||||
return Py_BuildValue("s", lvm_library_get_version());
|
return Py_BuildValue("s", lvm_library_get_version());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,13 +185,9 @@ static const char _gc_doc[] = "Garbage collect the C library";
|
|||||||
|
|
||||||
static PyObject *_liblvm_lvm_gc(void)
|
static PyObject *_liblvm_lvm_gc(void)
|
||||||
{
|
{
|
||||||
LVM_VALID(NULL);
|
if (_libh) {
|
||||||
|
|
||||||
lvm_quit(_libh);
|
lvm_quit(_libh);
|
||||||
|
_libh = NULL;
|
||||||
if (!(_libh = lvm_init(NULL))) {
|
|
||||||
PyErr_SetObject(_LibLVMError, _liblvm_get_last_error());
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
@ -2047,8 +2044,6 @@ PyMODINIT_FUNC initlvm(void)
|
|||||||
{
|
{
|
||||||
PyObject *m;
|
PyObject *m;
|
||||||
|
|
||||||
_libh = lvm_init(NULL);
|
|
||||||
|
|
||||||
if (PyType_Ready(&_LibLVMvgType) < 0)
|
if (PyType_Ready(&_LibLVMvgType) < 0)
|
||||||
MODINITERROR;
|
MODINITERROR;
|
||||||
if (PyType_Ready(&_LibLVMlvType) < 0)
|
if (PyType_Ready(&_LibLVMlvType) < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user