In a couple instances we have to mark a debug variable as ATTRIBUTE_UNUSED
to avoid warnings.
Signed-off-by: Cole Robinson <crobinso(a)redhat.com>
---
python/libvirt-override.c | 159 ++++++++++++++++-----------------------------
1 files changed, 55 insertions(+), 104 deletions(-)
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index 61d5b7d..d6582e2 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -28,6 +28,16 @@ extern void initlibvirtmod(void);
extern void initcygvirtmod(void);
#endif
+//#define DEBUG_ERROR 1
+
+#if DEBUG_ERROR
+# define DEBUG(fmt, ...) \
+ printf(fmt, __VA_ARGS__)
+#else
+# define DEBUG(fmt, ...) \
+ do {} while (0)
+#endif
+
/* The two-statement sequence "Py_INCREF(Py_None); return Py_None;"
is so common that we encapsulate it here. Now, each use is simply
return VIR_PY_NONE; */
@@ -621,10 +631,8 @@ libvirt_virErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, virErrorPtr
err)
PyObject *list, *info;
PyObject *result;
-#ifdef DEBUG_ERROR
- printf("libvirt_virErrorFuncHandler(%p, %s, ...) called\n", ctx,
- err->message);
-#endif
+ DEBUG("libvirt_virErrorFuncHandler(%p, %s, ...) called\n", ctx,
+ err->message);
if ((err == NULL) || (err->code == VIR_ERR_OK))
return;
@@ -671,10 +679,8 @@ libvirt_virRegisterErrorHandler(ATTRIBUTE_UNUSED PyObject * self,
&pyobj_ctx))
return (NULL);
-#ifdef DEBUG_ERROR
- printf("libvirt_virRegisterErrorHandler(%p, %p) called\n", pyobj_ctx,
- pyobj_f);
-#endif
+ DEBUG("libvirt_virRegisterErrorHandler(%p, %p) called\n", pyobj_ctx,
+ pyobj_f);
virSetErrorFunc(NULL, libvirt_virErrorFuncHandler);
if (libvirt_virPythonErrorFuncHandler != NULL) {
@@ -2451,9 +2457,7 @@ getLibvirtModuleObject (void) {
/* Bogus (char *) cast for RHEL-5 python API brokenness */
libvirt_module = PyImport_ImportModule((char *)"libvirt");
if(!libvirt_module) {
-#if DEBUG_ERROR
- printf("%s Error importing libvirt module\n", __FUNCTION__);
-#endif
+ DEBUG("%s Error importing libvirt module\n", __FUNCTION__);
PyErr_Print();
return NULL;
}
@@ -2469,9 +2473,7 @@ getLibvirtDictObject (void) {
// PyModule_GetDict returns a borrowed reference
libvirt_dict = PyModule_GetDict(getLibvirtModuleObject());
if(!libvirt_dict) {
-#if DEBUG_ERROR
- printf("%s Error importing libvirt dictionary\n", __FUNCTION__);
-#endif
+ DEBUG("%s Error importing libvirt dictionary\n", __FUNCTION__);
PyErr_Print();
return NULL;
}
@@ -2489,9 +2491,7 @@ getLibvirtDomainClassObject (void) {
libvirt_dom_class = PyDict_GetItemString(getLibvirtDictObject(),
"virDomain");
if(!libvirt_dom_class) {
-#if DEBUG_ERROR
- printf("%s Error importing virDomain class\n", __FUNCTION__);
-#endif
+ DEBUG("%s Error importing virDomain class\n", __FUNCTION__);
PyErr_Print();
return NULL;
}
@@ -2528,24 +2528,18 @@ libvirt_virConnectDomainEventCallback(virConnectPtr conn
ATTRIBUTE_UNUSED,
pyobj_dom = libvirt_virDomainPtrWrap(dom);
pyobj_dom_args = PyTuple_New(2);
if(PyTuple_SetItem(pyobj_dom_args, 0, pyobj_conn_inst)!=0) {
-#if DEBUG_ERROR
- printf("%s error creating tuple",__FUNCTION__);
-#endif
+ DEBUG("%s error creating tuple",__FUNCTION__);
goto cleanup;
}
if(PyTuple_SetItem(pyobj_dom_args, 1, pyobj_dom)!=0) {
-#if DEBUG_ERROR
- printf("%s error creating tuple",__FUNCTION__);
-#endif
+ DEBUG("%s error creating tuple",__FUNCTION__);
goto cleanup;
}
Py_INCREF(pyobj_conn_inst);
dom_class = getLibvirtDomainClassObject();
if(!PyClass_Check(dom_class)) {
-#if DEBUG_ERROR
- printf("%s dom_class is not a class!\n", __FUNCTION__);
-#endif
+ DEBUG("%s dom_class is not a class!\n", __FUNCTION__);
goto cleanup;
}
@@ -2556,9 +2550,8 @@ libvirt_virConnectDomainEventCallback(virConnectPtr conn
ATTRIBUTE_UNUSED,
Py_DECREF(pyobj_dom_args);
if(!pyobj_dom_inst) {
-#if DEBUG_ERROR
- printf("%s Error creating a python instance of virDomain\n",
__FUNCTION__);
-#endif
+ DEBUG("%s Error creating a python instance of virDomain\n",
+ __FUNCTION__);
PyErr_Print();
goto cleanup;
}
@@ -2574,9 +2567,7 @@ libvirt_virConnectDomainEventCallback(virConnectPtr conn
ATTRIBUTE_UNUSED,
Py_DECREF(pyobj_dom_inst);
if(!pyobj_ret) {
-#if DEBUG_ERROR
- printf("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
-#endif
+ DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
PyErr_Print();
} else {
Py_DECREF(pyobj_ret);
@@ -2603,16 +2594,12 @@ libvirt_virConnectDomainEventRegister(ATTRIBUTE_UNUSED PyObject *
self,
if (!PyArg_ParseTuple
(args, (char *) "OO:virConnectDomainEventRegister",
&pyobj_conn, &pyobj_conn_inst)) {
-#if DEBUG_ERROR
- printf("%s failed parsing tuple\n", __FUNCTION__);
-#endif
+ DEBUG("%s failed parsing tuple\n", __FUNCTION__);
return VIR_PY_INT_FAIL;
}
-#ifdef DEBUG_ERROR
- printf("libvirt_virConnectDomainEventRegister(%p %p) called\n",
- pyobj_conn, pyobj_conn_inst);
-#endif
+ DEBUG("libvirt_virConnectDomainEventRegister(%p %p) called\n",
+ pyobj_conn, pyobj_conn_inst);
conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
Py_INCREF(pyobj_conn_inst);
@@ -2645,9 +2632,7 @@ libvirt_virConnectDomainEventDeregister(ATTRIBUTE_UNUSED PyObject *
self,
&pyobj_conn, &pyobj_conn_inst))
return (NULL);
-#ifdef DEBUG_ERROR
- printf("libvirt_virConnectDomainEventDeregister(%p) called\n",
pyobj_conn);
-#endif
+ DEBUG("libvirt_virConnectDomainEventDeregister(%p) called\n", pyobj_conn);
conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
@@ -2702,19 +2687,16 @@ libvirt_virEventAddHandleFunc (int fd,
python_cb = PyDict_GetItemString(getLibvirtDictObject(),
"eventInvokeHandleCallback");
if(!python_cb) {
-#if DEBUG_ERROR
- printf("%s: Error finding eventInvokeHandleCallback\n", __FUNCTION__);
-#endif
+ DEBUG("%s: Error finding eventInvokeHandleCallback\n", __FUNCTION__);
PyErr_Print();
PyErr_Clear();
goto cleanup;
}
if (!PyCallable_Check(python_cb)) {
-#if DEBUG_ERROR
- char *name = py_str(python_cb);
- printf("%s: %s is not callable\n", __FUNCTION__,
- name ? name : "libvirt.eventInvokeHandleCallback");
-#endif
+ char *name ATTRIBUTE_UNUSED;
+ name = py_str(python_cb);
+ DEBUG("%s: %s is not callable\n", __FUNCTION__,
+ name ? name : "libvirt.eventInvokeHandleCallback");
goto cleanup;
}
Py_INCREF(python_cb);
@@ -2740,9 +2722,7 @@ libvirt_virEventAddHandleFunc (int fd,
PyErr_Print();
PyErr_Clear();
} else if (!PyInt_Check(result)) {
-#if DEBUG_ERROR
- printf("%s: %s should return an int\n", __FUNCTION__,
NAME(addHandle));
-#endif
+ DEBUG("%s: %s should return an int\n", __FUNCTION__, NAME(addHandle));
} else {
retval = (int)PyInt_AsLong(result);
}
@@ -2801,11 +2781,9 @@ libvirt_virEventRemoveHandleFunc(int watch)
PyErr_Print();
PyErr_Clear();
} else if (!PyTuple_Check(result) || PyTuple_Size(result) != 3) {
-#if DEBUG_ERROR
- printf("%s: %s must return opaque obj registered with %s"
- "to avoid leaking libvirt memory\n",
- __FUNCTION__, NAME(removeHandle), NAME(addHandle));
-#endif
+ DEBUG("%s: %s must return opaque obj registered with %s"
+ "to avoid leaking libvirt memory\n",
+ __FUNCTION__, NAME(removeHandle), NAME(addHandle));
} else {
opaque = PyTuple_GetItem(result, 1);
ff = PyTuple_GetItem(result, 2);
@@ -2846,19 +2824,16 @@ libvirt_virEventAddTimeoutFunc(int timeout,
python_cb = PyDict_GetItemString(getLibvirtDictObject(),
"eventInvokeTimeoutCallback");
if(!python_cb) {
-#if DEBUG_ERROR
- printf("%s: Error finding eventInvokeTimeoutCallback\n",
__FUNCTION__);
-#endif
+ DEBUG("%s: Error finding eventInvokeTimeoutCallback\n", __FUNCTION__);
PyErr_Print();
PyErr_Clear();
goto cleanup;
}
if (!PyCallable_Check(python_cb)) {
-#if DEBUG_ERROR
- char *name = py_str(python_cb);
- printf("%s: %s is not callable\n", __FUNCTION__,
- name ? name : "libvirt.eventInvokeTimeoutCallback");
-#endif
+ char *name ATTRIBUTE_UNUSED;
+ name = py_str(python_cb);
+ DEBUG("%s: %s is not callable\n", __FUNCTION__,
+ name ? name : "libvirt.eventInvokeTimeoutCallback");
goto cleanup;
}
Py_INCREF(python_cb);
@@ -2884,9 +2859,7 @@ libvirt_virEventAddTimeoutFunc(int timeout,
PyErr_Print();
PyErr_Clear();
} else if (!PyInt_Check(result)) {
-#if DEBUG_ERROR
- printf("%s: %s should return an int\n", __FUNCTION__,
NAME(addTimeout));
-#endif
+ DEBUG("%s: %s should return an int\n", __FUNCTION__,
NAME(addTimeout));
} else {
retval = (int)PyInt_AsLong(result);
}
@@ -2943,11 +2916,9 @@ libvirt_virEventRemoveTimeoutFunc(int timer)
PyErr_Print();
PyErr_Clear();
} else if (!PyTuple_Check(result) || PyTuple_Size(result) != 3) {
-#if DEBUG_ERROR
- printf("%s: %s must return opaque obj registered with %s"
- "to avoid leaking libvirt memory\n",
- __FUNCTION__, NAME(removeTimeout), NAME(addTimeout));
-#endif
+ DEBUG("%s: %s must return opaque obj registered with %s"
+ "to avoid leaking libvirt memory\n",
+ __FUNCTION__, NAME(removeTimeout), NAME(addTimeout));
} else {
opaque = PyTuple_GetItem(result, 1);
ff = PyTuple_GetItem(result, 2);
@@ -3127,9 +3098,7 @@ libvirt_virConnectDomainEventLifecycleCallback(virConnectPtr conn
ATTRIBUTE_UNUS
Py_DECREF(pyobj_dom);
if(!pyobj_ret) {
-#if DEBUG_ERROR
- printf("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
-#endif
+ DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
PyErr_Print();
} else {
Py_DECREF(pyobj_ret);
@@ -3173,9 +3142,7 @@ libvirt_virConnectDomainEventGenericCallback(virConnectPtr conn
ATTRIBUTE_UNUSED
Py_DECREF(pyobj_dom);
if(!pyobj_ret) {
-#if DEBUG_ERROR
- printf("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
-#endif
+ DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
PyErr_Print();
} else {
Py_DECREF(pyobj_ret);
@@ -3222,9 +3189,7 @@ libvirt_virConnectDomainEventRTCChangeCallback(virConnectPtr conn
ATTRIBUTE_UNUS
Py_DECREF(pyobj_dom);
if(!pyobj_ret) {
-#if DEBUG_ERROR
- printf("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
-#endif
+ DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
PyErr_Print();
} else {
Py_DECREF(pyobj_ret);
@@ -3271,9 +3236,7 @@ libvirt_virConnectDomainEventWatchdogCallback(virConnectPtr conn
ATTRIBUTE_UNUSE
Py_DECREF(pyobj_dom);
if(!pyobj_ret) {
-#if DEBUG_ERROR
- printf("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
-#endif
+ DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
PyErr_Print();
} else {
Py_DECREF(pyobj_ret);
@@ -3322,9 +3285,7 @@ libvirt_virConnectDomainEventIOErrorCallback(virConnectPtr conn
ATTRIBUTE_UNUSED
Py_DECREF(pyobj_dom);
if(!pyobj_ret) {
-#if DEBUG_ERROR
- printf("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
-#endif
+ DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
PyErr_Print();
} else {
Py_DECREF(pyobj_ret);
@@ -3374,9 +3335,7 @@ libvirt_virConnectDomainEventIOErrorReasonCallback(virConnectPtr
conn ATTRIBUTE_
Py_DECREF(pyobj_dom);
if(!pyobj_ret) {
-#if DEBUG_ERROR
- printf("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
-#endif
+ DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
PyErr_Print();
} else {
Py_DECREF(pyobj_ret);
@@ -3463,9 +3422,7 @@ libvirt_virConnectDomainEventGraphicsCallback(virConnectPtr conn
ATTRIBUTE_UNUSE
Py_DECREF(pyobj_dom);
if(!pyobj_ret) {
-#if DEBUG_ERROR
- printf("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
-#endif
+ DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
PyErr_Print();
} else {
Py_DECREF(pyobj_ret);
@@ -3541,16 +3498,12 @@ libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject
* self,
if (!PyArg_ParseTuple
(args, (char *) "OOiO:virConnectDomainEventRegisterAny",
&pyobj_conn, &pyobj_dom, &eventID, &pyobj_cbData)) {
-#if DEBUG_ERROR
- printf("%s failed parsing tuple\n", __FUNCTION__);
-#endif
+ DEBUG("%s failed parsing tuple\n", __FUNCTION__);
return VIR_PY_INT_FAIL;
}
-#ifdef DEBUG_ERROR
- printf("libvirt_virConnectDomainEventRegister(%p %p %d %p) called\n",
+ DEBUG("libvirt_virConnectDomainEventRegister(%p %p %d %p) called\n",
pyobj_conn, pyobj_dom, eventID, pyobj_cbData);
-#endif
conn = PyvirConnect_Get(pyobj_conn);
if (pyobj_dom == Py_None)
dom = NULL;
@@ -3622,9 +3575,7 @@ libvirt_virConnectDomainEventDeregisterAny(ATTRIBUTE_UNUSED PyObject
* self,
&pyobj_conn, &callbackID))
return (NULL);
-#ifdef DEBUG_ERROR
- printf("libvirt_virConnectDomainEventDeregister(%p) called\n",
pyobj_conn);
-#endif
+ DEBUG("libvirt_virConnectDomainEventDeregister(%p) called\n", pyobj_conn);
conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
--
1.7.4.4