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

Re: [libvirt] [PATCH 1/2] python: Add new helper functions for python to C integral conversion



On 03/26/2012 12:10 AM, Guannan Ren wrote:
>     int libvirt_intUnwrap(PyObject *obj, int *val);
>     int libvirt_uintUnwrap(PyObject *obj, unsigned int *val);
>     int libvirt_longUnwrap(PyObject *obj, long *val);
>     int libvirt_ulongUnwrap(PyObject *obj, unsigned long *val);
>     int libvirt_longlongUnwrap(PyObject *obj, long long *val);
>     int libvirt_ulonglongUnwrap(PyObject *obj, unsigned long long *val);
>     int libvirt_doubleUnwrap(PyObject *obj, double *val);
>     int libvirt_boolUnwrap(PyObject *obj, bool *val);
> ---
>  python/typewrappers.c |  142 +++++++++++++++++++++++++++++++++++++++++++++++++
>  python/typewrappers.h |    9 +++
>  2 files changed, 151 insertions(+), 0 deletions(-)
> 

> +int
> +libvirt_boolUnwrap(PyObject *obj, bool *val)
> +{
> +    int ret = -1;
> +
> +    /* We only accept PyInt_Type, PyLong_Type and PyBool_Type
> +     * as the boolean representation.

Why?

> +     */
> +    if (PyInt_Check(obj) ||
> +        PyLong_Check(obj) || PyBool_Check(obj)) {
> +        ret = PyObject_IsTrue(obj);

Why not blindly use PyObject_IsTrue(obj), and accept _all_ objects that
can be converted to python truth values, rather than forcing things to
be PyInt, PyBool, or PyLong?

ACK to the rest of the patch, but I think we want libvirt_boolUnwrap to
be more forgiving.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


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