qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] Re: [PATCH 2/2] Introduce macro for defining qdev propertie


From: Gerd Hoffmann
Subject: [Qemu-devel] Re: [PATCH 2/2] Introduce macro for defining qdev properties
Date: Tue, 21 Jul 2009 10:30:28 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1b3pre) Gecko/20090513 Fedora/3.0-2.3.beta2.fc11 Lightning/1.0pre Thunderbird/3.0b2

On 07/17/09 16:41, Anthony Liguori wrote:
This patch introduces macros for defining qdev properties.  The default macro
is clever enough to infer the type of the structure field and to automatically
generate a name for the property.  Additional macros are provided that allow
infered values to be overridden along with a set of macros to define properties
with default values.

+#define TYPEOF_FIELD(type, field) typeof(((type *)0)->field)

Hmm, tried to create something simliar. Didn't work, looks like I did something wrong :-(

+#define QDEV_PROP_TYPE_INFER(type, field)                          \
+        CHOOSE(TYPES_COMPAT(TYPEOF_FIELD(type, field), uint16_t),  \
+&qdev_prop_uint16,                                         \
+        CHOOSE(TYPES_COMPAT(TYPEOF_FIELD(type, field), int16_t),   \
+&qdev_prop_uint16,                                         \
+        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), CharDriverState *), \
+&qdev_prop_chrdev,                                         \
+        /* force a build break when inference fails */             \
+       (double)3.14159265)))))

You probably want to use something like &qdev_prop_not_found_for_this_type instead of pi to get a somewhat better error message.

Overall this looks pretty good to me.

cheers,
  Gerd




reply via email to

[Prev in Thread] Current Thread [Next in Thread]