qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Blue Swirl <blauwirbel@gmail.com>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: Gerd Hoffman <kraxel@redhat.com>,
	Paul Brook <paul@codesourcery.com>,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 2/2] Introduce macro for defining qdev properties
Date: Fri, 17 Jul 2009 21:32:02 +0300	[thread overview]
Message-ID: <f43fc5580907171132x71f65c80pae06a889b4b240ff@mail.gmail.com> (raw)
In-Reply-To: <4A60BEEF.2050601@us.ibm.com>

On Fri, Jul 17, 2009 at 9:11 PM, Anthony Liguori<aliguori@us.ibm.com> wrote:
> Paul Brook wrote:
>>
>> I think I agree. Using GCC extensions for error checking (e.g. DO_UPCAST)
>> or performance (__builtin_clz) is fine, but I'm a reluctant to rely on it
>> for correct operation.
>>
>
> Practically speaking, we've never supported anything but GCC and I doubt we
> ever will.  In this case, it's an important part of something I'm trying to
> fix about the current property system.
>
> It seems very brittle to me.  You have to specify a type in both the state
> structure and in the property definition.  Those two things are very, very
> far apart in the code.  Right now, the rules about type compatible are ill
> defined which makes it more likely to break beyond simple mistakes.  For
> instance, uint32 is used for uint32_t, int32_t, and int.  That seems odd.
>
> I also don't like the fact that we mix field type information with display
> information.  I haven't thought about the best solution to this but I think
> it's either introducing new struct types or adding an optional decorator
> parameter.
>
> The system I'm aiming for looks like this:
>
> typedef struct {
>  SysBusDevice parent;
>
>  /* public */
>  uint32_t queue_depth;
>  uint32_t tx_mitigation_delay;
>  CharDriverState *chr;
>
>  /* private */
>  ...
> } MyDeviceState;
>
> static Property my_device_properties[] = {
>  QDEV_PROP(MyDeviceState, queue_depth),
>  QDEV_PROP(MyDeviceState, tx_mitigation_delay),
>  QDEV_PROP(MyDeviceState, chr),
>  {}
> };
>
> Where there's a connection between properties and device state fields and
> there's no duplicate type information.  That means that for the most part,
> the rules of type compatible can be ignored by most users.
>
> I'd like to see most uses of QDEV_PROP_NAME eliminated by renaming variables
> and accepting '-' in place of '_'.  We'll always need a way to accept
> default values.
>
> 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:

typedef struct MyDeviceState {
#define PROP(type, name) type name;
#define C_TYPE
#include "mydevice_props.hx"
} MyDeviceState;
#undef PROP
#undef C_TYPE

static Property my_device_properties[] = {
#define PROP(type, name) glue(QDEV_PROP_, type)(MyDeviceState, name),
#include "mydevice_props.hx"
 {}
};

Where mydevice_props.hx contains:
#ifdef C_TYPE
#define I32 uint32_t
#define I64 uint64_t
#define CHRDEV CharDriverState *
#endif

PROP(I32, queue_depth)
PROP(I32, tx_mitigation_delay)
PROP(CHRDEV, chr)

  reply	other threads:[~2009-07-17 18:32 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 [this message]
2009-07-17 20:05           ` Anthony Liguori
2009-07-17 22:58             ` Paul Brook
2009-07-18 12:43               ` Jamie Lokier
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=f43fc5580907171132x71f65c80pae06a889b4b240ff@mail.gmail.com \
    --to=blauwirbel@gmail.com \
    --cc=aliguori@us.ibm.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).