
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@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org