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