Patchwork [6/8] qom: do not return root for empty path

login
register
mail settings
Submitter Paolo Bonzini
Date April 18, 2013, 4:44 p.m.
Message ID <1366303444-24620-7-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/237687/
State New
Headers show

Comments

Paolo Bonzini - April 18, 2013, 4:44 p.m.
An empty path will return the sole object of that type in the
QOM tree.  This is different from "/", which returns the root.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 qom/object.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
Andreas Färber - April 29, 2013, 5:30 p.m.
Am 18.04.2013 18:44, schrieb Paolo Bonzini:
> An empty path will return the sole object of that type in the
> QOM tree.  This is different from "/", which returns the root.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Looks OK to me, but not confident about callers' expectations.
Might this need a documentation update? CC'ing Mr. QOM.

Andreas

> ---
>  qom/object.c | 12 ++----------
>  1 file changed, 2 insertions(+), 10 deletions(-)
> 
> diff --git a/qom/object.c b/qom/object.c
> index 093502e..dd53d24 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -1113,21 +1113,13 @@ static Object *object_resolve_partial_path(Object *parent,
>  Object *object_resolve_path_type(const char *path, const char *typename,
>                                   bool *ambiguous)
>  {
> -    bool partial_path = true;
>      Object *obj;
>      gchar **parts;
>  
>      parts = g_strsplit(path, "/", 0);
> -    if (parts == NULL || parts[0] == NULL) {
> -        g_strfreev(parts);
> -        return object_get_root();
> -    }
> -
> -    if (strcmp(parts[0], "") == 0) {
> -        partial_path = false;
> -    }
> +    assert(parts);
>  
> -    if (partial_path) {
> +    if (parts[0] == NULL || strcmp(parts[0], "") != 0) {
>          if (ambiguous) {
>              *ambiguous = false;
>          }
>

Patch

diff --git a/qom/object.c b/qom/object.c
index 093502e..dd53d24 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1113,21 +1113,13 @@  static Object *object_resolve_partial_path(Object *parent,
 Object *object_resolve_path_type(const char *path, const char *typename,
                                  bool *ambiguous)
 {
-    bool partial_path = true;
     Object *obj;
     gchar **parts;
 
     parts = g_strsplit(path, "/", 0);
-    if (parts == NULL || parts[0] == NULL) {
-        g_strfreev(parts);
-        return object_get_root();
-    }
-
-    if (strcmp(parts[0], "") == 0) {
-        partial_path = false;
-    }
+    assert(parts);
 
-    if (partial_path) {
+    if (parts[0] == NULL || strcmp(parts[0], "") != 0) {
         if (ambiguous) {
             *ambiguous = false;
         }