]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Use global thread-local error for all python error reporting
authorDaniel P. Berrange <berrange@redhat.com>
Tue, 20 Jan 2009 22:10:52 +0000 (22:10 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 20 Jan 2009 22:10:52 +0000 (22:10 +0000)
ChangeLog
python/libvir.c
python/libvir.py

index 05be59ccae33791aa827a06ba67eafae0a396b33..a4fe397cbcf27f1cb670893d9d4abdd8553ddde3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Jan 20 22:06:53 GMT 2009 Daniel P. Berrange <berrange@redhat.com>
+
+       * python/libvir.c, python/libvir.py: Use global thread
+       local error variable for all exceptions.
+
 Tue Jan 20 13:35:36 PST 2009 John Levon <john.levon@sun.com>
 
        * qemud/qemud.c: respect LIBVIRT_DEBUG when logging to syslog
index e07171297b269d5981dd88cb20d13e18b0767af2..cdc5b51486a0d8d864ab44a07c0bdf23c0d4f15a 100644 (file)
@@ -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;
 }
index b90f795b8d60c177d4d1786d7e4ed64bc8ee704c..8a16dd0be8c03ed101a471195a185c4ea13d72d6 100644 (file)
@@ -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: