On 07/19/2013 05:04 AM, Pawit Pornkitprasan wrote:
> On Fri, Jul 19, 2013 at 7:57 PM, Eric Blake <ebl...@redhat.com> wrote:
>>
>> However, wouldn't it be nice if we improved the qapi generator to
>> guarantee a sane default value for optional parameters, even when
>> has_value is false?
>>
> 
> I'm not a qemu expert or anything, but wouldn't that destroy the point
> of has_value in the first place?

There are two uses for has_value.  One: on output, the user knows
whether the variable has been set to anything sane.  Two: on input, the
receiver knows if the caller passed an optional value.  For output,
has_value is always needed.  But for input, we could probably simplify a
LOT of code if 'value' already had a sane default of 0, without having
to first check 'has_value', instead of the current state where 'value'
must be treated as uninitialized if 'has_value' is false.  Improving the
qapi generator to guarantee 0 value of optional parameters that were not
specified in JSON should not block your patch (it would be a series by
itself), it's just a question of whether it is worth making the change
and the resulting simplifications we can make to code that can assume
sane default values.

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

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to