From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MRdxF-0008JO-0Q for qemu-devel@nongnu.org; Thu, 16 Jul 2009 23:17:49 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MRdxA-0008Iz-QS for qemu-devel@nongnu.org; Thu, 16 Jul 2009 23:17:48 -0400 Received: from [199.232.76.173] (port=56025 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MRdxA-0008In-Cy for qemu-devel@nongnu.org; Thu, 16 Jul 2009 23:17:44 -0400 Received: from mail-yx0-f188.google.com ([209.85.210.188]:54046) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MRdx9-0003d3-W1 for qemu-devel@nongnu.org; Thu, 16 Jul 2009 23:17:44 -0400 Received: by yxe26 with SMTP id 26so974453yxe.4 for ; Thu, 16 Jul 2009 20:17:43 -0700 (PDT) Message-ID: <4A5FED55.3080008@codemonkey.ws> Date: Thu, 16 Jul 2009 22:17:41 -0500 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [RfC PATCH] qdev: helper macros for properties References: <1247661358-5411-1-git-send-email-kraxel@redhat.com> <200907170123.48369.paul@codesourcery.com> In-Reply-To: <200907170123.48369.paul@codesourcery.com> Content-Type: multipart/mixed; boundary="------------020702000007010207080007" List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paul Brook Cc: qemu-devel@nongnu.org, Gerd Hoffmann This is a multi-part message in MIME format. --------------020702000007010207080007 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit 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 > > > --------------020702000007010207080007 Content-Type: text/x-patch; name="qdev-prop.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="qdev-prop.patch" commit a7e2799c7c3c790c83e015b48ba34ac0975b93bb Author: Anthony Liguori Date: Thu Jul 16 22:16:02 2009 -0500 Introduce macro for defining qdev properties. Signed-off-by: Anthony Liguori 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; --------------020702000007010207080007--