From f5a74a5a50387c6f980b2e2f94f062487a1826da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 19 Apr 2018 17:01:44 +0200 Subject: qobject: Modify qobject_ref() to return obj MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For convenience and clarity, make it possible to call qobject_ref() at the time when the reference is associated with a variable, or argument, by making qobject_ref() return the same pointer as given. Use that to simplify the callers. Signed-off-by: Marc-André Lureau Reviewed-by: Eric Blake Message-Id: <20180419150145.24795-5-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster [Useless change to qobject_ref_impl() dropped, commit message improved slightly] Signed-off-by: Markus Armbruster --- qapi/qobject-input-visitor.c | 6 ++---- qapi/qobject-output-visitor.c | 7 +++---- 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'qapi') diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index 7a290c4..da57f4c 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -588,8 +588,7 @@ static void qobject_input_type_any(Visitor *v, const char *name, QObject **obj, return; } - qobject_ref(qobj); - *obj = qobj; + *obj = qobject_ref(qobj); } static void qobject_input_type_null(Visitor *v, const char *name, @@ -677,8 +676,7 @@ static QObjectInputVisitor *qobject_input_visitor_base_new(QObject *obj) v->visitor.optional = qobject_input_optional; v->visitor.free = qobject_input_free; - v->root = obj; - qobject_ref(obj); + v->root = qobject_ref(obj); return v; } diff --git a/qapi/qobject-output-visitor.c b/qapi/qobject-output-visitor.c index 3a933b4..89ffd8a 100644 --- a/qapi/qobject-output-visitor.c +++ b/qapi/qobject-output-visitor.c @@ -188,8 +188,8 @@ static void qobject_output_type_any(Visitor *v, const char *name, QObject **obj, Error **errp) { QObjectOutputVisitor *qov = to_qov(v); - qobject_ref(*obj); - qobject_output_add_obj(qov, name, *obj); + + qobject_output_add_obj(qov, name, qobject_ref(*obj)); } static void qobject_output_type_null(Visitor *v, const char *name, @@ -210,8 +210,7 @@ static void qobject_output_complete(Visitor *v, void *opaque) assert(qov->root && QSLIST_EMPTY(&qov->stack)); assert(opaque == qov->result); - qobject_ref(qov->root); - *qov->result = qov->root; + *qov->result = qobject_ref(qov->root); qov->result = NULL; } -- cgit v1.1