qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alexey Kardashevskiy <aik@ozlabs.ru>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] qom: support orphan objects in object_get_canonical_path
Date: Thu, 31 May 2018 13:45:02 +1000	[thread overview]
Message-ID: <b1cca715-e58f-0013-20fb-9470ce3b6137@ozlabs.ru> (raw)
In-Reply-To: <20180530162349.31100-1-pbonzini@redhat.com>

On 31/5/18 2:23 am, Paolo Bonzini wrote:
> Mostly a rewrite, in order to keep the loop simple.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  qom/object.c | 29 ++++++++++++++++-------------
>  1 file changed, 16 insertions(+), 13 deletions(-)
> 
> diff --git a/qom/object.c b/qom/object.c
> index 0fc972030e..4f30431ae3 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -1669,25 +1669,28 @@ gchar *object_get_canonical_path(Object *obj)
>      Object *root = object_get_root();
>      char *newpath, *path = NULL;
>  
> -    while (obj != root) {
> +    if (obj == root) {
> +        return g_strdup("/");
> +    }
> +
> +    do {
>          char *component = object_get_canonical_path_component(obj);
>  
> -        if (path) {
> -            newpath = g_strdup_printf("%s/%s", component, path);
> -            g_free(component);
> +        if (!component) {
> +            /* A canonical path must be complete, so discard what was
> +             * collected so far.
> +             */

Well, this is correct indeed for the normal case when the result is used
for internal business but for my task (show the owner of an MR or at least
give a clue what to grep for) it will discard a partial path.

I guess I could print a typename if object_get_canonical_path() returns
NULL, I'll repost v4.


>              g_free(path);
> -            path = newpath;
> -        } else {
> -            path = component;
> +            return NULL;
>          }
>  
> -        obj = obj->parent;
> -    }
> -
> -    newpath = g_strdup_printf("/%s", path ? path : "");
> -    g_free(path);
> +        newpath = g_strdup_printf("/%s%s", component, path ? path : "");
> +        g_free(path);
> +        g_free(component);
> +        path = newpath;
> +    } while ((obj = obj->parent) != root);
>  
> -    return newpath;
> +    return path;
>  }
>  
>  Object *object_resolve_path_component(Object *parent, const gchar *part)
> 


-- 
Alexey

  parent reply	other threads:[~2018-05-31  3:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-30 16:23 [Qemu-devel] [PATCH] qom: support orphan objects in object_get_canonical_path Paolo Bonzini
2018-05-30 17:42 ` Philippe Mathieu-Daudé
2018-05-31  3:45 ` Alexey Kardashevskiy [this message]
2018-05-31 10:26   ` Paolo Bonzini

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=b1cca715-e58f-0013-20fb-9470ce3b6137@ozlabs.ru \
    --to=aik@ozlabs.ru \
    --cc=pbonzini@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).