From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Damien Hedde <damien.hedde@greensocs.com>,
qemu-arm <qemu-arm@nongnu.org>,
QEMU Developers <qemu-devel@nongnu.org>,
Juan Quintela <quintela@redhat.com>
Subject: Re: [Qemu-arm] [PATCH for-4.1? 2/2] vmstate.h: Type check VMSTATE_STRUCT_VARRAY macros
Date: Fri, 26 Jul 2019 10:32:08 +0100 [thread overview]
Message-ID: <20190726093208.GC2657@work-vm> (raw)
In-Reply-To: <CAFEAcA8T25Fq5wj8a-K9KAyXdfj3+HtW=kTJ13zr+-iHFz4-GA@mail.gmail.com>
* Peter Maydell (peter.maydell@linaro.org) wrote:
> On Thu, 25 Jul 2019 at 19:00, Dr. David Alan Gilbert
> <dgilbert@redhat.com> wrote:
> >
> > * Peter Maydell (peter.maydell@linaro.org) wrote:
> > > On Thu, 25 Jul 2019 at 18:27, Dr. David Alan Gilbert
> > > <dgilbert@redhat.com> wrote:
> > > >
> > > > * Peter Maydell (peter.maydell@linaro.org) wrote:
> > > > > #define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0)
> > > > > +/* Check that t2 is an array of t1 of size n */
> > > > > #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
> > > >
> > > > I'd have to admit I don't understand why that does what you say;
> > > > I'd expected something to index a t2 pointer with [n].
> > >
> > > Note that this is just a comment describing what the existing
> > > macro does, as a way to distinguish its job from that of the
> > > new macro I'm adding.
> > >
> > > What happens here is that t2 is a type like "foo [32]", ie
> > > it is an array type already. t1 is the base 'foo' type; so the macro
> > > is checking that t1[n] matches t2, where n is passed in to us
> > > and must match the declared array size of the field (32 in
> > > my example). (In C the size of the array is carried around as
> > > part of its type, and must match on both sides of the expression;
> > > so if you pass in the name of an array field that's the wrong size the
> > > type check will fail, which is what we want.)
> >
> > Ah, OK that makes sense; what it really needs is that example to make
> > me realise that t2 was already the array.
>
> Would
>
> /*
> * Check that type t2 is an array of type t1 of size n,
> * eg if t1 is 'foo' and n is 32 then t2 must be 'foo[32]'
> */
>
> be clearer ?
Yep.
Dave
> thanks
> -- PMM
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
WARNING: multiple messages have this Message-ID (diff)
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Damien Hedde <damien.hedde@greensocs.com>,
qemu-arm <qemu-arm@nongnu.org>,
QEMU Developers <qemu-devel@nongnu.org>,
Juan Quintela <quintela@redhat.com>
Subject: Re: [Qemu-devel] [PATCH for-4.1? 2/2] vmstate.h: Type check VMSTATE_STRUCT_VARRAY macros
Date: Fri, 26 Jul 2019 10:32:08 +0100 [thread overview]
Message-ID: <20190726093208.GC2657@work-vm> (raw)
In-Reply-To: <CAFEAcA8T25Fq5wj8a-K9KAyXdfj3+HtW=kTJ13zr+-iHFz4-GA@mail.gmail.com>
* Peter Maydell (peter.maydell@linaro.org) wrote:
> On Thu, 25 Jul 2019 at 19:00, Dr. David Alan Gilbert
> <dgilbert@redhat.com> wrote:
> >
> > * Peter Maydell (peter.maydell@linaro.org) wrote:
> > > On Thu, 25 Jul 2019 at 18:27, Dr. David Alan Gilbert
> > > <dgilbert@redhat.com> wrote:
> > > >
> > > > * Peter Maydell (peter.maydell@linaro.org) wrote:
> > > > > #define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0)
> > > > > +/* Check that t2 is an array of t1 of size n */
> > > > > #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
> > > >
> > > > I'd have to admit I don't understand why that does what you say;
> > > > I'd expected something to index a t2 pointer with [n].
> > >
> > > Note that this is just a comment describing what the existing
> > > macro does, as a way to distinguish its job from that of the
> > > new macro I'm adding.
> > >
> > > What happens here is that t2 is a type like "foo [32]", ie
> > > it is an array type already. t1 is the base 'foo' type; so the macro
> > > is checking that t1[n] matches t2, where n is passed in to us
> > > and must match the declared array size of the field (32 in
> > > my example). (In C the size of the array is carried around as
> > > part of its type, and must match on both sides of the expression;
> > > so if you pass in the name of an array field that's the wrong size the
> > > type check will fail, which is what we want.)
> >
> > Ah, OK that makes sense; what it really needs is that example to make
> > me realise that t2 was already the array.
>
> Would
>
> /*
> * Check that type t2 is an array of type t1 of size n,
> * eg if t1 is 'foo' and n is 32 then t2 must be 'foo[32]'
> */
>
> be clearer ?
Yep.
Dave
> thanks
> -- PMM
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
next prev parent reply other threads:[~2019-07-26 9:32 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-25 16:37 [Qemu-arm] [PATCH for-4.1? 0/2] Typecheck VMSTATE VARRAY macros and fix bug found Peter Maydell
2019-07-25 16:37 ` [Qemu-devel] " Peter Maydell
2019-07-25 16:37 ` [Qemu-devel] [PATCH for-4.1? 1/2] stellaris_input: Fix vmstate description of buttons field Peter Maydell
2019-07-25 17:02 ` [Qemu-arm] " Dr. David Alan Gilbert
2019-07-25 17:02 ` [Qemu-devel] " Dr. David Alan Gilbert
2019-07-25 17:40 ` [Qemu-arm] " Philippe Mathieu-Daudé
2019-07-25 17:40 ` Philippe Mathieu-Daudé
2019-07-26 9:52 ` [Qemu-arm] " Peter Maydell
2019-07-26 9:52 ` Peter Maydell
2019-07-26 9:59 ` [Qemu-arm] " Dr. David Alan Gilbert
2019-07-26 9:59 ` Dr. David Alan Gilbert
2019-07-26 10:03 ` [Qemu-arm] " Peter Maydell
2019-07-26 10:03 ` Peter Maydell
2019-07-25 17:59 ` [Qemu-arm] " Peter Maydell
2019-07-25 17:59 ` [Qemu-devel] " Peter Maydell
2019-07-25 18:32 ` [Qemu-arm] " Dr. David Alan Gilbert
2019-07-25 18:32 ` [Qemu-devel] " Dr. David Alan Gilbert
2019-07-26 8:25 ` [Qemu-arm] " Damien Hedde
2019-07-26 8:25 ` Damien Hedde
2019-07-26 8:47 ` [Qemu-arm] " Peter Maydell
2019-07-26 8:47 ` Peter Maydell
2019-07-25 16:37 ` [Qemu-devel] [PATCH for-4.1? 2/2] vmstate.h: Type check VMSTATE_STRUCT_VARRAY macros Peter Maydell
2019-07-25 17:27 ` [Qemu-arm] " Dr. David Alan Gilbert
2019-07-25 17:27 ` [Qemu-devel] " Dr. David Alan Gilbert
2019-07-25 17:57 ` [Qemu-arm] " Peter Maydell
2019-07-25 17:57 ` [Qemu-devel] " Peter Maydell
2019-07-25 18:00 ` [Qemu-arm] " Dr. David Alan Gilbert
2019-07-25 18:00 ` [Qemu-devel] " Dr. David Alan Gilbert
2019-07-26 9:24 ` [Qemu-arm] " Peter Maydell
2019-07-26 9:24 ` [Qemu-devel] " Peter Maydell
2019-07-26 9:32 ` Dr. David Alan Gilbert [this message]
2019-07-26 9:32 ` Dr. David Alan Gilbert
2019-07-26 9:33 ` [Qemu-arm] " Peter Maydell
2019-07-26 9:33 ` [Qemu-devel] " Peter Maydell
2019-07-26 9:34 ` [Qemu-arm] " Dr. David Alan Gilbert
2019-07-26 9:34 ` [Qemu-devel] " Dr. David Alan Gilbert
2019-07-26 9:12 ` [Qemu-arm] " Damien Hedde
2019-07-26 9:12 ` Damien Hedde
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=20190726093208.GC2657@work-vm \
--to=dgilbert@redhat.com \
--cc=damien.hedde@greensocs.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.