From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52568) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VLbIg-0003xZ-5n for qemu-devel@nongnu.org; Mon, 16 Sep 2013 12:05:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VLbIZ-00078s-TT for qemu-devel@nongnu.org; Mon, 16 Sep 2013 12:05:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45772) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VLbIZ-00077j-LP for qemu-devel@nongnu.org; Mon, 16 Sep 2013 12:05:15 -0400 Date: Mon, 16 Sep 2013 19:07:21 +0300 From: "Michael S. Tsirkin" Message-ID: <20130916160721.GA4386@redhat.com> References: <20130915172331.GA2821@redhat.com> <5236A5ED.3000804@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <5236A5ED.3000804@suse.de> 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: Andreas =?iso-8859-1?Q?F=E4rber?= Cc: Paolo Bonzini , Stefan Hajnoczi , qemu-devel@nongnu.org, Anthony Liguori , Igor Mammedov On Mon, Sep 16, 2013 at 08:32:13AM +0200, Andreas F=E4rber wrote: > 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? >=20 > Actually yes: Apart from the clang issues raised and the disturbing > upper-casing of arguments, BTW there are no upper casing of arguments: internal variable names in macros must include macro name otherwise you get hard to debug collisions: #define SQUARE_ME(x) \ do { \ int var =3D x; \ x =3D var * x; \ } while (0) \ int v =3D 2; SQUARE_ME(v); // v is 4 int var =3D 2; SQUARE_ME(var); // BUG: var is still 2 > 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. >=20 > So what about taking bool/string property helpers as example and puttin= g > 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 pointe= r > 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. >=20 > It does touch on the issue I brought up on a KVM call a couple weeks ag= o > 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. >=20 > Regards, > Andreas OK this makes you happy? All calls pass NULL as Error so I omitted it for now. We can add later if anyone has a use for it. diff --git a/include/qom/object.h b/include/qom/object.h index 1a7b71a..90dce59 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -795,6 +795,27 @@ void object_property_add(Object *obj, const char *na= me, const char *type, void object_property_del(Object *obj, const char *name, struct Error **e= rrp); =20 /** + * object_property_add_uint8_t_ptr: + * object_property_add_uint16_t_ptr: + * object_property_add_uint32_t_ptr: + * object_property_add_uint64_t_ptr: + * @obj: the object to add a property to + * @name: the name of the property + * @v: pointer to value + * + * Add an integer property in memory. This function will add a + * property of the appropriate type. + */ +void object_property_add_uint8_t_ptr(Object *obj, const char *name, + const uint8_t *v); +void object_property_add_uint16_t_ptr(Object *obj, const char *name, + const uint16_t *v); +void object_property_add_uint32_t_ptr(Object *obj, const char *name, + const uint32_t *v); +void object_property_add_uint64_t_ptr(Object *obj, const char *name, + const uint64_t *v); + +/** * object_property_find: * @obj: the object * @name: the name of the property