qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [RFC PATCH] qapi: Allow setting default values for opti


From: Eric Blake
Subject: Re: [Qemu-devel] [RFC PATCH] qapi: Allow setting default values for optional parameters
Date: Fri, 18 Apr 2014 15:15:09 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0

On 04/16/2014 12:04 AM, Fam Zheng wrote:
> In command definition, 'default' is now parsed as a dict of default
> values. Only optional parameters will have effect in generated code.

Can you make the python code explicitly error out for a default supplied
for a parameter not marked with * in data?

> 
> 'str' and 'int' are supported, both need single quote in the schema. In
> generated code, 'str' will be converted to g_strdup'ed pointer, 'int'
> will be identically set.
> 
> E.g.
> 
>     { 'command': 'block-commit',
>       'data': { 'device': 'str', '*base': 'str', 'top': 'str',
>                 '*speed': 'int' },
>       'default': {'base': 'earthquake', 'speed': '100' } }

'data' is plural, 'default' is singular; should it be named 'defaults'?

> 
> will generate
> 
>     int qmp_marshal_input_block_commit(Monitor *mon, const QDict *qdict, 
> QObject **ret)
>     {
>         ...
>         bool has_base = true;
>         char * base = g_strdup("earthquake");

Any reason the generator can't be fixed to avoid the space after '*'?

>         ...
>         bool has_speed = true;
>         int64_t speed = 100;

Looks like it would work.  But why not allow a JSON integer for an
integer default:

'data': { '*base': 'str', '*speed', 'int' },
'default': { 'base': 'earthquake', 'speed': 100 },

I'm not sure if that adds or reduces complexity; by using JSON types as
the default, you have to add code in the generator to ensure correct
type usage.  But it also opens the possibility of providing a default
for a struct, rather than limiting to just strings and integers.

> 
> Signed-off-by: Fam Zheng <address@hidden>
> ---
>  scripts/qapi-commands.py | 24 +++++++++++++++++-------
>  scripts/qapi.py          |  8 ++++++++
>  2 files changed, 25 insertions(+), 7 deletions(-)

Missing documentation and tests.  Docs to docs/qapi-code-gen.txt.

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

[Prev in Thread] Current Thread [Next in Thread]