Skip to content

Commit d709bbf

Browse files
elmarcobonzini
authored andcommitted
include/qapi: add g_autoptr support for qobject types
Need wrappers for qobject_unref() calls, which is a macro. Signed-off-by: Marc-André Lureau <[email protected]> Reviewed-by: Markus Armbruster <[email protected]> Reviewed-by: Richard Henderson <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 7773e13 commit d709bbf

File tree

12 files changed

+54
-0
lines changed

12 files changed

+54
-0
lines changed

include/qapi/qmp/qbool.h

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ struct QBool {
2121
bool value;
2222
};
2323

24+
void qbool_unref(QBool *q);
25+
26+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(QBool, qbool_unref)
27+
2428
QBool *qbool_from_bool(bool value);
2529
bool qbool_get_bool(const QBool *qb);
2630

include/qapi/qmp/qdict.h

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ struct QDict {
3030
QLIST_HEAD(,QDictEntry) table[QDICT_BUCKET_MAX];
3131
};
3232

33+
void qdict_unref(QDict *q);
34+
35+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(QDict, qdict_unref)
36+
3337
/* Object API */
3438
QDict *qdict_new(void);
3539
const char *qdict_entry_key(const QDictEntry *entry);

include/qapi/qmp/qlist.h

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ struct QList {
2626
QTAILQ_HEAD(,QListEntry) head;
2727
};
2828

29+
void qlist_unref(QList *q);
30+
31+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(QList, qlist_unref)
32+
2933
#define qlist_append(qlist, obj) \
3034
qlist_append_obj(qlist, QOBJECT(obj))
3135

include/qapi/qmp/qnull.h

+4
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ static inline QNull *qnull(void)
2626
return qobject_ref(&qnull_);
2727
}
2828

29+
void qnull_unref(QNull *q);
30+
31+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(QNull, qnull_unref)
32+
2933
#endif /* QNULL_H */

include/qapi/qmp/qnum.h

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ struct QNum {
5454
} u;
5555
};
5656

57+
void qnum_unref(QNum *q);
58+
59+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(QNum, qnum_unref)
60+
5761
QNum *qnum_from_int(int64_t value);
5862
QNum *qnum_from_uint(uint64_t value);
5963
QNum *qnum_from_double(double value);

include/qapi/qmp/qstring.h

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ struct QString {
2020
const char *string;
2121
};
2222

23+
void qstring_unref(QString *q);
24+
25+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(QString, qstring_unref)
26+
2327
QString *qstring_new(void);
2428
QString *qstring_from_str(const char *str);
2529
QString *qstring_from_substr(const char *str, size_t start, size_t end);

qobject/qbool.c

+5
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,8 @@ void qbool_destroy_obj(QObject *obj)
5656
assert(obj != NULL);
5757
g_free(qobject_to(QBool, obj));
5858
}
59+
60+
void qbool_unref(QBool *q)
61+
{
62+
qobject_unref(q);
63+
}

qobject/qdict.c

+5
Original file line numberDiff line numberDiff line change
@@ -442,3 +442,8 @@ void qdict_destroy_obj(QObject *obj)
442442

443443
g_free(qdict);
444444
}
445+
446+
void qdict_unref(QDict *q)
447+
{
448+
qobject_unref(q);
449+
}

qobject/qlist.c

+5
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,8 @@ void qlist_destroy_obj(QObject *obj)
182182

183183
g_free(qlist);
184184
}
185+
186+
void qlist_unref(QList *q)
187+
{
188+
qobject_unref(q);
189+
}

qobject/qnull.c

+5
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ bool qnull_is_equal(const QObject *x, const QObject *y)
2929
{
3030
return true;
3131
}
32+
33+
void qnull_unref(QNull *q)
34+
{
35+
qobject_unref(q);
36+
}

qobject/qnum.c

+5
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,8 @@ void qnum_destroy_obj(QObject *obj)
239239
assert(obj != NULL);
240240
g_free(qobject_to(QNum, obj));
241241
}
242+
243+
void qnum_unref(QNum *q)
244+
{
245+
qobject_unref(q);
246+
}

qobject/qstring.c

+5
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,8 @@ void qstring_destroy_obj(QObject *obj)
100100
g_free((char *)qs->string);
101101
g_free(qs);
102102
}
103+
104+
void qstring_unref(QString *q)
105+
{
106+
qobject_unref(q);
107+
}

0 commit comments

Comments
 (0)