Re: [PATCH] python: Use PyCapsule API if available

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12/08/2010 10:12 AM, Cole Robinson wrote:
> 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.

ping? I think this should be a safe change.

- Cole

> ---
>  python/typewrappers.c |   89 +++++++++++++++++++++++++++---------------------
>  1 files changed, 50 insertions(+), 39 deletions(-)
> 
> diff --git a/python/typewrappers.c b/python/typewrappers.c
> index 733aa20..e39d3cd 100644
> --- a/python/typewrappers.c
> +++ b/python/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);
>  }

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


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]