[libvirt] [PATCH] python: make virDomainSetSchedulerParameters accpet integer argument
Eric Blake
eblake at redhat.com
Mon Mar 19 18:03:06 UTC 2012
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 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/20120319/7497d75b/attachment-0001.sig>
More information about the libvir-list
mailing list