On 03/21/2012 07:22 AM, Guannan Ren wrote:
> On 03/21/2012 08:07 PM, Eric Blake wrote:
>> Maybe we need a wrapper:
>>
>> int libvirt_boolUnwrap(PyObject *obj, bool *value) {
>>      int ret = PyObject_IsTrue(obj);
>>      if (ret<  0)
>>          return ret;
>>      *value = ret>  0;
>>      return 0;
>> }
>>
>> and then callers become:
>>
>>      if (libvirt_boolUnwrap(value,&temp->value.b)<  0)
>>          goto cleanup;
>>
> 
>      The libvirt_boolUnwrap is okay to be flexible like this, we still need
>    the caller to check whether or not the value given from user python code
>    is boolean argument, we need to do the data type checking in python C
> API
>    before invoking the wrapper.

But that's my point - the wrapper should be doing the type checking
(PyObject_IsTrue already _does_ some type checking - that's why it can
fail with -1 with an already decent python exception created).  Callers
shouldn't have to duplicate the work which can be done in just one
place, but instead just pass in an object of unknown type and let the
wrapper do the work of both type validation and conversion if the type
was usable as a boolean.

-- 
Eric Blake   ebl...@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to