|
From: | Eric Blake |
Subject: | Re: [Qemu-block] [PATCH 01/13] qapi: Add default-variant for flat unions |
Date: | Thu, 10 May 2018 08:18:22 -0500 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 |
On 05/10/2018 08:12 AM, Eric Blake wrote: Oh, I just had a thought:
+++ b/scripts/qapi/visit.py@@ -40,10 +40,20 @@ def gen_visit_object_members(name, base, members,
if variants: + if variants.default_tag_value is None: + ret += mcgen(''' + %(c_name)s = obj->%(c_name)s; +''', + c_name=c_name(variants.tag_member.name)) + else: + ret += mcgen(''' + if (obj->has_%(c_name)s) { + %(c_name)s = obj->%(c_name)s; + } else { + %(c_name)s = %(enum_const)s;
In this branch of code, is it worth also generating: %has_(c_name)s = true;That way, the rest of the C code does not have to check has_discriminator, because the process of assigning the default will ensure that has_discriminator is always true later on. It does have the effect that output would never omit the discriminator - but that might be a good thing: if we ever have an output union that used to have a mandatory discriminator and want to now make it optional, we don't want to break older clients that expected the discriminator to be present. It does obscure whether input relied on the default, but I don't think that hurts.
-- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
[Prev in Thread] | Current Thread | [Next in Thread] |