Re: [PATCH v2] python: add virDomainGetCPUStats python binding API

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

 



On 03/21/2012 01:35 AM, Guannan Ren wrote:

>      will become:
>             if (PyBool_Check(value)) {

Why do we have to require a PyBool?  My reading of PyObject_IsTrue is
that it can convert other python objects to a boolean truth value, which
is more flexible.

>                  temp->value.b = PyObject_IsTrue(value) ? 1 : 0;

PyObject_IsTrue is tri-state; it can return failure.  You don't want to
map failure to true.

>             } else {
>                 PyErr_Format(PyExc_TypeError,
>                              "The value type of "
>                              "attribute \"%s\" must be bool", keystr);
>                 goto cleanup;
>             }

Maybe we need a wrapper:

int libvirt_boolUnwrap(PyObject *obj, bool *value) {
    int ret = PyObject_IsTrue(obj);
    if (ret < 0)
        return ret;
    *value = ret > 0;
    return 0;
}

and then callers become:

    if (libvirt_boolUnwrap(value, &temp->value.b) < 0)
        goto cleanup;

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

Attachment: signature.asc
Description: OpenPGP digital signature

--
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]