]> git.proxmox.com Git - mirror_qemu.git/blame - qapi/qapi-dealloc-visitor.c
Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging
[mirror_qemu.git] / qapi / qapi-dealloc-visitor.c
CommitLineData
d5f3c29c
MR
1/*
2 * Dealloc Visitor
3 *
08f9541d 4 * Copyright (C) 2012-2016 Red Hat, Inc.
d5f3c29c
MR
5 * Copyright IBM, Corp. 2011
6 *
7 * Authors:
8 * Michael Roth <mdroth@linux.vnet.ibm.com>
9 *
10 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
11 * See the COPYING.LIB file in the top-level directory.
12 *
13 */
14
cbf21151 15#include "qemu/osdep.h"
7b1b5d19 16#include "qapi/dealloc-visitor.h"
1de7afc9 17#include "qemu/queue.h"
d5f3c29c 18#include "qemu-common.h"
7b1b5d19
PB
19#include "qapi/qmp/types.h"
20#include "qapi/visitor-impl.h"
d5f3c29c 21
d5f3c29c
MR
22struct QapiDeallocVisitor
23{
24 Visitor visitor;
d5f3c29c
MR
25};
26
0b2a0d6b 27static void qapi_dealloc_start_struct(Visitor *v, const char *name, void **obj,
337283df 28 size_t unused, Error **errp)
d5f3c29c 29{
d5f3c29c
MR
30}
31
1158bb2a 32static void qapi_dealloc_end_struct(Visitor *v, void **obj)
d5f3c29c 33{
d5f3c29c 34 if (obj) {
7267c094 35 g_free(*obj);
d5f3c29c
MR
36 }
37}
38
dbf11922
EB
39static void qapi_dealloc_start_alternate(Visitor *v, const char *name,
40 GenericAlternate **obj, size_t size,
41 bool promote_int, Error **errp)
3dce9cad 42{
3dce9cad
WX
43}
44
1158bb2a 45static void qapi_dealloc_end_alternate(Visitor *v, void **obj)
3dce9cad 46{
3dce9cad
WX
47 if (obj) {
48 g_free(*obj);
49 }
50}
51
d9f62dde
EB
52static void qapi_dealloc_start_list(Visitor *v, const char *name,
53 GenericList **list, size_t size,
54 Error **errp)
d5f3c29c
MR
55{
56}
57
d9f62dde 58static GenericList *qapi_dealloc_next_list(Visitor *v, GenericList *tail,
e65d89bf 59 size_t size)
d5f3c29c 60{
d9f62dde
EB
61 GenericList *next = tail->next;
62 g_free(tail);
63 return next;
d5f3c29c
MR
64}
65
1158bb2a 66static void qapi_dealloc_end_list(Visitor *v, void **obj)
d5f3c29c
MR
67{
68}
69
0b2a0d6b 70static void qapi_dealloc_type_str(Visitor *v, const char *name, char **obj,
d5f3c29c
MR
71 Error **errp)
72{
b690d679
PL
73 if (obj) {
74 g_free(*obj);
75 }
d5f3c29c
MR
76}
77
0b2a0d6b 78static void qapi_dealloc_type_int64(Visitor *v, const char *name, int64_t *obj,
4c40314a 79 Error **errp)
d5f3c29c
MR
80{
81}
82
0b2a0d6b
EB
83static void qapi_dealloc_type_uint64(Visitor *v, const char *name,
84 uint64_t *obj, Error **errp)
f755dea7
EB
85{
86}
87
0b2a0d6b 88static void qapi_dealloc_type_bool(Visitor *v, const char *name, bool *obj,
d5f3c29c
MR
89 Error **errp)
90{
91}
92
0b2a0d6b 93static void qapi_dealloc_type_number(Visitor *v, const char *name, double *obj,
d5f3c29c
MR
94 Error **errp)
95{
96}
97
0b2a0d6b
EB
98static void qapi_dealloc_type_anything(Visitor *v, const char *name,
99 QObject **obj, Error **errp)
28770e05
MA
100{
101 if (obj) {
102 qobject_decref(*obj);
103 }
104}
105
3bc97fd5
EB
106static void qapi_dealloc_type_null(Visitor *v, const char *name, Error **errp)
107{
108}
109
2c0ef9f4 110static void qapi_dealloc_free(Visitor *v)
d5f3c29c 111{
2c0ef9f4 112 g_free(container_of(v, QapiDeallocVisitor, visitor));
d5f3c29c
MR
113}
114
2c0ef9f4 115Visitor *qapi_dealloc_visitor_new(void)
d5f3c29c
MR
116{
117 QapiDeallocVisitor *v;
118
7267c094 119 v = g_malloc0(sizeof(*v));
d5f3c29c 120
983f52d4 121 v->visitor.type = VISITOR_DEALLOC;
d5f3c29c
MR
122 v->visitor.start_struct = qapi_dealloc_start_struct;
123 v->visitor.end_struct = qapi_dealloc_end_struct;
dbf11922
EB
124 v->visitor.start_alternate = qapi_dealloc_start_alternate;
125 v->visitor.end_alternate = qapi_dealloc_end_alternate;
d5f3c29c
MR
126 v->visitor.start_list = qapi_dealloc_start_list;
127 v->visitor.next_list = qapi_dealloc_next_list;
128 v->visitor.end_list = qapi_dealloc_end_list;
4c40314a 129 v->visitor.type_int64 = qapi_dealloc_type_int64;
f755dea7 130 v->visitor.type_uint64 = qapi_dealloc_type_uint64;
d5f3c29c
MR
131 v->visitor.type_bool = qapi_dealloc_type_bool;
132 v->visitor.type_str = qapi_dealloc_type_str;
133 v->visitor.type_number = qapi_dealloc_type_number;
28770e05 134 v->visitor.type_any = qapi_dealloc_type_anything;
3bc97fd5 135 v->visitor.type_null = qapi_dealloc_type_null;
2c0ef9f4 136 v->visitor.free = qapi_dealloc_free;
d5f3c29c 137
2c0ef9f4 138 return &v->visitor;
d5f3c29c 139}