From d6d8338a07b39e19ef8243cbbea48617096bfba1 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Tue, 20 Jan 2009 22:10:52 +0000 Subject: Use global thread-local error for all python error reporting --- libvir.c | 44 ++++++++++++++++++++++---------------------- libvir.py | 7 +++---- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/libvir.c b/libvir.c index e071712..cdc5b51 100644 --- a/libvir.c +++ b/libvir.c @@ -438,23 +438,23 @@ static PyObject *libvirt_virPythonErrorFuncCtxt = NULL; 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 ATTRIBUTE_UNUSED, PyObject *args ATTRIBUT 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 *self ATTRIBUTE_UNUSED, PyObject *args) 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/libvir.py b/libvir.py index b90f795..8a16dd0 100644 --- a/libvir.py +++ b/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: -- cgit