All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Eric Auger" <eric.auger@linaro.org>,
	"qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>,
	"qemu-ppc Mailing List" <qemu-ppc@nongnu.org>,
	sean.stalley@intel.com, "Paolo Bonzini" <pbonzini@redhat.com>,
	"Andreas Färber" <afaerber@suse.de>
Subject: Re: [Qemu-devel] [PATCH 1/6] qom: macroify integer property helpers
Date: Wed, 02 Jul 2014 09:39:52 +0200	[thread overview]
Message-ID: <53B3B748.4090301@suse.de> (raw)
In-Reply-To: <CAEgOgz7fX=ngFxvtH33SVvv1=d=q=ymPb76qafxfT53u2nyNnA@mail.gmail.com>


On 02.07.14 05:29, Peter Crosthwaite wrote:
> On Wed, Jul 2, 2014 at 7:49 AM, Alexander Graf <agraf@suse.de> wrote:
>> We have a bunch of nice helpers that allow us to easily register an integer
>> field as QOM property. However, we have those duplicated for every integer
>> size available.
>>
>> This is very cumbersome (and prone to bugs) to work with and extend, so let's
>> strip out the only difference there is (the size) and generate the actual
>> functions via a macro.
>>
>> Signed-off-by: Alexander Graf <agraf@suse.de>
>> ---
>>   qom/object.c | 83 ++++++++++++++++++------------------------------------------
>>   1 file changed, 24 insertions(+), 59 deletions(-)
>>
>> diff --git a/qom/object.c b/qom/object.c
>> index 0e8267b..73cd717 100644
>> --- a/qom/object.c
>> +++ b/qom/object.c
>> @@ -1507,65 +1507,30 @@ static char *qdev_get_type(Object *obj, Error **errp)
>>       return g_strdup(object_get_typename(obj));
>>   }
>>
>> -static void property_get_uint8_ptr(Object *obj, Visitor *v,
>> -                                   void *opaque, const char *name,
>> -                                   Error **errp)
>> -{
>> -    uint8_t value = *(uint8_t *)opaque;
>> -    visit_type_uint8(v, &value, name, errp);
>> -}
>> -
>> -static void property_get_uint16_ptr(Object *obj, Visitor *v,
>> -                                   void *opaque, const char *name,
>> -                                   Error **errp)
>> -{
>> -    uint16_t value = *(uint16_t *)opaque;
>> -    visit_type_uint16(v, &value, name, errp);
>> -}
>> -
>> -static void property_get_uint32_ptr(Object *obj, Visitor *v,
>> -                                   void *opaque, const char *name,
>> -                                   Error **errp)
>> -{
>> -    uint32_t value = *(uint32_t *)opaque;
>> -    visit_type_uint32(v, &value, name, errp);
>> -}
>> -
>> -static void property_get_uint64_ptr(Object *obj, Visitor *v,
>> -                                   void *opaque, const char *name,
>> -                                   Error **errp)
>> -{
>> -    uint64_t value = *(uint64_t *)opaque;
>> -    visit_type_uint64(v, &value, name, errp);
>> -}
>> -
>> -void object_property_add_uint8_ptr(Object *obj, const char *name,
>> -                                   const uint8_t *v, Error **errp)
>> -{
>> -    object_property_add(obj, name, "uint8", property_get_uint8_ptr,
>> -                        NULL, NULL, (void *)v, errp);
>> -}
>> -
>> -void object_property_add_uint16_ptr(Object *obj, const char *name,
>> -                                    const uint16_t *v, Error **errp)
>> -{
>> -    object_property_add(obj, name, "uint16", property_get_uint16_ptr,
>> -                        NULL, NULL, (void *)v, errp);
>> -}
>> -
>> -void object_property_add_uint32_ptr(Object *obj, const char *name,
>> -                                    const uint32_t *v, Error **errp)
>> -{
>> -    object_property_add(obj, name, "uint32", property_get_uint32_ptr,
>> -                        NULL, NULL, (void *)v, errp);
>> -}
>> -
>> -void object_property_add_uint64_ptr(Object *obj, const char *name,
>> -                                    const uint64_t *v, Error **errp)
>> -{
>> -    object_property_add(obj, name, "uint64", property_get_uint64_ptr,
>> -                        NULL, NULL, (void *)v, errp);
>> -}
>> +#define DECLARE_INTEGER_VISITOR(size)                                          \
> macro needs a better name. DECLARE_PROP_SET_GET - something to make it
> clear its about properties.
>
>> +                                                                               \
>> +static void glue(glue(property_get_,size),_ptr)(Object *obj, Visitor *v,       \
>> +                                                void *opaque,                  \
>> +                                                const char *name,              \
>> +                                                Error **errp)                  \
>> +{                                                                              \
>> +    glue(size,_t) value = *(glue(size,_t) *)opaque;                            \
>> +    glue(visit_type_,size)(v, &value, name, errp);                             \
>> +}                                                                              \
>> +                                                                               \
>> +void glue(glue(object_property_add_,size),_ptr)(Object *obj, const char *name, \
>> +                                                const glue(size,_t) *v,        \
>> +                                                Error **errp)                  \
>> +{                                                                              \
>> +    ObjectPropertyAccessor *get = glue(glue(property_get_,size),_ptr);         \
>> +    object_property_add(obj, name, stringify(size), get, NULL, NULL, (void *)v,\
>> +                        errp);                                                 \
>> +}                                                                              \
>> +
>> +DECLARE_INTEGER_VISITOR(uint8)
>> +DECLARE_INTEGER_VISITOR(uint16)
>> +DECLARE_INTEGER_VISITOR(uint32)
>> +DECLARE_INTEGER_VISITOR(uint64)
>>
> Worth getting bool working this way too? Theres been a few times now
> where I have wanted to object_property_add_bool_ptr. Perhaps:
>
> #define DECLARE_PROP_SET_GET(name, type)
>
> DECLARE_PROP_SET_GET(uint8, uint8_t)
> DECLARE_PROP_SET_GET(uint16, uint16_t)
> DECLARE_PROP_SET_GET(uint32, uint32_t)
> DECLARE_PROP_SET_GET(uint64, uint64_t)
> DECLARE_PROP_SET_GET(bool, bool)
>
> Can actually add the bool one later in follow-up patch but just
> thinking ahead to get the macro right for wider usage.

I think that makes sense. Let me change it :).


Alex

  reply	other threads:[~2014-07-02  7:40 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-01 21:49 [Qemu-devel] [PATCH 0/6] Dynamic sysbus device allocation support Alexander Graf
2014-07-01 21:49 ` [Qemu-devel] [PATCH 1/6] qom: macroify integer property helpers Alexander Graf
2014-07-02  3:29   ` Peter Crosthwaite
2014-07-02  7:39     ` Alexander Graf [this message]
2014-07-01 21:49 ` [Qemu-devel] [PATCH 2/6] qom: Allow to make integer qom properties writeable Alexander Graf
2014-07-02  3:48   ` Peter Crosthwaite
2014-07-02  7:46     ` Alexander Graf
2014-07-01 21:49 ` [Qemu-devel] [PATCH 3/6] sysbus: Add user map hints Alexander Graf
2014-07-02  4:12   ` Peter Crosthwaite
2014-07-02  8:24     ` Alexander Graf
2014-07-02  8:26       ` Paolo Bonzini
2014-07-02  9:03       ` Peter Crosthwaite
2014-07-02  9:07         ` Alexander Graf
2014-07-02  9:17           ` Paolo Bonzini
2014-07-02  9:19             ` Alexander Graf
2014-07-02  9:26               ` Paolo Bonzini
2014-07-01 21:49 ` [Qemu-devel] [PATCH 4/6] sysbus: Make devices spawnable via -device Alexander Graf
2014-07-02  6:32   ` Paolo Bonzini
2014-07-02 15:36     ` Alexander Graf
2014-07-01 21:49 ` [Qemu-devel] [PATCH 5/6] PPC: e500: Support dynamically spawned sysbus devices Alexander Graf
2014-07-01 22:50   ` Scott Wood
2014-07-02 17:12     ` Alexander Graf
2014-07-02 17:26       ` Scott Wood
2014-07-02 17:30         ` Alexander Graf
2014-07-02 17:52           ` Scott Wood
2014-07-02 17:59             ` Alexander Graf
2014-07-02 19:34               ` Scott Wood
2014-07-02 20:59                 ` Alexander Graf
2014-07-01 21:49 ` [Qemu-devel] [PATCH 6/6] e500: Add support for eTSEC in device tree Alexander Graf
2014-07-01 22:56   ` Scott Wood
2014-07-02 17:24     ` Alexander Graf
2014-07-02 17:32       ` Scott Wood
2014-07-02 17:34         ` Alexander Graf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53B3B748.4090301@suse.de \
    --to=agraf@suse.de \
    --cc=afaerber@suse.de \
    --cc=eric.auger@linaro.org \
    --cc=pbonzini@redhat.com \
    --cc=peter.crosthwaite@xilinx.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=sean.stalley@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.