[Libguestfs] [PATCH nbdkit 2/2] python: More precise Python parameter passing

Nir Soffer nsoffer at redhat.com
Tue Dec 21 22:37:27 UTC 2021


On Wed, Dec 22, 2021 at 12:24 AM Richard W.M. Jones <rjones at redhat.com> wrote:
>
> On Wed, Dec 22, 2021 at 12:03:44AM +0200, Nir Soffer wrote:
> > This is not needed. I think the accepted way to pass boolean values
> > to python is "i". Internally python True and False are 1 and 0, and
> > you can use them as such:
>
> The documentation suggests "p" for bools:
>
> https://docs.python.org/3/c-api/arg.html#c.Py_BuildValue

According to the docs, "p" is only for parsing arguments:
https://docs.python.org/3.6/c-api/arg.html#parsing-arguments

And for building value there is no such option:
https://docs.python.org/3.6/c-api/arg.html#building-values

>
> But that's not relevant for the patch because:
>
> ...
> > However PyObject_CallFunctionObjArgs is more efficient than
> > PyObject_CallFunction
> > so this looks good.
>
> Indeed.
>
> > 0x10_0000_0000 is very confusing, why not 64 * GiB?
> >
> > For the zero count, should we use 2**32 - 1 to make sure zero
> > works with the maximum count?
>
> Is "GiB" defined somewhere?
>
> >>> print(GiB)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> NameError: name 'GiB' is not defined

We use this in vdsm:
https://github.com/oVirt/vdsm/blob/master/lib/vdsm/common/units.py

qemu also have:
https://github.com/qemu/qemu/blob/master/include/qemu/units.h




More information about the Libguestfs mailing list