The virGetLastError() method is now stored in a thread local and virConnGetLastError() is deprecated, so switch to only use the former. Also, no need to copy the error object since it is thread local already thus guarenteed not to change behind our backs libvir.c | 44 ++++++++++++++++++++++---------------------- libvir.py | 7 +++---- 2 files changed, 25 insertions(+), 26 deletions(-) Daniel diff --git a/python/libvir.c b/python/libvir.c --- a/python/libvir.c +++ b/python/libvir.c @@ -438,23 +438,23 @@ static PyObject *libvirt_virPythonErrorF static PyObject * libvirt_virGetLastError(PyObject *self ATTRIBUTE_UNUSED, PyObject *args ATTRIBUTE_UNUSED) { - virError err; + virError *err; PyObject *info; - if (virCopyLastError(&err) <= 0) + if ((err = virGetLastError()) == NULL) return VIR_PY_NONE; if ((info = PyTuple_New(9)) == NULL) return VIR_PY_NONE; - PyTuple_SetItem(info, 0, PyInt_FromLong((long) err.code)); - PyTuple_SetItem(info, 1, PyInt_FromLong((long) err.domain)); - PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(err.message)); - PyTuple_SetItem(info, 3, PyInt_FromLong((long) err.level)); - PyTuple_SetItem(info, 4, libvirt_constcharPtrWrap(err.str1)); - PyTuple_SetItem(info, 5, libvirt_constcharPtrWrap(err.str2)); - PyTuple_SetItem(info, 6, libvirt_constcharPtrWrap(err.str3)); - PyTuple_SetItem(info, 7, PyInt_FromLong((long) err.int1)); - PyTuple_SetItem(info, 8, PyInt_FromLong((long) err.int2)); + PyTuple_SetItem(info, 0, PyInt_FromLong((long) err->code)); + PyTuple_SetItem(info, 1, PyInt_FromLong((long) err->domain)); + PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(err->message)); + PyTuple_SetItem(info, 3, PyInt_FromLong((long) err->level)); + PyTuple_SetItem(info, 4, libvirt_constcharPtrWrap(err->str1)); + PyTuple_SetItem(info, 5, libvirt_constcharPtrWrap(err->str2)); + PyTuple_SetItem(info, 6, libvirt_constcharPtrWrap(err->str3)); + PyTuple_SetItem(info, 7, PyInt_FromLong((long) err->int1)); + PyTuple_SetItem(info, 8, PyInt_FromLong((long) err->int2)); return info; } @@ -462,7 +462,7 @@ libvirt_virGetLastError(PyObject *self A static PyObject * libvirt_virConnGetLastError(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { - virError err; + virError *err; PyObject *info; virConnectPtr conn; PyObject *pyobj_conn; @@ -471,20 +471,20 @@ libvirt_virConnGetLastError(PyObject *se return(NULL); conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn); - if (virConnCopyLastError(conn, &err) <= 0) + if ((err = virConnGetLastError(conn)) == NULL) return VIR_PY_NONE; if ((info = PyTuple_New(9)) == NULL) return VIR_PY_NONE; - PyTuple_SetItem(info, 0, PyInt_FromLong((long) err.code)); - PyTuple_SetItem(info, 1, PyInt_FromLong((long) err.domain)); - PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(err.message)); - PyTuple_SetItem(info, 3, PyInt_FromLong((long) err.level)); - PyTuple_SetItem(info, 4, libvirt_constcharPtrWrap(err.str1)); - PyTuple_SetItem(info, 5, libvirt_constcharPtrWrap(err.str2)); - PyTuple_SetItem(info, 6, libvirt_constcharPtrWrap(err.str3)); - PyTuple_SetItem(info, 7, PyInt_FromLong((long) err.int1)); - PyTuple_SetItem(info, 8, PyInt_FromLong((long) err.int2)); + PyTuple_SetItem(info, 0, PyInt_FromLong((long) err->code)); + PyTuple_SetItem(info, 1, PyInt_FromLong((long) err->domain)); + PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(err->message)); + PyTuple_SetItem(info, 3, PyInt_FromLong((long) err->level)); + PyTuple_SetItem(info, 4, libvirt_constcharPtrWrap(err->str1)); + PyTuple_SetItem(info, 5, libvirt_constcharPtrWrap(err->str2)); + PyTuple_SetItem(info, 6, libvirt_constcharPtrWrap(err->str3)); + PyTuple_SetItem(info, 7, PyInt_FromLong((long) err->int1)); + PyTuple_SetItem(info, 8, PyInt_FromLong((long) err->int2)); return info; } diff --git a/python/libvir.py b/python/libvir.py --- a/python/libvir.py +++ b/python/libvir.py @@ -26,10 +26,9 @@ class libvirtError(Exception): elif vol is not None: conn = vol._conn - if conn is None: - err = virGetLastError() - else: - err = conn.virConnGetLastError() + # Never call virConnGetLastError(). + # virGetLastError() is now thread local + err = virGetLastError() if err is None: msg = defmsg else: -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :| -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list