qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v4 04/14] qapi: Allow optional discriminators


From: Markus Armbruster
Subject: Re: [Qemu-devel] [PATCH v4 04/14] qapi: Allow optional discriminators
Date: Thu, 21 Nov 2019 16:13:47 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux)

Max Reitz <address@hidden> writes:

> Optional discriminators are fine, as long as there is a default value.
>
> Signed-off-by: Max Reitz <address@hidden>
> ---
>  scripts/qapi/common.py | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
> index 8c57d0c67a..203623795b 100644
> --- a/scripts/qapi/common.py
> +++ b/scripts/qapi/common.py
> @@ -1052,11 +1052,21 @@ def check_union(expr, info):
>          base_members = find_base_members(base)
>          assert base_members is not None
>  
> -        # The value of member 'discriminator' must name a non-optional
> -        # member of the base struct.
> +        # The value of member 'discriminator' must name a member of
> +        # the base struct.  (Optional members are allowed, but the
> +        # discriminator name must not start with '*', so keep
> +        # allow_optional=False.)
>          check_name(info, "Discriminator of flat union '%s'" % name,
>                     discriminator)
> +
>          discriminator_value = base_members.get(discriminator)
> +        if not discriminator_value:
> +            discriminator_value = base_members.get('*' + discriminator)
> +            if discriminator_value and 'default' not in discriminator_value:
> +                raise QAPISemError(info,
> +                    "Optional discriminator '%s' has no default value" %
> +                    discriminator)
> +
>          if not discriminator_value:
>              raise QAPISemError(info,
>                                 "Discriminator '%s' is not a member of base "

Needs test coverage and doc update.

Oh, looks like later patches provide.  Please consider squashing.  Doc
updates and tests often make code changes easier to understand.




reply via email to

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