From: "Daniel P. Berrangé" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>
Subject: [PATCH v3 10/10] qom: drop user_creatable_add_type method
Date: Mon, 11 May 2026 15:14:20 +0100 [thread overview]
Message-ID: <20260511141420.229023-11-berrange@redhat.com> (raw)
In-Reply-To: <20260511141420.229023-1-berrange@redhat.com>
This can be replaced by object_new_with_props_from_qdict, which does
functionally the same job, but the caller does not own the returned
reference, instead the parent object owns it.
In one case we can use object_new_with_props_from_qdict_owned instead
since the object is not intended to have any parent.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
authz/listfile.c | 4 +-
include/qom/object_interfaces.h | 18 ---------
qom/object_interfaces.c | 70 ++-------------------------------
tests/unit/check-qom-proplist.c | 5 +--
4 files changed, 7 insertions(+), 90 deletions(-)
diff --git a/authz/listfile.c b/authz/listfile.c
index 13741d5a72..23655f8663 100644
--- a/authz/listfile.c
+++ b/authz/listfile.c
@@ -79,8 +79,8 @@ qauthz_list_file_load(QAuthZListFile *fauthz, Error **errp)
v = qobject_input_visitor_new(obj);
- ret = (QAuthZ *)user_creatable_add_type(TYPE_QAUTHZ_LIST,
- NULL, pdict, v, errp);
+ ret = QAUTHZ(object_new_with_props_from_qdict_parentless(
+ TYPE_QAUTHZ_LIST, pdict, v, errp));
cleanup:
visit_free(v);
diff --git a/include/qom/object_interfaces.h b/include/qom/object_interfaces.h
index 02b11a7ef0..e2b8615617 100644
--- a/include/qom/object_interfaces.h
+++ b/include/qom/object_interfaces.h
@@ -69,24 +69,6 @@ bool user_creatable_complete(UserCreatable *uc, Error **errp);
*/
bool user_creatable_can_be_deleted(UserCreatable *uc);
-/**
- * user_creatable_add_type:
- * @type: the object type name
- * @id: the unique ID for the object
- * @qdict: the object properties
- * @v: the visitor
- * @errp: if an error occurs, a pointer to an area to store the error
- *
- * Create an instance of the user creatable object @type, placing
- * it in the object composition tree with name @id, initializing
- * it with properties from @qdict
- *
- * Returns: the newly created object or NULL on error
- */
-Object *user_creatable_add_type(const char *type, const char *id,
- const QDict *qdict,
- Visitor *v, Error **errp);
-
/**
* user_creatable_add_qapi:
* @options: the object definition
diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index e0a3cd8d0f..7080f85f95 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -44,75 +44,11 @@ bool user_creatable_can_be_deleted(UserCreatable *uc)
}
}
-Object *user_creatable_add_type(const char *type, const char *id,
- const QDict *qdict,
- Visitor *v, Error **errp)
-{
- ERRP_GUARD();
- Object *obj;
- ObjectClass *klass;
- Error *local_err = NULL;
-
- if (id != NULL && !id_wellformed(id)) {
- error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "id", "an identifier");
- error_append_hint(errp, "Identifiers consist of letters, digits, "
- "'-', '.', '_', starting with a letter.\n");
- return NULL;
- }
-
- klass = module_object_class_by_name(type);
- if (!klass) {
- error_setg(errp, "invalid object type: %s", type);
- return NULL;
- }
-
- if (!object_class_dynamic_cast(klass, TYPE_USER_CREATABLE)) {
- error_setg(errp, "object type '%s' isn't supported by object-add",
- type);
- return NULL;
- }
-
- if (object_class_is_abstract(klass)) {
- error_setg(errp, "object type '%s' is abstract", type);
- return NULL;
- }
-
- assert(qdict);
- obj = object_new_with_class(klass);
- object_set_props_from_qdict(obj, qdict, v, &local_err);
- if (local_err) {
- goto out;
- }
-
- if (id != NULL) {
- object_property_try_add_child(object_get_objects_root(),
- id, obj, &local_err);
- if (local_err) {
- goto out;
- }
- }
-
- if (!user_creatable_complete(USER_CREATABLE(obj), &local_err)) {
- if (id != NULL) {
- object_property_del(object_get_objects_root(), id);
- }
- goto out;
- }
-out:
- if (local_err) {
- error_propagate(errp, local_err);
- object_unref(obj);
- return NULL;
- }
- return obj;
-}
-
void user_creatable_add_qapi(ObjectOptions *options, Error **errp)
{
Visitor *v;
QObject *qobj;
QDict *props;
- Object *obj;
v = qobject_output_visitor_new(&qobj);
visit_type_ObjectOptions(v, NULL, &options, &error_abort);
@@ -124,9 +60,9 @@ void user_creatable_add_qapi(ObjectOptions *options, Error **errp)
qdict_del(props, "id");
v = qobject_input_visitor_new(QOBJECT(props));
- obj = user_creatable_add_type(ObjectType_str(options->qom_type),
- options->id, props, v, errp);
- object_unref(obj);
+ object_new_with_props_from_qdict(ObjectType_str(options->qom_type),
+ object_get_objects_root(),
+ options->id, props, v, errp);
qobject_unref(qobj);
visit_free(v);
}
diff --git a/tests/unit/check-qom-proplist.c b/tests/unit/check-qom-proplist.c
index 954c898ce1..89de92b7d9 100644
--- a/tests/unit/check-qom-proplist.c
+++ b/tests/unit/check-qom-proplist.c
@@ -461,10 +461,9 @@ static void test_dummy_createlist_parentless(void)
static bool test_create_obj(QDict *qdict, Error **errp)
{
Visitor *v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
- Object *obj = user_creatable_add_type(TYPE_DUMMY, "dev0", qdict, v, errp);
-
+ Object *obj = object_new_with_props_from_qdict(
+ TYPE_DUMMY, object_get_objects_root(), "dev0", qdict, v, errp);
visit_free(v);
- object_unref(obj);
return !!obj;
}
--
2.54.0
prev parent reply other threads:[~2026-05-11 14:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-11 14:14 [PATCH v3 00/10] qom: misc cleanups / fixes Daniel P. Berrangé
2026-05-11 14:14 ` [PATCH v3 01/10] qom: add trace events for object/property lifecycle Daniel P. Berrangé
2026-05-11 14:14 ` [PATCH v3 02/10] qom: validate ID format when creating objects Daniel P. Berrangé
2026-05-11 14:14 ` [PATCH v3 03/10] qom: make errp last param in methods taking va_list Daniel P. Berrangé
2026-05-11 14:14 ` [PATCH v3 04/10] qom: shorten name of object_set_properties_from_keyval Daniel P. Berrangé
2026-05-11 14:14 ` [PATCH v3 05/10] qom: have object_set_props_keyval return bool Daniel P. Berrangé
2026-05-11 14:14 ` [PATCH v3 06/10] qom: move object_set_prop_keyval into object.c Daniel P. Berrangé
2026-05-11 14:14 ` [PATCH v3 07/10] qom: add object_new_with_props_from_qdict Daniel P. Berrangé
2026-05-11 14:14 ` [PATCH v3 08/10] qom: fix ability to create objects without a parent Daniel P. Berrangé
2026-05-11 15:43 ` marcandre.lureau
2026-05-11 14:14 ` [PATCH v3 09/10] qom: allow object_new_with_prop* to trigger module loading Daniel P. Berrangé
2026-05-11 14:14 ` Daniel P. Berrangé [this message]
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=20260511141420.229023-11-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox