1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#include "qemu/osdep.h"
16#include "qapi/dealloc-visitor.h"
17#include "qapi/qmp/qnull.h"
18#include "qemu/queue.h"
19#include "qemu-common.h"
20#include "qapi/visitor-impl.h"
21
22struct QapiDeallocVisitor
23{
24 Visitor visitor;
25};
26
27static void qapi_dealloc_start_struct(Visitor *v, const char *name, void **obj,
28 size_t unused, Error **errp)
29{
30}
31
32static void qapi_dealloc_end_struct(Visitor *v, void **obj)
33{
34 if (obj) {
35 g_free(*obj);
36 }
37}
38
39static void qapi_dealloc_start_alternate(Visitor *v, const char *name,
40 GenericAlternate **obj, size_t size,
41 Error **errp)
42{
43}
44
45static void qapi_dealloc_end_alternate(Visitor *v, void **obj)
46{
47 if (obj) {
48 g_free(*obj);
49 }
50}
51
52static void qapi_dealloc_start_list(Visitor *v, const char *name,
53 GenericList **list, size_t size,
54 Error **errp)
55{
56}
57
58static GenericList *qapi_dealloc_next_list(Visitor *v, GenericList *tail,
59 size_t size)
60{
61 GenericList *next = tail->next;
62 g_free(tail);
63 return next;
64}
65
66static void qapi_dealloc_end_list(Visitor *v, void **obj)
67{
68}
69
70static void qapi_dealloc_type_str(Visitor *v, const char *name, char **obj,
71 Error **errp)
72{
73 if (obj) {
74 g_free(*obj);
75 }
76}
77
78static void qapi_dealloc_type_int64(Visitor *v, const char *name, int64_t *obj,
79 Error **errp)
80{
81}
82
83static void qapi_dealloc_type_uint64(Visitor *v, const char *name,
84 uint64_t *obj, Error **errp)
85{
86}
87
88static void qapi_dealloc_type_bool(Visitor *v, const char *name, bool *obj,
89 Error **errp)
90{
91}
92
93static void qapi_dealloc_type_number(Visitor *v, const char *name, double *obj,
94 Error **errp)
95{
96}
97
98static void qapi_dealloc_type_anything(Visitor *v, const char *name,
99 QObject **obj, Error **errp)
100{
101 if (obj) {
102 qobject_unref(*obj);
103 }
104}
105
106static void qapi_dealloc_type_null(Visitor *v, const char *name,
107 QNull **obj, Error **errp)
108{
109 if (obj) {
110 qobject_unref(*obj);
111 }
112}
113
114static void qapi_dealloc_free(Visitor *v)
115{
116 g_free(container_of(v, QapiDeallocVisitor, visitor));
117}
118
119Visitor *qapi_dealloc_visitor_new(void)
120{
121 QapiDeallocVisitor *v;
122
123 v = g_malloc0(sizeof(*v));
124
125 v->visitor.type = VISITOR_DEALLOC;
126 v->visitor.start_struct = qapi_dealloc_start_struct;
127 v->visitor.end_struct = qapi_dealloc_end_struct;
128 v->visitor.start_alternate = qapi_dealloc_start_alternate;
129 v->visitor.end_alternate = qapi_dealloc_end_alternate;
130 v->visitor.start_list = qapi_dealloc_start_list;
131 v->visitor.next_list = qapi_dealloc_next_list;
132 v->visitor.end_list = qapi_dealloc_end_list;
133 v->visitor.type_int64 = qapi_dealloc_type_int64;
134 v->visitor.type_uint64 = qapi_dealloc_type_uint64;
135 v->visitor.type_bool = qapi_dealloc_type_bool;
136 v->visitor.type_str = qapi_dealloc_type_str;
137 v->visitor.type_number = qapi_dealloc_type_number;
138 v->visitor.type_any = qapi_dealloc_type_anything;
139 v->visitor.type_null = qapi_dealloc_type_null;
140 v->visitor.free = qapi_dealloc_free;
141
142 return &v->visitor;
143}
144