Re: [PATCH v3 7/7] python: add bindings for virConnectGetCPUModelNames

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

 



Eric Blake <eblake@xxxxxxxxxx> writes:

> On 09/11/2013 08:13 AM, Giuseppe Scrivano wrote:
>> Signed-off-by: Giuseppe Scrivano <gscrivan@xxxxxxxxxx>
>> ---
>>  python/generator.py             |  2 +-
>>  python/libvirt-override-api.xml |  7 ++++++
>>  python/libvirt-override.c       | 52 +++++++++++++++++++++++++++++++++++++++++
>>  python/libvirt-override.py      | 11 +++++++++
>>  4 files changed, 71 insertions(+), 1 deletion(-)
>> 
>
>> +
>> +    LIBVIRT_BEGIN_ALLOW_THREADS;
>> +
>> +    c_retval = virConnectGetCPUModelNames(conn, arch, &models, flags);
>> +
>> +    LIBVIRT_END_ALLOW_THREADS;
>> +
>> +    if (c_retval == -1)
>> +        return VIR_PY_INT_FAIL;
>> +
>> +    if ((rv = PyList_New(c_retval)) == NULL)
>> +        goto error;
>> +
>> +    for (i = 0; i < c_retval; i++) {
>> +        PyObject *str;
>> +        if ((str = PyString_FromString(models[i])) == NULL)
>> +            goto error;
>> +
>> +        PyList_SET_ITEM(rv, i, str);
>
> Elsewhere, we've used PyList_New(0)/PyList_Append() rather than
> PyList_New(count)/PyList_SET_ITEM(); but that's not universal; also, I
> see uses of PyList_SetItem but not PyList_SET_ITEM; what's the difference?

PyList_SET_ITEM is just an optimized version of PyList_SetItem that
doesn't do any error checking or attempt to release an object already
present in the slot.  It is ok to use here, as we are sure the rv list
is free when we fill it with model names.

I think there are other cases in libvirt-override.c where we can replace
PyList_SetItem with PyList_SET_ITEM without any harm.

Giuseppe

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