Skip to content

Commit

Permalink
include/qapi: add g_autoptr support for qobject types
Browse files Browse the repository at this point in the history
Need wrappers for qobject_unref() calls, which is a macro.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220323155743.1585078-10-marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
elmarco authored and bonzini committed Apr 3, 2022
1 parent bd9fc60 commit 4315bc6
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/qapi/qmp/qbool.h
Expand Up @@ -21,6 +21,10 @@ struct QBool {
bool value;
};

void qbool_unref(QBool *q);

G_DEFINE_AUTOPTR_CLEANUP_FUNC(QBool, qbool_unref)

QBool *qbool_from_bool(bool value);
bool qbool_get_bool(const QBool *qb);

Expand Down
4 changes: 4 additions & 0 deletions include/qapi/qmp/qdict.h
Expand Up @@ -30,6 +30,10 @@ struct QDict {
QLIST_HEAD(,QDictEntry) table[QDICT_BUCKET_MAX];
};

void qdict_unref(QDict *q);

G_DEFINE_AUTOPTR_CLEANUP_FUNC(QDict, qdict_unref)

/* Object API */
QDict *qdict_new(void);
const char *qdict_entry_key(const QDictEntry *entry);
Expand Down
4 changes: 4 additions & 0 deletions include/qapi/qmp/qlist.h
Expand Up @@ -26,6 +26,10 @@ struct QList {
QTAILQ_HEAD(,QListEntry) head;
};

void qlist_unref(QList *q);

G_DEFINE_AUTOPTR_CLEANUP_FUNC(QList, qlist_unref)

#define qlist_append(qlist, obj) \
qlist_append_obj(qlist, QOBJECT(obj))

Expand Down
4 changes: 4 additions & 0 deletions include/qapi/qmp/qnull.h
Expand Up @@ -26,4 +26,8 @@ static inline QNull *qnull(void)
return qobject_ref(&qnull_);
}

void qnull_unref(QNull *q);

G_DEFINE_AUTOPTR_CLEANUP_FUNC(QNull, qnull_unref)

#endif /* QNULL_H */
4 changes: 4 additions & 0 deletions include/qapi/qmp/qnum.h
Expand Up @@ -54,6 +54,10 @@ struct QNum {
} u;
};

void qnum_unref(QNum *q);

G_DEFINE_AUTOPTR_CLEANUP_FUNC(QNum, qnum_unref)

QNum *qnum_from_int(int64_t value);
QNum *qnum_from_uint(uint64_t value);
QNum *qnum_from_double(double value);
Expand Down
4 changes: 4 additions & 0 deletions include/qapi/qmp/qstring.h
Expand Up @@ -20,6 +20,10 @@ struct QString {
const char *string;
};

void qstring_unref(QString *q);

G_DEFINE_AUTOPTR_CLEANUP_FUNC(QString, qstring_unref)

QString *qstring_new(void);
QString *qstring_from_str(const char *str);
QString *qstring_from_substr(const char *str, size_t start, size_t end);
Expand Down
5 changes: 5 additions & 0 deletions qobject/qbool.c
Expand Up @@ -56,3 +56,8 @@ void qbool_destroy_obj(QObject *obj)
assert(obj != NULL);
g_free(qobject_to(QBool, obj));
}

void qbool_unref(QBool *q)
{
qobject_unref(q);
}
5 changes: 5 additions & 0 deletions qobject/qdict.c
Expand Up @@ -442,3 +442,8 @@ void qdict_destroy_obj(QObject *obj)

g_free(qdict);
}

void qdict_unref(QDict *q)
{
qobject_unref(q);
}
5 changes: 5 additions & 0 deletions qobject/qlist.c
Expand Up @@ -182,3 +182,8 @@ void qlist_destroy_obj(QObject *obj)

g_free(qlist);
}

void qlist_unref(QList *q)
{
qobject_unref(q);
}
5 changes: 5 additions & 0 deletions qobject/qnull.c
Expand Up @@ -29,3 +29,8 @@ bool qnull_is_equal(const QObject *x, const QObject *y)
{
return true;
}

void qnull_unref(QNull *q)
{
qobject_unref(q);
}
5 changes: 5 additions & 0 deletions qobject/qnum.c
Expand Up @@ -239,3 +239,8 @@ void qnum_destroy_obj(QObject *obj)
assert(obj != NULL);
g_free(qobject_to(QNum, obj));
}

void qnum_unref(QNum *q)
{
qobject_unref(q);
}
5 changes: 5 additions & 0 deletions qobject/qstring.c
Expand Up @@ -100,3 +100,8 @@ void qstring_destroy_obj(QObject *obj)
g_free((char *)qs->string);
g_free(qs);
}

void qstring_unref(QString *q)
{
qobject_unref(q);
}

0 comments on commit 4315bc6

Please sign in to comment.