From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MTAm8-0004aF-NK for qemu-devel@nongnu.org; Tue, 21 Jul 2009 04:32:40 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MTAm3-0004Zw-SE for qemu-devel@nongnu.org; Tue, 21 Jul 2009 04:32:40 -0400 Received: from [199.232.76.173] (port=58202 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MTAm3-0004Zt-P1 for qemu-devel@nongnu.org; Tue, 21 Jul 2009 04:32:35 -0400 Received: from mx2.redhat.com ([66.187.237.31]:58426) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MTAm3-000891-By for qemu-devel@nongnu.org; Tue, 21 Jul 2009 04:32:35 -0400 Message-ID: <4A657CA4.7080203@redhat.com> Date: Tue, 21 Jul 2009 10:30:28 +0200 From: Gerd Hoffmann MIME-Version: 1.0 References: <1247841685-18495-1-git-send-email-aliguori@us.ibm.com> <1247841685-18495-3-git-send-email-aliguori@us.ibm.com> In-Reply-To: <1247841685-18495-3-git-send-email-aliguori@us.ibm.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [PATCH 2/2] Introduce macro for defining qdev properties List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: qemu-devel@nongnu.org, Paul Brook 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