xref: /openbmc/qemu/qapi/qapi-dealloc-visitor.c (revision f2a1cf9180f63e88bb38ff21c169da97c3f2bad5)
1d5f3c29cSMichael Roth /*
2d5f3c29cSMichael Roth  * Dealloc Visitor
3d5f3c29cSMichael Roth  *
408f9541dSEric Blake  * Copyright (C) 2012-2016 Red Hat, Inc.
5d5f3c29cSMichael Roth  * Copyright IBM, Corp. 2011
6d5f3c29cSMichael Roth  *
7d5f3c29cSMichael Roth  * Authors:
8d5f3c29cSMichael Roth  *  Michael Roth   <mdroth@linux.vnet.ibm.com>
9d5f3c29cSMichael Roth  *
10d5f3c29cSMichael Roth  * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
11d5f3c29cSMichael Roth  * See the COPYING.LIB file in the top-level directory.
12d5f3c29cSMichael Roth  *
13d5f3c29cSMichael Roth  */
14d5f3c29cSMichael Roth 
15cbf21151SPeter Maydell #include "qemu/osdep.h"
167b1b5d19SPaolo Bonzini #include "qapi/dealloc-visitor.h"
1715280c36SMarkus Armbruster #include "qapi/qmp/qnull.h"
187b1b5d19SPaolo Bonzini #include "qapi/visitor-impl.h"
19d5f3c29cSMichael Roth 
20d5f3c29cSMichael Roth struct QapiDeallocVisitor
21d5f3c29cSMichael Roth {
22d5f3c29cSMichael Roth     Visitor visitor;
23d5f3c29cSMichael Roth };
24d5f3c29cSMichael Roth 
qapi_dealloc_start_struct(Visitor * v,const char * name,void ** obj,size_t unused,Error ** errp)25*012d4c96SMarkus Armbruster static bool qapi_dealloc_start_struct(Visitor *v, const char *name, void **obj,
26337283dfSEric Blake                                       size_t unused, Error **errp)
27d5f3c29cSMichael Roth {
28*012d4c96SMarkus Armbruster     return true;
29d5f3c29cSMichael Roth }
30d5f3c29cSMichael Roth 
qapi_dealloc_end_struct(Visitor * v,void ** obj)311158bb2aSEric Blake static void qapi_dealloc_end_struct(Visitor *v, void **obj)
32d5f3c29cSMichael Roth {
33d5f3c29cSMichael Roth     if (obj) {
347267c094SAnthony Liguori         g_free(*obj);
35d5f3c29cSMichael Roth     }
36d5f3c29cSMichael Roth }
37d5f3c29cSMichael Roth 
qapi_dealloc_end_alternate(Visitor * v,void ** obj)381158bb2aSEric Blake static void qapi_dealloc_end_alternate(Visitor *v, void **obj)
393dce9cadSWenchao Xia {
403dce9cadSWenchao Xia     if (obj) {
413dce9cadSWenchao Xia         g_free(*obj);
423dce9cadSWenchao Xia     }
433dce9cadSWenchao Xia }
443dce9cadSWenchao Xia 
qapi_dealloc_start_list(Visitor * v,const char * name,GenericList ** list,size_t size,Error ** errp)45*012d4c96SMarkus Armbruster static bool qapi_dealloc_start_list(Visitor *v, const char *name,
46d9f62ddeSEric Blake                                     GenericList **list, size_t size,
47d9f62ddeSEric Blake                                     Error **errp)
48d5f3c29cSMichael Roth {
49*012d4c96SMarkus Armbruster     return true;
50d5f3c29cSMichael Roth }
51d5f3c29cSMichael Roth 
qapi_dealloc_next_list(Visitor * v,GenericList * tail,size_t size)52d9f62ddeSEric Blake static GenericList *qapi_dealloc_next_list(Visitor *v, GenericList *tail,
53e65d89bfSEric Blake                                            size_t size)
54d5f3c29cSMichael Roth {
55d9f62ddeSEric Blake     GenericList *next = tail->next;
56d9f62ddeSEric Blake     g_free(tail);
57d9f62ddeSEric Blake     return next;
580b9d8542SMichael Roth }
590b9d8542SMichael Roth 
qapi_dealloc_end_list(Visitor * v,void ** obj)601158bb2aSEric Blake static void qapi_dealloc_end_list(Visitor *v, void **obj)
61d5f3c29cSMichael Roth {
62d5f3c29cSMichael Roth }
63d5f3c29cSMichael Roth 
qapi_dealloc_type_str(Visitor * v,const char * name,char ** obj,Error ** errp)64*012d4c96SMarkus Armbruster static bool qapi_dealloc_type_str(Visitor *v, const char *name, char **obj,
65d5f3c29cSMichael Roth                                   Error **errp)
66d5f3c29cSMichael Roth {
67b690d679SPeter Lieven     if (obj) {
687267c094SAnthony Liguori         g_free(*obj);
69d5f3c29cSMichael Roth     }
70*012d4c96SMarkus Armbruster     return true;
71b690d679SPeter Lieven }
72d5f3c29cSMichael Roth 
qapi_dealloc_type_int64(Visitor * v,const char * name,int64_t * obj,Error ** errp)73*012d4c96SMarkus Armbruster static bool qapi_dealloc_type_int64(Visitor *v, const char *name, int64_t *obj,
74d5f3c29cSMichael Roth                                     Error **errp)
75d5f3c29cSMichael Roth {
76*012d4c96SMarkus Armbruster     return true;
77d5f3c29cSMichael Roth }
78d5f3c29cSMichael Roth 
qapi_dealloc_type_uint64(Visitor * v,const char * name,uint64_t * obj,Error ** errp)79*012d4c96SMarkus Armbruster static bool qapi_dealloc_type_uint64(Visitor *v, const char *name,
800b2a0d6bSEric Blake                                      uint64_t *obj, Error **errp)
81f755dea7SEric Blake {
82*012d4c96SMarkus Armbruster     return true;
83f755dea7SEric Blake }
84f755dea7SEric Blake 
qapi_dealloc_type_bool(Visitor * v,const char * name,bool * obj,Error ** errp)85*012d4c96SMarkus Armbruster static bool qapi_dealloc_type_bool(Visitor *v, const char *name, bool *obj,
86d5f3c29cSMichael Roth                                    Error **errp)
87d5f3c29cSMichael Roth {
88*012d4c96SMarkus Armbruster     return true;
89d5f3c29cSMichael Roth }
90d5f3c29cSMichael Roth 
qapi_dealloc_type_number(Visitor * v,const char * name,double * obj,Error ** errp)91*012d4c96SMarkus Armbruster static bool qapi_dealloc_type_number(Visitor *v, const char *name, double *obj,
92d5f3c29cSMichael Roth                                      Error **errp)
93d5f3c29cSMichael Roth {
94*012d4c96SMarkus Armbruster     return true;
95d5f3c29cSMichael Roth }
96d5f3c29cSMichael Roth 
qapi_dealloc_type_anything(Visitor * v,const char * name,QObject ** obj,Error ** errp)97*012d4c96SMarkus Armbruster static bool qapi_dealloc_type_anything(Visitor *v, const char *name,
980b2a0d6bSEric Blake                                        QObject **obj, Error **errp)
9928770e05SMarkus Armbruster {
10028770e05SMarkus Armbruster     if (obj) {
101cb3e7f08SMarc-André Lureau         qobject_unref(*obj);
10228770e05SMarkus Armbruster     }
103*012d4c96SMarkus Armbruster     return true;
10428770e05SMarkus Armbruster }
10528770e05SMarkus Armbruster 
qapi_dealloc_type_null(Visitor * v,const char * name,QNull ** obj,Error ** errp)106*012d4c96SMarkus Armbruster static bool qapi_dealloc_type_null(Visitor *v, const char *name,
107d2f95f4dSMarkus Armbruster                                    QNull **obj, Error **errp)
1083bc97fd5SEric Blake {
109d2f95f4dSMarkus Armbruster     if (obj) {
110cb3e7f08SMarc-André Lureau         qobject_unref(*obj);
111d2f95f4dSMarkus Armbruster     }
112*012d4c96SMarkus Armbruster     return true;
1133bc97fd5SEric Blake }
1143bc97fd5SEric Blake 
qapi_dealloc_free(Visitor * v)1152c0ef9f4SEric Blake static void qapi_dealloc_free(Visitor *v)
116d5f3c29cSMichael Roth {
1172c0ef9f4SEric Blake     g_free(container_of(v, QapiDeallocVisitor, visitor));
118d5f3c29cSMichael Roth }
119d5f3c29cSMichael Roth 
qapi_dealloc_visitor_new(void)1202c0ef9f4SEric Blake Visitor *qapi_dealloc_visitor_new(void)
121d5f3c29cSMichael Roth {
122d5f3c29cSMichael Roth     QapiDeallocVisitor *v;
123d5f3c29cSMichael Roth 
1247267c094SAnthony Liguori     v = g_malloc0(sizeof(*v));
125d5f3c29cSMichael Roth 
126983f52d4SEric Blake     v->visitor.type = VISITOR_DEALLOC;
127d5f3c29cSMichael Roth     v->visitor.start_struct = qapi_dealloc_start_struct;
128d5f3c29cSMichael Roth     v->visitor.end_struct = qapi_dealloc_end_struct;
129dbf11922SEric Blake     v->visitor.end_alternate = qapi_dealloc_end_alternate;
130d5f3c29cSMichael Roth     v->visitor.start_list = qapi_dealloc_start_list;
131d5f3c29cSMichael Roth     v->visitor.next_list = qapi_dealloc_next_list;
132d5f3c29cSMichael Roth     v->visitor.end_list = qapi_dealloc_end_list;
1334c40314aSEric Blake     v->visitor.type_int64 = qapi_dealloc_type_int64;
134f755dea7SEric Blake     v->visitor.type_uint64 = qapi_dealloc_type_uint64;
135d5f3c29cSMichael Roth     v->visitor.type_bool = qapi_dealloc_type_bool;
136d5f3c29cSMichael Roth     v->visitor.type_str = qapi_dealloc_type_str;
137d5f3c29cSMichael Roth     v->visitor.type_number = qapi_dealloc_type_number;
13828770e05SMarkus Armbruster     v->visitor.type_any = qapi_dealloc_type_anything;
1393bc97fd5SEric Blake     v->visitor.type_null = qapi_dealloc_type_null;
1402c0ef9f4SEric Blake     v->visitor.free = qapi_dealloc_free;
141d5f3c29cSMichael Roth 
1422c0ef9f4SEric Blake     return &v->visitor;
143d5f3c29cSMichael Roth }
144