master - python: move lvm_init
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=7ef152c07290c79f47a64b0fc81975ae52554919 Commit: 7ef152c07290c79f47a64b0fc81975ae52554919 Parent: 57e9df7dc535bcba6124fce814323b63c6a0d779 Author: David Teigland <[email protected]> AuthorDate: Wed May 11 13:42:00 2016 -0500 Committer: David Teigland <[email protected]> CommitterDate: Mon May 16 14:36:55 2016 -0500
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.
--- python/liblvm.c | 17 ++++++----------- 1 files changed, 6 insertions(+), 11 deletions(-)
python/liblvm.c +6 -11
@@ -93,6 +93,9 @@ static PyObject *_LibLVMError;#define LVM_VALID (ptr) \ do { \ + if (!_libh) { \ + _libh = lvm_init(NULL); \ + } \ if (ptr && _libh) { \ if (ptr != _libh) { \ 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 ) { -LVM_VALID (NULL ); -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 ) { -LVM_VALID (NULL ); - -lvm_quit (_libh); - -if (!(_libh =lvm_init (NULL ))) { -PyErr_SetObject (_LibLVMError,_liblvm_get_last_error ()); -return NULL ; +if (_libh) { +lvm_quit (_libh); + _libh =NULL ; }Py_INCREF (Py_None);
@@ -2047,8 +2044,6 @@ PyMODINIT_FUNC initlvm(void) {PyObject *m; - _libh =lvm_init (NULL ); -if (PyType_Ready (&_LibLVMvgType) <0 )MODINITERROR ;if (PyType_Ready (&_LibLVMlvType) <0 )