qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jamie Lokier <jamie@shareable.org>
To: Paul Brook <paul@codesourcery.com>
Cc: Blue Swirl <blauwirbel@gmail.com>,
	Anthony Liguori <aliguori@us.ibm.com>,
	qemu-devel@nongnu.org, Gerd Hoffman <kraxel@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 2/2] Introduce macro for defining qdev properties
Date: Sat, 18 Jul 2009 13:43:49 +0100	[thread overview]
Message-ID: <20090718124349.GA9677@shareable.org> (raw)
In-Reply-To: <200907172358.43108.paul@codesourcery.com>

Paul Brook wrote:
> On Friday 17 July 2009, Anthony Liguori wrote:
> > Blue Swirl wrote:
> > >> I'm not sure how to do this without GCC extensions.  We could
> > >> potentially add macro decorators and use a sparse-like tool to extract
> > >> property lists automatically from device state.
> > >
> > > Then there is the template way:
> >
> > Yes, I also considered that.
> >
> > Another option would be comment decorators along with a post-processor.
> 
> QDEV_PROP(uint32, field) and QDEV_PROP_UINT32(field) are pretty much 
> isomorphic. Both cases it can be implemented with standard C preprocessor 
> functionality, and maybe GCC extensions for compile time checking. I don't 
> mind requiring gcc for debug builds and consistency checking.
> 
> There is some duplication, with the type specified in both the property macro 
> and the structure member definition. As long as we have compile time checking 
> I'm willing to accept that.
> 
> 
> However I don't think it is possible to implement QDEV_PROP(field) without 
> fancy GCC extensions or fairly invasive preprocessing. It feels a little too 
> clever for comfort, verging on a custom device description langage.

In (hopefully) ANSI-portable C code which performs a very similar
function, I got it down to OPTION_SIGNED("name", var),
OPTION_UNSIGNED("name", var), OPTION_BOOL("name", var),
OPTION_STRING("name", var), for the major non-compound types.

For enums, OPTION_ENUM("name", var, ), ENUM("this", THIS),
ENUM("that", THAT), for good value checking, or OPTION_ENUM("name",
var, "this|that|other") if you're confident that the numeric
values are sequential.

Lists, vectors, bounds checks and predicates are easily supplied.

I suspect with C99 varargs macros and compound initialisers (both
supported by GCC) it can be rather tidier, but I didn't explore that.

Then OPTION_SIGNED_RANGE("name", var, 0, 99) and OPTION_UNSIGNED_RANGE
provide nice bounds checks in many cases.

I never found a way to eliminate the SIGNED/UNSIGNED/FLOAT/BOOL
distinction portably, due to the constant-expression rules for global
initialisers.

-- Jamie

  reply	other threads:[~2009-07-18 12:44 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-17 14:41 [Qemu-devel] [PATCH 0/2][RFC] Introduce macros for setting properties Anthony Liguori
2009-07-17 14:41 ` [Qemu-devel] [PATCH 1/2] Introduce CharDriverState qdev property type Anthony Liguori
2009-07-21 14:46   ` [Qemu-devel] " Gerd Hoffmann
2009-07-21 14:53     ` Anthony Liguori
2009-07-21 15:03       ` Gerd Hoffmann
2009-07-21 15:14         ` Gerd Hoffmann
2009-07-21 15:23         ` Anthony Liguori
2009-07-21 15:34           ` Gerd Hoffmann
2009-07-21 15:47             ` Anthony Liguori
2009-07-22  9:48               ` Gerd Hoffmann
2009-07-17 14:41 ` [Qemu-devel] [PATCH 2/2] Introduce macro for defining qdev properties Anthony Liguori
2009-07-17 17:23   ` Blue Swirl
2009-07-17 17:26     ` Anthony Liguori
2009-07-17 17:33     ` Paul Brook
2009-07-17 18:11       ` Anthony Liguori
2009-07-17 18:32         ` Blue Swirl
2009-07-17 20:05           ` Anthony Liguori
2009-07-17 22:58             ` Paul Brook
2009-07-18 12:43               ` Jamie Lokier [this message]
2009-07-18 16:13                 ` Anthony Liguori
2009-07-20  2:29                   ` Jamie Lokier
2009-07-21  8:30   ` [Qemu-devel] " Gerd Hoffmann

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=20090718124349.GA9677@shareable.org \
    --to=jamie@shareable.org \
    --cc=aliguori@us.ibm.com \
    --cc=blauwirbel@gmail.com \
    --cc=kraxel@redhat.com \
    --cc=paul@codesourcery.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).