[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 04/59] qom: New object_property_add_new_container()
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 04/59] qom: New object_property_add_new_container() |
Date: |
Fri, 20 Dec 2024 17:14:55 +0100 |
From: Peter Xu <peterx@redhat.com>
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>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20241121192202.4155849-3-peterx@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
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 de02e16817c..95d6e064d9b 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -2019,6 +2019,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 cfec92a9447..20ab74b0e8d 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.47.1
- [PULL 00/59] Accel & exec patches for 2024-12-20, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 02/59] log: Add separate debug option for logging invalid memory accesses, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 01/59] hvf: arm: Ignore writes to CNTP_CTL_EL0, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 03/59] qom: Add TYPE_CONTAINER macro, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 04/59] qom: New object_property_add_new_container(),
Philippe Mathieu-Daudé <=
- [PULL 05/59] tests: Fix test-qdev-global-props on anonymous qdev realize(), Philippe Mathieu-Daudé, 2024/12/20
- [PULL 06/59] tests: Explicitly create containers in test_qom_partial_path(), Philippe Mathieu-Daudé, 2024/12/20
- [PULL 07/59] ppc/e500: Avoid abuse of container_get(), Philippe Mathieu-Daudé, 2024/12/20
- [PULL 08/59] hw/ppc: Explicitly create the drc container, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 09/59] qom: Create system containers explicitly, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 10/59] target/i386/sev: Reduce system specific declarations, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 11/59] include: Rename sysemu/ -> system/, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 12/59] system: Move 'exec/confidential-guest-support.h' to system/, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 13/59] tcg/tci: Include missing 'disas/dis-asm.h' header, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 14/59] accel/tcg: Include missing 'exec/tswap.h' header in translator.c, Philippe Mathieu-Daudé, 2024/12/20