All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: Paul Brook <paul@codesourcery.com>
Cc: qemu-devel@nongnu.org, Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: [Qemu-devel] [RfC PATCH] qdev: helper macros for properties
Date: Thu, 16 Jul 2009 22:17:41 -0500	[thread overview]
Message-ID: <4A5FED55.3080008@codemonkey.ws> (raw)
In-Reply-To: <200907170123.48369.paul@codesourcery.com>

[-- Attachment #1: Type: text/plain, Size: 484 bytes --]

Paul Brook wrote:
> On Wednesday 15 July 2009, Gerd Hoffmann wrote:
>   
>>   Hi,
>>
>> New revision of the helper macros for defining properties, going on top
>> of all other qdev patches posted today.
>>     
>
> IMO this should have been part of the initial properties rework, not a 
> followup change. Use of these macros should not be optional.
>   

For the common case, I'd rather something like the following.  Very GCC 
specific.

Regards,

Anthony Liguori

> Paul
>
>
>   


[-- Attachment #2: qdev-prop.patch --]
[-- Type: text/x-patch, Size: 2540 bytes --]

commit a7e2799c7c3c790c83e015b48ba34ac0975b93bb
Author: Anthony Liguori <aliguori@us.ibm.com>
Date:   Thu Jul 16 22:16:02 2009 -0500

    Introduce macro for defining qdev properties.
    
    Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

diff --git a/hw/escc.c b/hw/escc.c
index 9abd092..43230b9 100644
--- a/hw/escc.c
+++ b/hw/escc.c
@@ -952,21 +952,9 @@ static SysBusDeviceInfo escc_info = {
     .qdev.name  = "escc",
     .qdev.size  = sizeof(SerialState),
     .qdev.props = (Property[]) {
-        {
-            .name = "frequency",
-            .info = &qdev_prop_uint32,
-            .offset = offsetof(SerialState, frequency),
-        },
-        {
-            .name = "it_shift",
-            .info = &qdev_prop_uint32,
-            .offset = offsetof(SerialState, it_shift),
-        },
-        {
-            .name = "disabled",
-            .info = &qdev_prop_uint32,
-            .offset = offsetof(SerialState, disabled),
-        },
+        QDEV_PROP(SerialState, frequency),
+        QDEV_PROP(SerialState, it_shift),
+        QDEV_PROP(SerialState, disabled),
         {
             .name = "chrB",
             .info = &qdev_prop_ptr,
diff --git a/hw/qdev.h b/hw/qdev.h
index 11744fa..957ce22 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -143,6 +143,25 @@ void do_info_qtree(Monitor *mon);
 
 /*** qdev-properties.c ***/
 
+#define CHOOSE(a, b, c) __builtin_choose_expr(a, b, c)
+#define TYPES_COMPAT(a, b) __builtin_types_compatible_p(a, b)
+#define TYPEOF_FIELD(type, field) typeof(((type *)0)->field)
+#define BUILD_BUG() sizeof(char[-1])
+
+#define QDEV_PROP(type, field)                                     \
+    {                                                              \
+        .name = stringify(field),                                  \
+        .offset = offsetof(type, field),                           \
+        .info =                                                    \
+        CHOOSE(TYPES_COMPAT(TYPEOF_FIELD(type, field), uint32_t),  \
+        &qdev_prop_uint32,                                         \
+        CHOOSE(TYPES_COMPAT(TYPEOF_FIELD(type, field), int32_t),   \
+        &qdev_prop_uint32,                                         \
+        CHOOSE(TYPES_COMPAT(TYPEOF_FIELD(type, field), void *),    \
+        &qdev_prop_ptr,                                            \
+        NULL))),                                                   \
+    }
+
 extern PropertyInfo qdev_prop_uint16;
 extern PropertyInfo qdev_prop_uint32;
 extern PropertyInfo qdev_prop_hex32;

  reply	other threads:[~2009-07-17  3:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-15 12:35 [Qemu-devel] [RfC PATCH] qdev: helper macros for properties Gerd Hoffmann
2009-07-17  0:23 ` Paul Brook
2009-07-17  3:17   ` Anthony Liguori [this message]
2009-07-17  3:28   ` Anthony Liguori

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=4A5FED55.3080008@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --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 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.