From 554d82a200289938d5639a782a9f12e3e2e968f0 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Tue, 20 Jan 2009 22:10:52 +0000 Subject: [PATCH] Use global thread-local error for all python error reporting --- ChangeLog | 5 +++++ python/libvir.c | 44 ++++++++++++++++++++++---------------------- python/libvir.py | 7 +++---- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 05be59ccae..a4fe397cbc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Jan 20 22:06:53 GMT 2009 Daniel P. Berrange + + * 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 * qemud/qemud.c: respect LIBVIRT_DEBUG when logging to syslog diff --git a/python/libvir.c b/python/libvir.c index e07171297b..cdc5b51486 100644 --- a/python/libvir.c +++ b/python/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/python/libvir.py b/python/libvir.py index b90f795b8d..8a16dd0be8 100644 --- 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: -- 2.39.5