[PATCH v2 02/13] qom: New object_property_add_new_container()

Peter Xu posted 13 patches 1 day, 20 hours ago
[PATCH v2 02/13] qom: New object_property_add_new_container()
Posted by Peter Xu 1 day, 20 hours ago
To move towards explicit creations of containers, starting that by
providing a helper for creating container objects.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 include/qom/object.h | 12 ++++++++++++
 qom/container.c      | 14 +++++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/include/qom/object.h b/include/qom/object.h
index 3ba370ce9b..597e961b8c 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -2033,6 +2033,18 @@ int object_child_foreach_recursive(Object *obj,
  */
 Object *container_get(Object *root, const char *path);
 
+/**
+ * object_property_add_new_container:
+ * @obj: the parent object
+ * @name: the name of the parent object's property to add
+ *
+ * Add a newly created container object to a parent object.
+ *
+ * Returns: the newly created container object.  Its reference count is 1,
+ * and the reference is owned by the parent object.
+ */
+Object *object_property_add_new_container(Object *obj, const char *name);
+
 /**
  * object_property_help:
  * @name: the name of the property
diff --git a/qom/container.c b/qom/container.c
index cfec92a944..20ab74b0e8 100644
--- a/qom/container.c
+++ b/qom/container.c
@@ -24,6 +24,16 @@ static void container_register_types(void)
     type_register_static(&container_info);
 }
 
+Object *object_property_add_new_container(Object *obj, const char *name)
+{
+    Object *child = object_new(TYPE_CONTAINER);
+
+    object_property_add_child(obj, name, child);
+    object_unref(child);
+
+    return child;
+}
+
 Object *container_get(Object *root, const char *path)
 {
     Object *obj, *child;
@@ -37,9 +47,7 @@ Object *container_get(Object *root, const char *path)
     for (i = 1; parts[i] != NULL; i++, obj = child) {
         child = object_resolve_path_component(obj, parts[i]);
         if (!child) {
-            child = object_new(TYPE_CONTAINER);
-            object_property_add_child(obj, parts[i], child);
-            object_unref(child);
+            child = object_property_add_new_container(obj, parts[i]);
         }
     }
 
-- 
2.45.0
Re: [PATCH v2 02/13] qom: New object_property_add_new_container()
Posted by Markus Armbruster 1 day, 1 hour ago
Peter Xu <peterx@redhat.com> writes:

> To move towards explicit creations of containers, starting that by
> providing a helper for creating container objects.
>
> Signed-off-by: Peter Xu <peterx@redhat.com>

Reviewed-by: Markus Armbruster <armbru@redhat.com>
Re: [PATCH v2 02/13] qom: New object_property_add_new_container()
Posted by Philippe Mathieu-Daudé 1 day, 19 hours ago
On 21/11/24 20:21, Peter Xu wrote:
> To move towards explicit creations of containers, starting that by
> providing a helper for creating container objects.
> 
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>   include/qom/object.h | 12 ++++++++++++
>   qom/container.c      | 14 +++++++++++---
>   2 files changed, 23 insertions(+), 3 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>