
On 03/19/2012 11:45 AM, Guannan Ren wrote:
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
+++ 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;
Pre-initialize this to -1; otherwise...
+ if (PyInt_Check(value)) + ullong_val = (unsigned long long)PyInt_AsLong(value);
Cast is unnecessary.
+ 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())
...if I don't pass in PyInt or PyLong, then this error detection will be based on uninitialized memory. Why are you doing this for just VIR_TYPED_PARAM_ULLONG? I argue that we should be doing it for all of the integral conversions. Needs a v2. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org