@samitouri / QOSamiQemu / commits / 7b0376d24c

qom: drop user_creatable_add_type method

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. Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Daniel P. Berrangé committed Apr 17, 2026 at 17:02 UTC 7b0376d24ce34893a9512587d1d82a6e07680e6d
4 files changed +7 -90
authz/listfile.c
+2 -2
@@ -79,8 +79,8 @@ qauthz_list_file_load(QAuthZListFile *fauthz, Error **errp)
79
80 v = qobject_input_visitor_new(obj);
81
82 - ret = (QAuthZ *)user_creatable_add_type(TYPE_QAUTHZ_LIST,
83 - NULL, pdict, v, errp);
82 + ret = QAUTHZ(object_new_with_props_from_qdict_parentless(
83 + TYPE_QAUTHZ_LIST, pdict, v, errp));
84
85 cleanup:
86 visit_free(v);
include/qom/object_interfaces.h
-18
@@ -69,24 +69,6 @@ bool user_creatable_complete(UserCreatable *uc, Error **errp);
69 */
70 bool user_creatable_can_be_deleted(UserCreatable *uc);
71
72 -/**
73 - * user_creatable_add_type:
74 - * @type: the object type name
75 - * @id: the unique ID for the object
76 - * @qdict: the object properties
77 - * @v: the visitor
78 - * @errp: if an error occurs, a pointer to an area to store the error
79 - *
80 - * Create an instance of the user creatable object @type, placing
81 - * it in the object composition tree with name @id, initializing
82 - * it with properties from @qdict
83 - *
84 - * Returns: the newly created object or NULL on error
85 - */
86 -Object *user_creatable_add_type(const char *type, const char *id,
87 - const QDict *qdict,
88 - Visitor *v, Error **errp);
89 -
72 /**
73 * user_creatable_add_qapi:
74 * @options: the object definition
qom/object_interfaces.c
+3 -67
@@ -44,75 +44,11 @@ bool user_creatable_can_be_deleted(UserCreatable *uc)
44 }
45 }
46
47 -Object *user_creatable_add_type(const char *type, const char *id,
48 - const QDict *qdict,
49 - Visitor *v, Error **errp)
50 -{
51 - ERRP_GUARD();
52 - Object *obj;
53 - ObjectClass *klass;
54 - Error *local_err = NULL;
55 -
56 - if (id != NULL && !id_wellformed(id)) {
57 - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "id", "an identifier");
58 - error_append_hint(errp, "Identifiers consist of letters, digits, "
59 - "'-', '.', '_', starting with a letter.\n");
60 - return NULL;
61 - }
62 -
63 - klass = module_object_class_by_name(type);
64 - if (!klass) {
65 - error_setg(errp, "invalid object type: %s", type);
66 - return NULL;
67 - }
68 -
69 - if (!object_class_dynamic_cast(klass, TYPE_USER_CREATABLE)) {
70 - error_setg(errp, "object type '%s' isn't supported by object-add",
71 - type);
72 - return NULL;
73 - }
74 -
75 - if (object_class_is_abstract(klass)) {
76 - error_setg(errp, "object type '%s' is abstract", type);
77 - return NULL;
78 - }
79 -
80 - assert(qdict);
81 - obj = object_new_with_class(klass);
82 - object_set_props_from_qdict(obj, qdict, v, &local_err);
83 - if (local_err) {
84 - goto out;
85 - }
86 -
87 - if (id != NULL) {
88 - object_property_try_add_child(object_get_objects_root(),
89 - id, obj, &local_err);
90 - if (local_err) {
91 - goto out;
92 - }
93 - }
94 -
95 - if (!user_creatable_complete(USER_CREATABLE(obj), &local_err)) {
96 - if (id != NULL) {
97 - object_property_del(object_get_objects_root(), id);
98 - }
99 - goto out;
100 - }
101 -out:
102 - if (local_err) {
103 - error_propagate(errp, local_err);
104 - object_unref(obj);
105 - return NULL;
106 - }
107 - return obj;
108 -}
109 -
47 void user_creatable_add_qapi(ObjectOptions *options, Error **errp)
48 {
49 Visitor *v;
50 QObject *qobj;
51 QDict *props;
115 - Object *obj;
52
53 v = qobject_output_visitor_new(&qobj);
54 visit_type_ObjectOptions(v, NULL, &options, &error_abort);
@@ -124,9 +60,9 @@ void user_creatable_add_qapi(ObjectOptions *options, Error **errp)
60 qdict_del(props, "id");
61
62 v = qobject_input_visitor_new(QOBJECT(props));
127 - obj = user_creatable_add_type(ObjectType_str(options->qom_type),
128 - options->id, props, v, errp);
129 - object_unref(obj);
63 + object_new_with_props_from_qdict(ObjectType_str(options->qom_type),
64 + object_get_objects_root(),
65 + options->id, props, v, errp);
66 qobject_unref(qobj);
67 visit_free(v);
68 }
tests/unit/check-qom-proplist.c
+2 -3
@@ -461,10 +461,9 @@ static void test_dummy_createlist_parentless(void)
461 static bool test_create_obj(QDict *qdict, Error **errp)
462 {
463 Visitor *v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
464 - Object *obj = user_creatable_add_type(TYPE_DUMMY, "dev0", qdict, v, errp);
465 -
464 + Object *obj = object_new_with_props_from_qdict(
465 + TYPE_DUMMY, object_get_objects_root(), "dev0", qdict, v, errp);
466 visit_free(v);
467 - object_unref(obj);
467 return !!obj;
468 }
469