[libvirt] Python binding APIs strict or loose
Eric Blake
eblake at redhat.com
Sun Apr 22 02:36:24 UTC 2012
On 04/20/2012 04:23 AM, Guannan Ren wrote:
>
>
>
> Hi
>
> There is a question. we need strict python binding API
> or loose one.
>
> For example:
> The setSchedulerParameters(), it accepts one of
> parameters: 'vcpu_quota'
> In C its type is of 'long long', then we need a
> conversion from PyInt/PyLong
> to 'long long' by using cpython function
> 'PyLong_AsLongLong'.
> The problem is when the user python pass in a value of
> type Pyfloat instead
> of PyInt/PyLong, the cpython function drops the fraction
> part of the value
> automatically, Is it what we want or we need to add a
> type checking to ensure that
> the type of value passed in is PyInt/PyLong, otherwise,
> we raise an exception.
Or a third option - if it is not PyLong, but is a floating point, then
validate that conversion from floating point to integer and back does
not change the value (that is, there was no fractional value to begin with).
I know C would just truncate unconditionally, but I don't know enough
python coding conventions to know if python programmers expect the same
behavior as C, or if they expect something else. But I do know that
whatever we pick should be consistent - our current approach of
accepting but truncating fractions for int while rejecting fractions for
long long is not consistent.
--
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/20120421/ce64420b/attachment-0001.sig>
More information about the libvir-list
mailing list