All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: Peter Crosthwaite <peter.crosthwaite@xilinx.com>, qemu-devel@nongnu.org
Cc: pbonzini@redhat.com
Subject: Re: [Qemu-devel] [PATCH qom v2 1/2] qom: object_property_add: Add automatic arrayification
Date: Tue, 12 Aug 2014 13:36:07 +0200	[thread overview]
Message-ID: <53E9FC27.7@suse.de> (raw)
In-Reply-To: <9e52946a183e4c6371285df8d7a99febd546998c.1407128441.git.peter.crosthwaite@xilinx.com>

Am 04.08.2014 07:08, schrieb Peter Crosthwaite:
> If "[*]" is given as the last part of a QOM property name, treat that
> as an array property. The added property is given the first available
> name, replacing the * with a decimal number counting from 0.
> 
> First add with name "foo[*]" will be "foo[0]". Second "foo[1]" and so
> on.

I think it's worth mentioning here that the caller learns about which
one has been created through the ObjectProperty return value - which is
not immediately obvious from the diff.

> 
> Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
> ---
> changed since v1 (Paolo review):
> Cache strlen result in variable
> Use memcmp instead of strncmp
> 
> Suggest by Paolo and first pass discussion on list about the feature
> here:
> 
> https://lists.nongnu.org/archive/html/qemu-devel/2014-06/msg03794.html
> 
>  qom/object.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/qom/object.c b/qom/object.c
> index 0e8267b..4484330 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -738,6 +738,29 @@ object_property_add(Object *obj, const char *name, const char *type,
>                      void *opaque, Error **errp)
>  {
>      ObjectProperty *prop;
> +    size_t name_len = strlen(name);
> +
> +    if (name_len >= 3 && !memcmp(name + name_len - 3, "[*]", 4)) {
> +        int i;
> +        ObjectProperty *ret;
> +        char *name_no_array = g_strdup(name);
> +
> +        name_no_array[name_len - 3] = '\0';
> +        for (i = 0; ; ++i) {
> +            char *full_name = g_strdup_printf("%s[%d]", name_no_array, i);
> +            Error *local_err = NULL;

White line missing here...

> +            ret = object_property_add(obj, full_name, type, get, set,
> +                                      release, opaque, &local_err);
> +

... but present here.

> +            g_free(full_name);
> +            if (!local_err) {
> +                break;
> +            }
> +            error_free(local_err);

Can't we do this without creating and throwing away an Error by
comparing the list of obj->properties against full_name like below?

> +        }
> +        g_free(name_no_array);
> +        return ret;
> +    }
>  
>      QTAILQ_FOREACH(prop, &obj->properties, node) {
>          if (strcmp(prop->name, name) == 0) {

Regards,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

  parent reply	other threads:[~2014-08-12 11:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-04  5:08 [Qemu-devel] [PATCH qom v2 1/2] qom: object_property_add: Add automatic arrayification Peter Crosthwaite
2014-08-04  5:08 ` [Qemu-devel] [PATCH qom v2 2/2] memory: remove object_property_add_child_array Peter Crosthwaite
2014-08-12  7:51 ` [Qemu-devel] [PATCH qom v2 1/2] qom: object_property_add: Add automatic arrayification Peter Crosthwaite
2014-08-12 11:36 ` Andreas Färber [this message]
2014-08-14  2:15   ` Peter Crosthwaite

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=53E9FC27.7@suse.de \
    --to=afaerber@suse.de \
    --cc=pbonzini@redhat.com \
    --cc=peter.crosthwaite@xilinx.com \
    --cc=qemu-devel@nongnu.org \
    /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.