summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCole Robinson <crobinso@redhat.com>2010-12-02 12:15:10 -0500
committerCole Robinson <crobinso@redhat.com>2011-01-10 15:18:05 -0500
commitaa37abae901eaf6114f96dc24d6478fd1099192a (patch)
tree745baaf9f7f450d3fa43c90365cb9c9ad5c4fca8
parent1e025b834b7f5cdd677d29a6c78e3edbecc839a4 (diff)
downloadlibvirt-python-split-aa37abae901eaf6114f96dc24d6478fd1099192a.tar.gz
libvirt-python-split-aa37abae901eaf6114f96dc24d6478fd1099192a.tar.xz
libvirt-python-split-aa37abae901eaf6114f96dc24d6478fd1099192a.zip
python: Use PyCapsule API if availablev0.8.8
On Fedore 14, virt-manager spews a bunch of warnings to the console: /usr/lib64/python2.7/site-packages/libvirt.py:1781: PendingDeprecationWarning: The CObject type is marked Pending Deprecation in Python 2.7. Please use capsule objects instead. Have libvirt use the capsule API if available. I've verified this compiles fine on older python (2.6 in RHEL6 which doesn't have capsules), and virt-manager seems to function fine.
-rw-r--r--typewrappers.c89
1 files changed, 50 insertions, 39 deletions
diff --git a/typewrappers.c b/typewrappers.c
index 733aa20..e39d3cd 100644
--- a/typewrappers.c
+++ b/typewrappers.c
@@ -16,6 +16,26 @@
#include "typewrappers.h"
+#ifndef Py_CAPSULE_H
+typedef void(*PyCapsule_Destructor)(void *, void *);
+#endif
+
+static PyObject *
+libvirt_buildPyObject(void *cobj,
+ const char *name,
+ PyCapsule_Destructor destr)
+{
+ PyObject *ret;
+
+#ifdef Py_CAPSULE_H
+ ret = PyCapsule_New(cobj, name, destr);
+#else
+ ret = PyCObject_FromVoidPtrAndDesc(cobj, (void *) name, destr);
+#endif /* _TEST_CAPSULE */
+
+ return ret;
+}
+
PyObject *
libvirt_intWrap(int val)
{
@@ -105,9 +125,8 @@ libvirt_virDomainPtrWrap(virDomainPtr node)
Py_INCREF(Py_None);
return (Py_None);
}
- ret =
- PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virDomainPtr",
- NULL);
+
+ ret = libvirt_buildPyObject(node, "virDomainPtr", NULL);
return (ret);
}
@@ -120,9 +139,8 @@ libvirt_virNetworkPtrWrap(virNetworkPtr node)
Py_INCREF(Py_None);
return (Py_None);
}
- ret =
- PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virNetworkPtr",
- NULL);
+
+ ret = libvirt_buildPyObject(node, "virNetworkPtr", NULL);
return (ret);
}
@@ -135,9 +153,8 @@ libvirt_virInterfacePtrWrap(virInterfacePtr node)
Py_INCREF(Py_None);
return (Py_None);
}
- ret =
- PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virInterfacePtr",
- NULL);
+
+ ret = libvirt_buildPyObject(node, "virInterfacePtr", NULL);
return (ret);
}
@@ -150,9 +167,8 @@ libvirt_virStoragePoolPtrWrap(virStoragePoolPtr node)
Py_INCREF(Py_None);
return (Py_None);
}
- ret =
- PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virStoragePoolPtr",
- NULL);
+
+ ret = libvirt_buildPyObject(node, "virStoragePoolPtr", NULL);
return (ret);
}
@@ -165,9 +181,8 @@ libvirt_virStorageVolPtrWrap(virStorageVolPtr node)
Py_INCREF(Py_None);
return (Py_None);
}
- ret =
- PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virStorageVolPtr",
- NULL);
+
+ ret = libvirt_buildPyObject(node, "virStorageVolPtr", NULL);
return (ret);
}
@@ -180,9 +195,8 @@ libvirt_virConnectPtrWrap(virConnectPtr node)
Py_INCREF(Py_None);
return (Py_None);
}
- ret =
- PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virConnectPtr",
- NULL);
+
+ ret = libvirt_buildPyObject(node, "virConnectPtr", NULL);
return (ret);
}
@@ -195,9 +209,8 @@ libvirt_virNodeDevicePtrWrap(virNodeDevicePtr node)
Py_INCREF(Py_None);
return (Py_None);
}
- ret =
- PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virNodeDevicePtr",
- NULL);
+
+ ret = libvirt_buildPyObject(node, "virNodeDevicePtr", NULL);
return (ret);
}
@@ -210,7 +223,8 @@ libvirt_virSecretPtrWrap(virSecretPtr node)
Py_INCREF(Py_None);
return Py_None;
}
- ret = PyCObject_FromVoidPtrAndDesc(node, (char *) "virSecretPtr", NULL);
+
+ ret = libvirt_buildPyObject(node, "virSecretPtr", NULL);
return (ret);
}
@@ -223,7 +237,8 @@ libvirt_virNWFilterPtrWrap(virNWFilterPtr node)
Py_INCREF(Py_None);
return Py_None;
}
- ret = PyCObject_FromVoidPtrAndDesc(node, (char *) "virNWFilterPtr", NULL);
+
+ ret = libvirt_buildPyObject(node, "virNWFilterPtr", NULL);
return (ret);
}
@@ -236,7 +251,8 @@ libvirt_virStreamPtrWrap(virStreamPtr node)
Py_INCREF(Py_None);
return Py_None;
}
- ret = PyCObject_FromVoidPtrAndDesc(node, (char *) "virStreamPtr", NULL);
+
+ ret = libvirt_buildPyObject(node, "virStreamPtr", NULL);
return (ret);
}
@@ -249,9 +265,8 @@ libvirt_virDomainSnapshotPtrWrap(virDomainSnapshotPtr node)
Py_INCREF(Py_None);
return (Py_None);
}
- ret =
- PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virDomainSnapshotPtr",
- NULL);
+
+ ret = libvirt_buildPyObject(node, "virDomainSnapshotPtr", NULL);
return (ret);
}
@@ -265,9 +280,8 @@ libvirt_virEventHandleCallbackWrap(virEventHandleCallback node)
printf("%s: WARNING - Wrapping None\n", __func__);
return (Py_None);
}
- ret =
- PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virEventHandleCallback",
- NULL);
+
+ ret = libvirt_buildPyObject(node, "virEventHandleCallback", NULL);
return (ret);
}
@@ -281,9 +295,8 @@ libvirt_virEventTimeoutCallbackWrap(virEventTimeoutCallback node)
Py_INCREF(Py_None);
return (Py_None);
}
- ret =
- PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virEventTimeoutCallback",
- NULL);
+
+ ret = libvirt_buildPyObject(node, "virEventTimeoutCallback", NULL);
return (ret);
}
@@ -296,9 +309,8 @@ libvirt_virFreeCallbackWrap(virFreeCallback node)
Py_INCREF(Py_None);
return (Py_None);
}
- ret =
- PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virFreeCallback",
- NULL);
+
+ ret = libvirt_buildPyObject(node, "virFreeCallback", NULL);
return (ret);
}
@@ -311,8 +323,7 @@ libvirt_virVoidPtrWrap(void* node)
Py_INCREF(Py_None);
return (Py_None);
}
- ret =
- PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "void*",
- NULL);
+
+ ret = libvirt_buildPyObject(node, "void*", NULL);
return (ret);
}