[PATCH] python: make virDomainSetSchedulerParameters accpet integer argument

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

 



    When sending a Python integer as an argument to
    PyLong_AsUnsignedLong or PyLong_AsUnsignedLongLong,
    the following error occurs

    SystemError: Objects/longobject.c:980:
    bad argument to internal function

    This error comes from the fact that
    PyLong_AsUnsignedLong and PyLong_AsUnsignedLongLong,
    unlike PyLong_AsLong or PyLong_AsLongLong, does not check
    to see if the number is a long or integer, but only a long.

    The regression is introduced by
    9c8466daac19379c41be39ec8f18db36c9573c02

    >>> dom.setSchedulerParameters({'cpu_shares': 1024})
    0
    dom.schedulerParameters()
    {'cpu_shares': 1024L}
    >>> dom.setSchedulerParameters({'cpu_shares': 1024L})
    0
    >>> dom.schedulerParameters()
    {'cpu_shares': 1024L}
---
 python/libvirt-override.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index 792cfa3..aec8f5a 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -233,7 +233,14 @@ setPyVirTypedParameter(PyObject *info,
         break;
         case VIR_TYPED_PARAM_ULLONG:
         {
-            unsigned long long ullong_val = PyLong_AsUnsignedLongLong(value);
+            unsigned long long ullong_val;
+            if (PyInt_Check(value))
+                ullong_val = (unsigned long long)PyInt_AsLong(value);
+            else if (PyLong_Check(value))
+                ullong_val = PyLong_AsUnsignedLongLong(value);
+            else
+                PyErr_SetString(PyExc_TypeError, "an integer is required");
+
             if ((ullong_val == -1) && PyErr_Occurred())
                 goto cleanup;
             temp->value.ul = ullong_val;
-- 
1.7.7.5

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