From: "Michael S. Tsirkin" <mst@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: "Stefan Hajnoczi" <stefanha@linux.vnet.ibm.com>,
"Jan Kiszka" <jan.kiszka@siemens.com>,
"Alexander Graf" <agraf@suse.de>,
qemu-devel@nongnu.org,
"Christian Borntraeger" <borntraeger@de.ibm.com>,
pbonzini@redhat.com, "Andreas Färber" <afaerber@suse.de>
Subject: Re: [Qemu-devel] [PATCHv2] virtio: make bindings typesafe
Date: Tue, 18 Dec 2012 12:53:27 +0200 [thread overview]
Message-ID: <20121218105327.GB22586@redhat.com> (raw)
In-Reply-To: <878v8w5gx9.fsf@codemonkey.ws>
On Mon, Dec 17, 2012 at 06:42:58PM -0600, Anthony Liguori wrote:
> "Michael S. Tsirkin" <mst@redhat.com> writes:
>
> > On Mon, Dec 17, 2012 at 11:59:15PM +0100, Andreas Färber wrote:
> >> Am 17.12.2012 22:40, schrieb Michael S. Tsirkin:
> >> > Move bindings from opaque to DeviceState.
> >> > This gives us better type safety with no performance cost.
> >> > Add macros to make future QOM work easier, document
> >> > which ones are data-path sensitive.
> >> >
> >> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> >> > ---
> >> >
> >> > Changes from v1:
> >> > - Address comment by Anreas Färber: wrap container_of
> >> > macros to make future QOM work easier
> >> > - make a couple of bindings that v1 missed typesafe:
> >> > virtio doesn't use any void * now
> >> >
> >> > diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c
> >> > index e0ac2d1..8c693b4 100644
> >> > --- a/hw/s390-virtio-bus.c
> >> > +++ b/hw/s390-virtio-bus.c
> >> > @@ -137,7 +137,7 @@ static int s390_virtio_device_init(VirtIOS390Device *dev, VirtIODevice *vdev)
> >> >
> >> > bus->dev_offs += dev_len;
> >> >
> >> > - virtio_bind_device(vdev, &virtio_s390_bindings, dev);
> >> > + virtio_bind_device(vdev, &virtio_s390_bindings, VIRTIO_S390_TO_QDEV(dev));
> >>
> >> DEVICE(dev) exists for exactly that purpose, and device init is
> >> certainly no hot path. Please don't reinvent the wheel for virtio.
> >
> > OK.
> > Though my beef with DEVICE is that it ignores the type
> > passed in completely. You can give it int * and it will
> > happily cast to devicestate. Your only hope is to
> > catch the error at runtime.
>
> That's a feature. DEVICE can do upcasting and downcasting. There's no
> way to do compile time checking of upcasting when
>
> > It would be better if DEVICE got the name of the
> > qdev field, then we could check it's actually DeviceState
> > before casting. Yes it would mean a bit of churn if you rename the
> > field but it's very rare and trivial to change by a regexp.
>
> No, it would be much, much worse. You shouldn't have to know what the
> layout of the structure is to convert between types.
Still I'm pointing out the problems, they are real.
Illegal code like
DEVICE("foobar")
compiles fine and it shouldn't.
--
MST
prev parent reply other threads:[~2012-12-18 10:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-17 21:40 [Qemu-devel] [PATCHv2] virtio: make bindings typesafe Michael S. Tsirkin
2012-12-17 22:59 ` Andreas Färber
2012-12-17 23:27 ` Michael S. Tsirkin
2012-12-18 0:42 ` Anthony Liguori
2012-12-18 8:36 ` Michael S. Tsirkin
2012-12-18 10:53 ` Michael S. Tsirkin [this message]
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=20121218105327.GB22586@redhat.com \
--to=mst@redhat.com \
--cc=afaerber@suse.de \
--cc=agraf@suse.de \
--cc=anthony@codemonkey.ws \
--cc=borntraeger@de.ibm.com \
--cc=jan.kiszka@siemens.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@linux.vnet.ibm.com \
/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).