[libvirt] [PATCH v2] python: add virDomainGetCPUStats python binding API
Eric Blake
eblake at redhat.com
Wed Mar 21 12:07:37 UTC 2012
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 at redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120321/92d50d6b/attachment-0001.sig>
More information about the libvir-list
mailing list