提交 4254dfea 编写于 作者: C Cole Robinson

python: Use PyCapsule API if available

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.
上级 8f3b6bc2
...@@ -16,6 +16,26 @@ ...@@ -16,6 +16,26 @@
#include "typewrappers.h" #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 * PyObject *
libvirt_intWrap(int val) libvirt_intWrap(int val)
{ {
...@@ -105,9 +125,8 @@ libvirt_virDomainPtrWrap(virDomainPtr node) ...@@ -105,9 +125,8 @@ libvirt_virDomainPtrWrap(virDomainPtr node)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return (Py_None); return (Py_None);
} }
ret =
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virDomainPtr", ret = libvirt_buildPyObject(node, "virDomainPtr", NULL);
NULL);
return (ret); return (ret);
} }
...@@ -120,9 +139,8 @@ libvirt_virNetworkPtrWrap(virNetworkPtr node) ...@@ -120,9 +139,8 @@ libvirt_virNetworkPtrWrap(virNetworkPtr node)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return (Py_None); return (Py_None);
} }
ret =
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virNetworkPtr", ret = libvirt_buildPyObject(node, "virNetworkPtr", NULL);
NULL);
return (ret); return (ret);
} }
...@@ -135,9 +153,8 @@ libvirt_virInterfacePtrWrap(virInterfacePtr node) ...@@ -135,9 +153,8 @@ libvirt_virInterfacePtrWrap(virInterfacePtr node)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return (Py_None); return (Py_None);
} }
ret =
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virInterfacePtr", ret = libvirt_buildPyObject(node, "virInterfacePtr", NULL);
NULL);
return (ret); return (ret);
} }
...@@ -150,9 +167,8 @@ libvirt_virStoragePoolPtrWrap(virStoragePoolPtr node) ...@@ -150,9 +167,8 @@ libvirt_virStoragePoolPtrWrap(virStoragePoolPtr node)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return (Py_None); return (Py_None);
} }
ret =
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virStoragePoolPtr", ret = libvirt_buildPyObject(node, "virStoragePoolPtr", NULL);
NULL);
return (ret); return (ret);
} }
...@@ -165,9 +181,8 @@ libvirt_virStorageVolPtrWrap(virStorageVolPtr node) ...@@ -165,9 +181,8 @@ libvirt_virStorageVolPtrWrap(virStorageVolPtr node)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return (Py_None); return (Py_None);
} }
ret =
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virStorageVolPtr", ret = libvirt_buildPyObject(node, "virStorageVolPtr", NULL);
NULL);
return (ret); return (ret);
} }
...@@ -180,9 +195,8 @@ libvirt_virConnectPtrWrap(virConnectPtr node) ...@@ -180,9 +195,8 @@ libvirt_virConnectPtrWrap(virConnectPtr node)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return (Py_None); return (Py_None);
} }
ret =
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virConnectPtr", ret = libvirt_buildPyObject(node, "virConnectPtr", NULL);
NULL);
return (ret); return (ret);
} }
...@@ -195,9 +209,8 @@ libvirt_virNodeDevicePtrWrap(virNodeDevicePtr node) ...@@ -195,9 +209,8 @@ libvirt_virNodeDevicePtrWrap(virNodeDevicePtr node)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return (Py_None); return (Py_None);
} }
ret =
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virNodeDevicePtr", ret = libvirt_buildPyObject(node, "virNodeDevicePtr", NULL);
NULL);
return (ret); return (ret);
} }
...@@ -210,7 +223,8 @@ libvirt_virSecretPtrWrap(virSecretPtr node) ...@@ -210,7 +223,8 @@ libvirt_virSecretPtrWrap(virSecretPtr node)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
ret = PyCObject_FromVoidPtrAndDesc(node, (char *) "virSecretPtr", NULL);
ret = libvirt_buildPyObject(node, "virSecretPtr", NULL);
return (ret); return (ret);
} }
...@@ -223,7 +237,8 @@ libvirt_virNWFilterPtrWrap(virNWFilterPtr node) ...@@ -223,7 +237,8 @@ libvirt_virNWFilterPtrWrap(virNWFilterPtr node)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
ret = PyCObject_FromVoidPtrAndDesc(node, (char *) "virNWFilterPtr", NULL);
ret = libvirt_buildPyObject(node, "virNWFilterPtr", NULL);
return (ret); return (ret);
} }
...@@ -236,7 +251,8 @@ libvirt_virStreamPtrWrap(virStreamPtr node) ...@@ -236,7 +251,8 @@ libvirt_virStreamPtrWrap(virStreamPtr node)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
ret = PyCObject_FromVoidPtrAndDesc(node, (char *) "virStreamPtr", NULL);
ret = libvirt_buildPyObject(node, "virStreamPtr", NULL);
return (ret); return (ret);
} }
...@@ -249,9 +265,8 @@ libvirt_virDomainSnapshotPtrWrap(virDomainSnapshotPtr node) ...@@ -249,9 +265,8 @@ libvirt_virDomainSnapshotPtrWrap(virDomainSnapshotPtr node)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return (Py_None); return (Py_None);
} }
ret =
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virDomainSnapshotPtr", ret = libvirt_buildPyObject(node, "virDomainSnapshotPtr", NULL);
NULL);
return (ret); return (ret);
} }
...@@ -265,9 +280,8 @@ libvirt_virEventHandleCallbackWrap(virEventHandleCallback node) ...@@ -265,9 +280,8 @@ libvirt_virEventHandleCallbackWrap(virEventHandleCallback node)
printf("%s: WARNING - Wrapping None\n", __func__); printf("%s: WARNING - Wrapping None\n", __func__);
return (Py_None); return (Py_None);
} }
ret =
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virEventHandleCallback", ret = libvirt_buildPyObject(node, "virEventHandleCallback", NULL);
NULL);
return (ret); return (ret);
} }
...@@ -281,9 +295,8 @@ libvirt_virEventTimeoutCallbackWrap(virEventTimeoutCallback node) ...@@ -281,9 +295,8 @@ libvirt_virEventTimeoutCallbackWrap(virEventTimeoutCallback node)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return (Py_None); return (Py_None);
} }
ret =
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virEventTimeoutCallback", ret = libvirt_buildPyObject(node, "virEventTimeoutCallback", NULL);
NULL);
return (ret); return (ret);
} }
...@@ -296,9 +309,8 @@ libvirt_virFreeCallbackWrap(virFreeCallback node) ...@@ -296,9 +309,8 @@ libvirt_virFreeCallbackWrap(virFreeCallback node)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return (Py_None); return (Py_None);
} }
ret =
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "virFreeCallback", ret = libvirt_buildPyObject(node, "virFreeCallback", NULL);
NULL);
return (ret); return (ret);
} }
...@@ -311,8 +323,7 @@ libvirt_virVoidPtrWrap(void* node) ...@@ -311,8 +323,7 @@ libvirt_virVoidPtrWrap(void* node)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return (Py_None); return (Py_None);
} }
ret =
PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "void*", ret = libvirt_buildPyObject(node, "void*", NULL);
NULL);
return (ret); return (ret);
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册