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 --- include/qapi/qmp/qnull.h | 3 +-- include/qapi/qmp/qobject.h | 9 ++++++++- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/qapi/qmp/qnull.h b/include/qapi/qmp/qnull.h index 75b29c6..c142688 100644 --- a/include/qapi/qmp/qnull.h +++ b/include/qapi/qmp/qnull.h @@ -23,8 +23,7 @@ extern QNull qnull_; static inline QNull *qnull(void) { - qobject_ref(&qnull_); - return &qnull_; + return qobject_ref(&qnull_); } bool qnull_is_equal(const QObject *x, const QObject *y); diff --git a/include/qapi/qmp/qobject.h b/include/qapi/qmp/qobject.h index e20006f..fcfd549 100644 --- a/include/qapi/qmp/qobject.h +++ b/include/qapi/qmp/qobject.h @@ -103,8 +103,15 @@ static inline void qobject_unref_impl(QObject *obj) /** * qobject_ref(): Increment QObject's reference count + * + * Returns: the same @obj. The type of @obj will be propagated to the + * return type. */ -#define qobject_ref(obj) qobject_ref_impl(QOBJECT(obj)) +#define qobject_ref(obj) ({ \ + typeof(obj) _o = (obj); \ + qobject_ref_impl(QOBJECT(_o)); \ + _o; \ +}) /** * qobject_unref(): Decrement QObject's reference count, deallocate -- cgit v1.1