Extract a subroutine from user_creatable_add_qapi that converts object options to a dictionary of properties and returns them. Use g_autoptr to simplify the code. No functional change.
Signed-off-by: Steve Sistare <steven.sist...@oracle.com> --- include/qapi/visitor.h | 1 + include/qom/object_interfaces.h | 8 ++++++++ qom/object_interfaces.c | 27 ++++++++++++++------------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index 27b85d4..640b941 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -268,6 +268,7 @@ void visit_complete(Visitor *v, void *opaque); */ void visit_free(Visitor *v); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(Visitor, visit_free) /*** Visiting structures ***/ diff --git a/include/qom/object_interfaces.h b/include/qom/object_interfaces.h index 02b11a7..2384263 100644 --- a/include/qom/object_interfaces.h +++ b/include/qom/object_interfaces.h @@ -98,6 +98,14 @@ Object *user_creatable_add_type(const char *type, const char *id, void user_creatable_add_qapi(ObjectOptions *options, Error **errp); /** + * user_creatable_get_props: + * @options: the object definition + * + * Convert @options to a dictionary of properties and return it. + */ +QDict *user_creatable_get_props(ObjectOptions *options); + +/** * user_creatable_parse_str: * @str: the object definition string as passed on the command line * @errp: if an error occurs, a pointer to an area to store the error diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index e0833c8..104d75c 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -139,26 +139,27 @@ out: void user_creatable_add_qapi(ObjectOptions *options, Error **errp) { - Visitor *v; - QObject *qobj; - QDict *props; - Object *obj; + g_autoptr(Visitor) v; + g_autoptr(Object) obj; + g_autoptr(QDict) props = user_creatable_get_props(options); - v = qobject_output_visitor_new(&qobj); - visit_type_ObjectOptions(v, NULL, &options, &error_abort); - visit_complete(v, &qobj); - visit_free(v); - - props = qobject_to(QDict, qobj); qdict_del(props, "qom-type"); 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); - qobject_unref(qobj); - visit_free(v); +} + +QDict *user_creatable_get_props(ObjectOptions *options) +{ + g_autoptr(Visitor) v; + QObject *qobj; + + v = qobject_output_visitor_new(&qobj); + visit_type_ObjectOptions(v, NULL, &options, &error_abort); + visit_complete(v, &qobj); + return qobject_to(QDict, qobj); } char *object_property_help(const char *name, const char *type, -- 1.8.3.1