[libvirt] [PATCH python] Report an error if registering an event loop twice

Daniel P. Berrange posted 1 patch 6 years, 7 months ago
Failed in applying to current master (apply log)
libvirt-override.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
[libvirt] [PATCH python] Report an error if registering an event loop twice
Posted by Daniel P. Berrange 6 years, 7 months ago
The C library will now ignore an attempt to register an event
loop twice. It is unable to report an error in this case though
due to the C API returning 'void'. To improve this we must
manually report an error at the python level.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 libvirt-override.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/libvirt-override.c b/libvirt-override.c
index a3a0508..9eba4ed 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -5427,13 +5427,12 @@ static PyObject *
 libvirt_virEventRegisterImpl(PyObject *self ATTRIBUTE_UNUSED,
                              PyObject *args)
 {
-    /* Unref the previously-registered impl (if any) */
-    Py_XDECREF(addHandleObj);
-    Py_XDECREF(updateHandleObj);
-    Py_XDECREF(removeHandleObj);
-    Py_XDECREF(addTimeoutObj);
-    Py_XDECREF(updateTimeoutObj);
-    Py_XDECREF(removeTimeoutObj);
+    if (addHandleObj || updateHandleObj || removeHandleObj ||
+        addTimeoutObj || updateTimeoutObj || removeTimeoutObj) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        "Event loop is already registered");
+        return NULL;
+    }
 
     /* Parse and check arguments */
     if (!PyArg_ParseTuple(args, (char *) "OOOOOO:virEventRegisterImpl",
-- 
2.13.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH python] Report an error if registering an event loop twice
Posted by Michal Privoznik 6 years, 7 months ago
On 09/04/2017 03:06 PM, Daniel P. Berrange wrote:
> The C library will now ignore an attempt to register an event
> loop twice. It is unable to report an error in this case though
> due to the C API returning 'void'. To improve this we must
> manually report an error at the python level.
> 
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> ---
>  libvirt-override.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)

ACK

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list