From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:42808) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rt2SD-0000ku-1G for qemu-devel@nongnu.org; Thu, 02 Feb 2012 14:36:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rt2SB-0005mT-Jz for qemu-devel@nongnu.org; Thu, 02 Feb 2012 14:36:20 -0500 Received: from mail-pw0-f45.google.com ([209.85.160.45]:47483) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rt2SB-0005mD-FO for qemu-devel@nongnu.org; Thu, 02 Feb 2012 14:36:19 -0500 Received: by pbaa11 with SMTP id a11so2941149pba.4 for ; Thu, 02 Feb 2012 11:36:18 -0800 (PST) Message-ID: <4F2AE5AE.8040205@codemonkey.ws> Date: Thu, 02 Feb 2012 13:36:14 -0600 From: Anthony Liguori MIME-Version: 1.0 References: <1328201142-26145-1-git-send-email-pbonzini@redhat.com> <1328201142-26145-5-git-send-email-pbonzini@redhat.com> <4F2ADEB0.6090308@codemonkey.ws> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 04/16] qom: add QObject-based property get/set wrappers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org On 02/02/2012 01:24 PM, Paolo Bonzini wrote: > On 02/02/2012 08:06 PM, Anthony Liguori wrote: >> I don't want object.h to have a dependency on QObject. We need to phase >> out QObject. > > The header doesn't. > >> Couple things: >> >> 1) We shouldn't use generic interfaces to read/write properties from >> objects. We should use type-safe accessors provided by the types >> themselves. >> >> 2) If we want to get fancy, we can add property_set_int, etc. and then >> implement (1) via header files that just call these functions. > > That's what patch 5 does. But writing visitors in C is a royal PITA. The only > sane way to do so is via QObject. You just need a variant visitor. It's pretty simple to do, essentially: typedef struct VariantVisitor { Visitor parent; enum { VV_INT, VV_STR } kind; union { int64_t v_int; char *v_str }; } VariantVisitor; /* input */ static void visit_int(...) { v->kind = TYPE_INT; v->v_int = *value; } /* output */ static void visit_int(...) { assert(v->kind == TYPE_INT); *value = v->v_int; } void variant_visitor_set_int(VariantVisitor *v, int64_t value) { v->kind = TYPE_INT; v->v_int = value; } The only types that matter are int and string so the variant visitor is pretty simple. Regards, Anthony Liguori > > Paolo > >