blob: fd6f9fb61cf621f2c6bea2b37d2075bbc13c0a25 [file] [log] [blame]
Michael Rothd5f3c292011-07-19 14:50:35 -05001/*
2 * Dealloc Visitor
3 *
Eric Blake08f95412016-01-29 06:48:59 -07004 * Copyright (C) 2012-2016 Red Hat, Inc.
Michael Rothd5f3c292011-07-19 14:50:35 -05005 * 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
Peter Maydellcbf21152016-01-29 17:49:57 +000015#include "qemu/osdep.h"
Paolo Bonzini7b1b5d12012-12-17 18:19:43 +010016#include "qapi/dealloc-visitor.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010017#include "qemu/queue.h"
Michael Rothd5f3c292011-07-19 14:50:35 -050018#include "qemu-common.h"
Paolo Bonzini7b1b5d12012-12-17 18:19:43 +010019#include "qapi/qmp/types.h"
20#include "qapi/visitor-impl.h"
Michael Rothd5f3c292011-07-19 14:50:35 -050021
Michael Rothd5f3c292011-07-19 14:50:35 -050022struct QapiDeallocVisitor
23{
24 Visitor visitor;
Michael Rothd5f3c292011-07-19 14:50:35 -050025};
26
Eric Blake0b2a0d62016-01-29 06:48:56 -070027static void qapi_dealloc_start_struct(Visitor *v, const char *name, void **obj,
Eric Blake337283d2016-01-29 06:48:57 -070028 size_t unused, Error **errp)
Michael Rothd5f3c292011-07-19 14:50:35 -050029{
Michael Rothd5f3c292011-07-19 14:50:35 -050030}
31
Eric Blake1158bb22016-06-09 10:48:34 -060032static void qapi_dealloc_end_struct(Visitor *v, void **obj)
Michael Rothd5f3c292011-07-19 14:50:35 -050033{
Michael Rothd5f3c292011-07-19 14:50:35 -050034 if (obj) {
Anthony Liguori7267c092011-08-20 22:09:37 -050035 g_free(*obj);
Michael Rothd5f3c292011-07-19 14:50:35 -050036 }
37}
38
Eric Blakedbf11922016-02-17 23:48:29 -070039static void qapi_dealloc_start_alternate(Visitor *v, const char *name,
40 GenericAlternate **obj, size_t size,
Marc-André Lureau60390d22017-06-07 20:35:59 +040041 Error **errp)
Wenchao Xia3dce9ca2013-11-06 02:35:50 +080042{
Wenchao Xia3dce9ca2013-11-06 02:35:50 +080043}
44
Eric Blake1158bb22016-06-09 10:48:34 -060045static void qapi_dealloc_end_alternate(Visitor *v, void **obj)
Wenchao Xia3dce9ca2013-11-06 02:35:50 +080046{
Wenchao Xia3dce9ca2013-11-06 02:35:50 +080047 if (obj) {
48 g_free(*obj);
49 }
50}
51
Eric Blaked9f62dd2016-04-28 15:45:31 -060052static void qapi_dealloc_start_list(Visitor *v, const char *name,
53 GenericList **list, size_t size,
54 Error **errp)
Michael Rothd5f3c292011-07-19 14:50:35 -050055{
56}
57
Eric Blaked9f62dd2016-04-28 15:45:31 -060058static GenericList *qapi_dealloc_next_list(Visitor *v, GenericList *tail,
Eric Blakee65d89b2016-02-17 23:48:23 -070059 size_t size)
Michael Rothd5f3c292011-07-19 14:50:35 -050060{
Eric Blaked9f62dd2016-04-28 15:45:31 -060061 GenericList *next = tail->next;
62 g_free(tail);
63 return next;
Michael Rothd5f3c292011-07-19 14:50:35 -050064}
65
Eric Blake1158bb22016-06-09 10:48:34 -060066static void qapi_dealloc_end_list(Visitor *v, void **obj)
Michael Rothd5f3c292011-07-19 14:50:35 -050067{
68}
69
Eric Blake0b2a0d62016-01-29 06:48:56 -070070static void qapi_dealloc_type_str(Visitor *v, const char *name, char **obj,
Michael Rothd5f3c292011-07-19 14:50:35 -050071 Error **errp)
72{
Peter Lievenb690d672014-05-08 18:03:15 +020073 if (obj) {
74 g_free(*obj);
75 }
Michael Rothd5f3c292011-07-19 14:50:35 -050076}
77
Eric Blake0b2a0d62016-01-29 06:48:56 -070078static void qapi_dealloc_type_int64(Visitor *v, const char *name, int64_t *obj,
Eric Blake4c403142016-01-29 06:48:49 -070079 Error **errp)
Michael Rothd5f3c292011-07-19 14:50:35 -050080{
81}
82
Eric Blake0b2a0d62016-01-29 06:48:56 -070083static void qapi_dealloc_type_uint64(Visitor *v, const char *name,
84 uint64_t *obj, Error **errp)
Eric Blakef755dea2016-01-29 06:48:50 -070085{
86}
87
Eric Blake0b2a0d62016-01-29 06:48:56 -070088static void qapi_dealloc_type_bool(Visitor *v, const char *name, bool *obj,
Michael Rothd5f3c292011-07-19 14:50:35 -050089 Error **errp)
90{
91}
92
Eric Blake0b2a0d62016-01-29 06:48:56 -070093static void qapi_dealloc_type_number(Visitor *v, const char *name, double *obj,
Michael Rothd5f3c292011-07-19 14:50:35 -050094 Error **errp)
95{
96}
97
Eric Blake0b2a0d62016-01-29 06:48:56 -070098static void qapi_dealloc_type_anything(Visitor *v, const char *name,
99 QObject **obj, Error **errp)
Markus Armbruster28770e02015-09-16 13:06:24 +0200100{
101 if (obj) {
102 qobject_decref(*obj);
103 }
104}
105
Eric Blake3bc97fd2016-04-28 15:45:22 -0600106static void qapi_dealloc_type_null(Visitor *v, const char *name, Error **errp)
107{
108}
109
Eric Blake2c0ef9f2016-06-09 10:48:35 -0600110static void qapi_dealloc_free(Visitor *v)
Michael Rothd5f3c292011-07-19 14:50:35 -0500111{
Eric Blake2c0ef9f2016-06-09 10:48:35 -0600112 g_free(container_of(v, QapiDeallocVisitor, visitor));
Michael Rothd5f3c292011-07-19 14:50:35 -0500113}
114
Eric Blake2c0ef9f2016-06-09 10:48:35 -0600115Visitor *qapi_dealloc_visitor_new(void)
Michael Rothd5f3c292011-07-19 14:50:35 -0500116{
117 QapiDeallocVisitor *v;
118
Anthony Liguori7267c092011-08-20 22:09:37 -0500119 v = g_malloc0(sizeof(*v));
Michael Rothd5f3c292011-07-19 14:50:35 -0500120
Eric Blake983f52d2016-04-28 15:45:09 -0600121 v->visitor.type = VISITOR_DEALLOC;
Michael Rothd5f3c292011-07-19 14:50:35 -0500122 v->visitor.start_struct = qapi_dealloc_start_struct;
123 v->visitor.end_struct = qapi_dealloc_end_struct;
Eric Blakedbf11922016-02-17 23:48:29 -0700124 v->visitor.start_alternate = qapi_dealloc_start_alternate;
125 v->visitor.end_alternate = qapi_dealloc_end_alternate;
Michael Rothd5f3c292011-07-19 14:50:35 -0500126 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;
Eric Blake4c403142016-01-29 06:48:49 -0700129 v->visitor.type_int64 = qapi_dealloc_type_int64;
Eric Blakef755dea2016-01-29 06:48:50 -0700130 v->visitor.type_uint64 = qapi_dealloc_type_uint64;
Michael Rothd5f3c292011-07-19 14:50:35 -0500131 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;
Markus Armbruster28770e02015-09-16 13:06:24 +0200134 v->visitor.type_any = qapi_dealloc_type_anything;
Eric Blake3bc97fd2016-04-28 15:45:22 -0600135 v->visitor.type_null = qapi_dealloc_type_null;
Eric Blake2c0ef9f2016-06-09 10:48:35 -0600136 v->visitor.free = qapi_dealloc_free;
Michael Rothd5f3c292011-07-19 14:50:35 -0500137
Eric Blake2c0ef9f2016-06-09 10:48:35 -0600138 return &v->visitor;
Michael Rothd5f3c292011-07-19 14:50:35 -0500139}