From: Eric Blake <eblake@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
Markus Armbruster <armbru@redhat.com>
Cc: marcandre.lureau@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/3] qom-qobject: introduce object_property_{g, s}et_ptr
Date: Fri, 24 Feb 2017 10:54:44 -0600 [thread overview]
Message-ID: <488abb9e-d1d3-30ad-18e1-3a00bb7f10d8@redhat.com> (raw)
In-Reply-To: <09c6aaf5-0575-0445-b8bc-400c026a8a68@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 2484 bytes --]
On 02/24/2017 09:29 AM, Paolo Bonzini wrote:
>
>> Here's a non-ducky way to convert between QAPI types. QAPI guarantees
>> that a pointer to a QAPI type is also valid as pointer to its base type.
>> One can do:
>>
>> UserDefOne *one;
>> UserDefOneMore *more;
>>
>> *(UserDefOne *)more = *one; // get UserDefOne into UserDefOneMore
>> // members not in one are untouched
>> *one = *(UserDefOne *)more; // set UserDefOne from UserDefOneMore
>> // members not in one are ignored
And rather than having to write the casts yourself, the generator
produces qapi_UserDefOneMore_base() which returns the proper UserDefOne
pointer (giving you a bit more type safety, and isolates you from any
generator change in layout).
>>
>> Would this technique suffice for your problem?
>
> I am not sure. What I'm trying to do here is to keep backwards
> compatibility in case a device provides UserDefOneMore for a well-known
> property name, and another device provides UserDefOneAnother. As long
> as all devices provide the same (duck-typed) base class, things work.
>
> Maybe the right thing to do would be to define a union, but I wasn't
> sure it was possible to do that in a fully backwards compatible way (can
> you define a union where the discriminator is optional, for example?).
Not yet, although I've discussed the idea of an optional discriminator
several times before. As soon as we have a killer use case where an
optional discriminator makes sense, it shouldn't be too hard to add that
support into the generator.
>
> If you're setting UserDefOne from UserDefOneMore, some of the values are
> going to be lost. Presumably there was a reason why you used
> UserDefOneMore, and therefore an error is the safe bet.
>
> If you're getting UserDefOne from UserDefOneMore, some of the values are
> going to be lost. However, it's reasonable that you didn't even know
> that UserDefOneMore existed, which makes it sensible to allow reading
> into a covariant type.
How often to we add qapi subtypes, but not adjust the rest of the code
base to cope with it existing? Is it going to be less of a maintenance
burden just patching all the uses of the property getters to deal with
the new type than it is to keep the non-strict visitor?
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
next prev parent reply other threads:[~2017-02-24 16:54 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-22 18:04 [Qemu-devel] [PATCH v2 0/3] simplify struct QOM properties and use the result for GUEST_PANICKED Paolo Bonzini
2017-02-22 18:04 ` [Qemu-devel] [PATCH 1/3] qom-qobject: introduce object_property_{g, s}et_ptr Paolo Bonzini
2017-02-22 23:34 ` Eric Blake
2017-02-23 8:33 ` Marc-André Lureau
2017-02-24 14:54 ` Markus Armbruster
2017-02-24 15:29 ` Paolo Bonzini
2017-02-24 16:54 ` Eric Blake [this message]
2017-02-24 17:12 ` Paolo Bonzini
2017-02-24 19:18 ` Markus Armbruster
2017-02-22 18:04 ` [Qemu-devel] [PATCH 2/3] cpu: implement get_crash_info through QOM properties Paolo Bonzini
2017-02-22 18:04 ` [Qemu-devel] [PATCH 3/3] vl: pass CPUState to qemu_system_guest_panicked Paolo Bonzini
2017-02-22 18:13 ` [Qemu-devel] [PATCH v2 0/3] simplify struct QOM properties and use the result for GUEST_PANICKED no-reply
2017-02-23 8:34 ` Marc-André Lureau
-- strict thread matches above, loose matches on Subject: below --
2017-02-21 10:42 [Qemu-devel] [PATCH " Paolo Bonzini
2017-02-21 10:42 ` [Qemu-devel] [PATCH 1/3] qom-qobject: introduce object_property_{g, s}et_ptr Paolo Bonzini
2017-02-21 11:56 ` Paolo Bonzini
2017-02-21 16:36 ` Marc-André Lureau
2017-02-21 15:57 ` Eric Blake
2017-02-21 16:23 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=488abb9e-d1d3-30ad-18e1-3a00bb7f10d8@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).