mirror of https://github.com/proxmox/mirror_qemu
qom: support orphan objects in object_get_canonical_path
Mostly a rewrite, in order to keep the loop simple. Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>master
parent
24ed117232
commit
e40077fd2c
36
qom/object.c
36
qom/object.c
|
@ -1669,25 +1669,29 @@ gchar *object_get_canonical_path(Object *obj)
|
||||||
Object *root = object_get_root();
|
Object *root = object_get_root();
|
||||||
char *newpath, *path = NULL;
|
char *newpath, *path = NULL;
|
||||||
|
|
||||||
while (obj != root) {
|
if (obj == root) {
|
||||||
char *component = object_get_canonical_path_component(obj);
|
return g_strdup("/");
|
||||||
|
|
||||||
if (path) {
|
|
||||||
newpath = g_strdup_printf("%s/%s", component, path);
|
|
||||||
g_free(component);
|
|
||||||
g_free(path);
|
|
||||||
path = newpath;
|
|
||||||
} else {
|
|
||||||
path = component;
|
|
||||||
}
|
|
||||||
|
|
||||||
obj = obj->parent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
newpath = g_strdup_printf("/%s", path ? path : "");
|
do {
|
||||||
g_free(path);
|
char *component = object_get_canonical_path_component(obj);
|
||||||
|
|
||||||
return newpath;
|
if (!component) {
|
||||||
|
/* A canonical path must be complete, so discard what was
|
||||||
|
* collected so far.
|
||||||
|
*/
|
||||||
|
g_free(path);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
newpath = g_strdup_printf("/%s%s", component, path ? path : "");
|
||||||
|
g_free(path);
|
||||||
|
g_free(component);
|
||||||
|
path = newpath;
|
||||||
|
obj = obj->parent;
|
||||||
|
} while (obj != root);
|
||||||
|
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object *object_resolve_path_component(Object *parent, const gchar *part)
|
Object *object_resolve_path_component(Object *parent, const gchar *part)
|
||||||
|
|
Loading…
Reference in New Issue