summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2009-01-20 22:10:52 +0000
committerDaniel P. Berrange <berrange@redhat.com>2009-01-20 22:10:52 +0000
commitd6d8338a07b39e19ef8243cbbea48617096bfba1 (patch)
tree61df26d7cda46c622778afe2e6d9ec4449194199
parent92583135c8a6576176511c92154a8806873a0beb (diff)
downloadlibvirt-python-d6d8338a07b39e19ef8243cbbea48617096bfba1.tar.gz
Use global thread-local error for all python error reportingv0.6.0LIBVIRT_0_6_0
-rw-r--r--libvir.c44
-rw-r--r--libvir.py7
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: