Now that we can safely call QOBJECT() on QObject * and children types,
we can have a single macro to ref/unref the object.
Change the incref/decref prefix name for the more common ref/unref.
Note that before the patch, "QDECREF(obj)" was problematic because it
would expand to "obj ? obj : ...", which could evaluate "obj" multiple
times.
Signed-off-by: Marc-André Lureau <address@hidden>
---
+++ b/include/qapi/qmp/qobject.h
@@ -48,14 +48,6 @@ struct QObject {
__x ? container_of(&(__x)->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
@@ -78,10 +70,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(QObject *obj)
{
if (obj) {
obj->base.refcnt++;
@@ -102,11 +91,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(QObject *obj)
{
assert(!obj || obj->base.refcnt);
if (obj && --obj->base.refcnt == 0) {
@@ -114,6 +99,19 @@ static inline void qobject_decref(QObject *obj)
}
}
+/**
+ * qobject_ref(): Increment QObject's reference count
+ */
+#define qobject_ref(obj) \
+ qobject_ref(QOBJECT(obj))