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

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

 



On 03/27/2012 07:03 AM, Eric Blake wrote:

+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?

        If we don't check here, these APIs which use libvirt_boolUnwrap
   will not have any checking for its type of arguments in bool wise.
   The upper python code could pass a null list or dictionary as a False.
Maybe a little bit loose use here. but It's fine to blindly use it actually.

    Guannan Ren

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