[libvirt] [PATCH python 08/14] override: Replace PyInt_AsLong with helper

Daniel P. Berrange berrange at redhat.com
Mon Dec 9 15:15:43 UTC 2013


From: "Daniel P. Berrange" <berrange at redhat.com>

Replace use of the PyInt_AsLong libvirt_intUnwrap helper.
This isolates the need for Python3 specific code in one
place

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

diff --git a/libvirt-override.c b/libvirt-override.c
index 3334c3f..9a013ca 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -5177,10 +5177,8 @@ libvirt_virEventAddHandleFunc  (int fd,
     if (!result) {
         PyErr_Print();
         PyErr_Clear();
-    } else if (!PyInt_Check(result)) {
-        DEBUG("%s: %s should return an int\n", __FUNCTION__, NAME(addHandle));
     } else {
-        retval = (int)PyInt_AsLong(result);
+        libvirt_intUnwrap(result, &retval);
     }
 
     Py_XDECREF(result);
@@ -5304,10 +5302,8 @@ libvirt_virEventAddTimeoutFunc(int timeout,
     if (!result) {
         PyErr_Print();
         PyErr_Clear();
-    } else if (!PyInt_Check(result)) {
-        DEBUG("%s: %s should return an int\n", __FUNCTION__, NAME(addTimeout));
     } else {
-        retval = (int)PyInt_AsLong(result);
+        libvirt_intUnwrap(result, &retval);
     }
 
     Py_XDECREF(result);
@@ -6825,7 +6821,7 @@ libvirt_virDomainSendKey(PyObject *self ATTRIBUTE_UNUSED,
     }
 
     for (i = 0; i < nkeycodes; i++) {
-        keycodes[i] = (int)PyInt_AsLong(PyList_GetItem(pyobj_list, i));
+        libvirt_uintUnwrap(PyList_GetItem(pyobj_list, i), &(keycodes[i]));
     }
 
     LIBVIRT_BEGIN_ALLOW_THREADS;
-- 
1.8.3.1




More information about the libvir-list mailing list