From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51845) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VLSMG-0005ei-Dw for qemu-devel@nongnu.org; Mon, 16 Sep 2013 02:32:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VLSM9-0004nW-48 for qemu-devel@nongnu.org; Mon, 16 Sep 2013 02:32:28 -0400 Received: from cantor2.suse.de ([195.135.220.15]:51702 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VLSM8-0004mU-RA for qemu-devel@nongnu.org; Mon, 16 Sep 2013 02:32:21 -0400 Message-ID: <5236A5ED.3000804@suse.de> Date: Mon, 16 Sep 2013 08:32:13 +0200 From: =?ISO-8859-1?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <20130915172331.GA2821@redhat.com> In-Reply-To: <20130915172331.GA2821@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] qom: helper macro for adding read-only properties List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" Cc: Paolo Bonzini , Stefan Hajnoczi , qemu-devel@nongnu.org, Anthony Liguori , Igor Mammedov Am 15.09.2013 19:23, schrieb Michael S. Tsirkin: > Add a helper macro for adding read-only properties, that works in the > common case where the value is a constant. >=20 > Signed-off-by: Michael S. Tsirkin > --- >=20 > I'm using this patch in my acpi work - any objections > to applying it on my tree? Actually yes: Apart from the clang issues raised and the disturbing upper-casing of arguments, this is hardcoding "int" type and NULL errp, so I don't think it deserves to live in object.h as is. I do agree that we could use more helper functions to deal with dynamic properties. So what about taking bool/string property helpers as example and putting intX_t getters into object.c, using a passed-through opaque argument to obtain the value? We could then have real object_property_add_int32() etc. functions using the appropriate type name, with field/value pointer and Error** arguments. A pointer can be assumed to hold up to uint32_t values or, to keep the API more general, use a local static const variable for non-field values. It does touch on the issue I brought up on a KVM call a couple weeks ago of how dynamic and static properties are supposed to relate. I personally welcome making dynamic properties more easy to deal with; an alternative might be to extend qdev-properties.c with DEFINE_PROP_READONLY_UINT32() etc. CC'ing Igor, who has dealt with dynamic-vs.-static properties for X86CPU. Regards, Andreas >=20 > include/qom/object.h | 21 +++++++++++++++++++++ > 1 file changed, 21 insertions(+) >=20 > diff --git a/include/qom/object.h b/include/qom/object.h > index 1a7b71a..4787de6 100644 > --- a/include/qom/object.h > +++ b/include/qom/object.h > @@ -17,6 +17,7 @@ > #include > #include > #include > +#include "qemu/typedefs.h" > #include "qemu/queue.h" > =20 > struct Visitor; > @@ -792,6 +793,26 @@ void object_property_add(Object *obj, const char *= name, const char *type, > ObjectPropertyRelease *release, > void *opaque, struct Error **errp); > =20 > +/* Add a property that is an integer constant. */ > +#define OBJECT_ADD_PROP_CONST(obj, name, value) \ > + do { = \ > + void OBJECT_ADD_PROP_GET(Object *OBJECT_ADD_PROP_OBJ, = \ > + struct Visitor *OBJECT_ADD_PROP_VISIT= OR, \ > + void *OBJECT_ADD_PROP_OPAQUE, = \ > + const char *OBJECT_ADD_PROP_NAME, = \ > + struct Error **OBJECT_ADD_PROP_VALUE_= ERR) \ > + { = \ > + int64_t OBJECT_ADD_PROP_VALUE =3D value; = \ > + = \ > + visit_type_int64(OBJECT_ADD_PROP_VISITOR, = \ > + &OBJECT_ADD_PROP_VALUE, = \ > + OBJECT_ADD_PROP_NAME, = \ > + OBJECT_ADD_PROP_VALUE_ERR); = \ > + } = \ > + object_property_add(obj, name, "int", OBJECT_ADD_PROP_GET, = \ > + NULL, NULL, NULL, NULL); = \ > + } while (0) > + > void object_property_del(Object *obj, const char *name, struct Error *= *errp); > =20 > /** >=20 --=20 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrnbe= rg