summary refs log tree commit diff stats
path: root/include/qapi/qmp/qobject.h
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2018-04-19 17:01:43 +0200
committerMarkus Armbruster <armbru@redhat.com>2018-05-04 08:27:53 +0200
commitcb3e7f08aeaab0ab13e629ce8496dca150a449ba (patch)
tree189830b93bea625aac19f86f26dc4b04cd99f5a3 /include/qapi/qmp/qobject.h
parent3d3eacaeccaab718ea0e2ddaa578bfae9e311c59 (diff)
downloadfocaccia-qemu-cb3e7f08aeaab0ab13e629ce8496dca150a449ba.tar.gz
focaccia-qemu-cb3e7f08aeaab0ab13e629ce8496dca150a449ba.zip
qobject: Replace qobject_incref/QINCREF qobject_decref/QDECREF
Now that we can safely call QOBJECT() on QObject * as well as its
subtypes, we can have macros qobject_ref() / qobject_unref() that work
everywhere instead of having to use QINCREF() / QDECREF() for QObject
and qobject_incref() / qobject_decref() for its subtypes.

The replacement is mechanical, except I broke a long line, and added a
cast in monitor_qmp_cleanup_req_queue_locked().  Unlike
qobject_decref(), qobject_unref() doesn't accept void *.

Note that the new macros evaluate their argument exactly once, thus no
need to shout them.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180419150145.24795-4-marcandre.lureau@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Rebased, semantic conflict resolved, commit message improved]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'include/qapi/qmp/qobject.h')
-rw-r--r--include/qapi/qmp/qobject.h40
1 files changed, 18 insertions, 22 deletions
diff --git a/include/qapi/qmp/qobject.h b/include/qapi/qmp/qobject.h
index a713c0165b..e20006faf5 100644
--- a/include/qapi/qmp/qobject.h
+++ b/include/qapi/qmp/qobject.h
@@ -15,17 +15,17 @@
  * ------------------------------------
  *
  *  - Returning references: A function that returns an object may
- *  return it as either a weak or a strong reference.  If the reference
- *  is strong, you are responsible for calling QDECREF() on the reference
- *  when you are done.
+ *  return it as either a weak or a strong reference.  If the
+ *  reference is strong, you are responsible for calling
+ *  qobject_unref() on the reference when you are done.
  *
  *  If the reference is weak, the owner of the reference may free it at
  *  any time in the future.  Before storing the reference anywhere, you
- *  should call QINCREF() to make the reference strong.
+ *  should call qobject_ref() to make the reference strong.
  *
  *  - Transferring ownership: when you transfer ownership of a reference
  *  by calling a function, you are no longer responsible for calling
- *  QDECREF() when the reference is no longer needed.  In other words,
+ *  qobject_unref() when the reference is no longer needed.  In other words,
  *  when the function returns you must behave as if the reference to the
  *  passed object was weak.
  */
@@ -50,14 +50,6 @@ struct QObject {
     _obj ? container_of(&(_obj)->base, QObject, base) : NULL;   \
 })
 
-/* High-level interface for qobject_incref() */
-#define QINCREF(obj)      \
-    qobject_incref(QOBJECT(obj))
-
-/* High-level interface for qobject_decref() */
-#define QDECREF(obj)              \
-    qobject_decref(obj ? QOBJECT(obj) : NULL)
-
 /* Required for qobject_to() */
 #define QTYPE_CAST_TO_QNull     QTYPE_QNULL
 #define QTYPE_CAST_TO_QNum      QTYPE_QNUM
@@ -80,10 +72,7 @@ static inline void qobject_init(QObject *obj, QType type)
     obj->base.type = type;
 }
 
-/**
- * qobject_incref(): Increment QObject's reference count
- */
-static inline void qobject_incref(QObject *obj)
+static inline void qobject_ref_impl(QObject *obj)
 {
     if (obj) {
         obj->base.refcnt++;
@@ -104,11 +93,7 @@ bool qobject_is_equal(const QObject *x, const QObject *y);
  */
 void qobject_destroy(QObject *obj);
 
-/**
- * qobject_decref(): Decrement QObject's reference count, deallocate
- * when it reaches zero
- */
-static inline void qobject_decref(QObject *obj)
+static inline void qobject_unref_impl(QObject *obj)
 {
     assert(!obj || obj->base.refcnt);
     if (obj && --obj->base.refcnt == 0) {
@@ -117,6 +102,17 @@ static inline void qobject_decref(QObject *obj)
 }
 
 /**
+ * qobject_ref(): Increment QObject's reference count
+ */
+#define qobject_ref(obj) qobject_ref_impl(QOBJECT(obj))
+
+/**
+ * qobject_unref(): Decrement QObject's reference count, deallocate
+ * when it reaches zero
+ */
+#define qobject_unref(obj) qobject_unref_impl(QOBJECT(obj))
+
+/**
  * qobject_type(): Return the QObject's type
  */
 static inline QType qobject_type(const QObject *obj)