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é <[email protected]> Reviewed-by: Marc-André Lureau <[email protected]> Signed-off-by: Daniel P. Berrangé <[email protected]> --- 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
