From: "Daniel P. Berrangé" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [PATCH v2 07/10] qom: add object_new_with_props_from_qdict
Date: Fri, 8 May 2026 12:24:26 +0100 [thread overview]
Message-ID: <20260508112429.643360-8-berrange@redhat.com> (raw)
In-Reply-To: <20260508112429.643360-1-berrange@redhat.com>
This will be used to replace user_creatable_add_type with an impl
that shares most code with object_new_with_props, and is not tied
to the user creatable interface.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
include/qom/object.h | 19 +++++++++++
qom/object.c | 75 ++++++++++++++++++++++++++++++++++++++++----
2 files changed, 88 insertions(+), 6 deletions(-)
diff --git a/include/qom/object.h b/include/qom/object.h
index 1b2b2702fc..cd59f1f171 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -700,6 +700,25 @@ Object *object_new_with_propv(const char *typename,
va_list vargs,
Error **errp);
+/**
+ * object_new_with_props_from_qdict:
+ * @typename: The name of the type of the object to instantiate.
+ * @parent: the parent object
+ * @id: The unique ID of the object
+ * @props: dictionary of property names and values
+ * @v: visitor to iterate over @props
+ * @errp: pointer to error object
+ *
+ * A variant of object_new_with_props() which accepts the
+ * properties in a QDict.
+ */
+Object *object_new_with_props_from_qdict(const char *typename,
+ Object *parent,
+ const char *id,
+ QDict *props,
+ Visitor *v,
+ Error **errp);
+
/**
* object_set_props:
* @obj: the object instance to set properties on
diff --git a/qom/object.c b/qom/object.c
index d8083dc318..4f908b3232 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -757,11 +757,14 @@ Object *object_new_with_props(const char *typename,
}
-Object *object_new_with_propv(const char *typename,
- Object *parent,
- const char *id,
- va_list vargs,
- Error **errp)
+static Object *
+object_new_with_props_helper(const char *typename,
+ Object *parent,
+ const char *id,
+ void *props,
+ bool (set_props)(Object *obj, void *props,
+ Error **errp),
+ Error **errp)
{
Object *obj;
ObjectClass *klass;
@@ -786,7 +789,7 @@ Object *object_new_with_propv(const char *typename,
}
obj = object_new_with_type(klass->type);
- if (!object_set_propv(obj, vargs, errp)) {
+ if (!set_props(obj, props, errp)) {
goto error;
}
@@ -812,6 +815,66 @@ Object *object_new_with_propv(const char *typename,
return NULL;
}
+struct ObjectNewVargsData {
+ va_list vargs;
+};
+
+static bool object_new_with_propv_setter(Object *obj,
+ void *props,
+ Error **errp)
+{
+ struct ObjectNewVargsData *data = props;
+ return object_set_propv(obj, data->vargs, errp);
+}
+
+Object *object_new_with_propv(const char *typename,
+ Object *parent,
+ const char *id,
+ va_list vargs,
+ Error **errp)
+{
+ Object *obj;
+ struct ObjectNewVargsData data;
+
+ va_copy(data.vargs, vargs);
+ obj = object_new_with_props_helper(typename,
+ parent,
+ id,
+ &data,
+ object_new_with_propv_setter,
+ errp);
+ va_end(data.vargs);
+ return obj;
+}
+
+struct ObjectNewQDictData {
+ QDict *props;
+ Visitor *v;
+};
+
+static bool object_new_with_qdict_setter(Object *obj,
+ void *props,
+ Error **errp)
+{
+ struct ObjectNewQDictData *data = props;
+ return object_set_props_from_qdict(obj, data->props, data->v, errp);
+}
+
+Object *object_new_with_props_from_qdict(const char *typename,
+ Object *parent,
+ const char *id,
+ QDict *props,
+ Visitor *v,
+ Error **errp)
+{
+ struct ObjectNewQDictData data = { props, v };
+ return object_new_with_props_helper(typename,
+ parent,
+ id,
+ &data,
+ object_new_with_qdict_setter,
+ errp);
+}
bool object_set_props(Object *obj,
Error **errp,
--
2.54.0
next prev parent reply other threads:[~2026-05-08 11:25 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-08 11:24 [PATCH v2 00/10] qom: misc cleanups / fixes Daniel P. Berrangé
2026-05-08 11:24 ` [PATCH v2 01/10] qom: add trace events for object/property lifecycle Daniel P. Berrangé
2026-05-08 15:18 ` marcandre.lureau
2026-05-08 15:47 ` Daniel P. Berrangé
2026-05-08 11:24 ` [PATCH v2 02/10] qom: validate ID format when creating objects Daniel P. Berrangé
2026-05-11 10:35 ` Philippe Mathieu-Daudé
2026-05-11 10:37 ` Philippe Mathieu-Daudé
2026-05-11 10:39 ` Daniel P. Berrangé
2026-05-08 11:24 ` [PATCH v2 03/10] qom: make errp last param in methods taking va_list Daniel P. Berrangé
2026-05-08 11:24 ` [PATCH v2 04/10] qom: shorten name of object_set_properties_from_keyval Daniel P. Berrangé
2026-05-08 11:24 ` [PATCH v2 05/10] qom: have object_set_props_keyval return bool Daniel P. Berrangé
2026-05-11 10:32 ` Philippe Mathieu-Daudé
2026-05-08 11:24 ` [PATCH v2 06/10] qom: move object_set_prop_keyval into object.c Daniel P. Berrangé
2026-05-11 10:37 ` Philippe Mathieu-Daudé
2026-05-08 11:24 ` Daniel P. Berrangé [this message]
2026-05-08 15:18 ` [PATCH v2 07/10] qom: add object_new_with_props_from_qdict marcandre.lureau
2026-05-08 15:51 ` Daniel P. Berrangé
2026-05-08 11:24 ` [PATCH v2 08/10] qom: fix ability to create objects without a parent Daniel P. Berrangé
2026-05-08 11:24 ` [PATCH v2 09/10] qom: allow object_new_with_prop* to trigger module loading Daniel P. Berrangé
2026-05-08 11:24 ` [PATCH v2 10/10] qom: drop user_creatable_add_type method Daniel P. Berrangé
2026-05-08 15:18 ` marcandre.lureau
2026-05-08 15:44 ` Daniel P. Berrangé
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=20260508112429.643360-8-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.