blob: ef283f296601a20365e9fb80baa005c83a6e0933 [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"
Markus Armbruster15280c32018-02-01 12:18:36 +010017#include "qapi/qmp/qnull.h"
Paolo Bonzini7b1b5d12012-12-17 18:19:43 +010018#include "qapi/visitor-impl.h"
Michael Rothd5f3c292011-07-19 14:50:35 -050019
Michael Rothd5f3c292011-07-19 14:50:35 -050020struct QapiDeallocVisitor
21{
22 Visitor visitor;
Michael Rothd5f3c292011-07-19 14:50:35 -050023};
24
Markus Armbruster012d4c92020-07-07 18:05:45 +020025static bool qapi_dealloc_start_struct(Visitor *v, const char *name, void **obj,
Eric Blake337283d2016-01-29 06:48:57 -070026 size_t unused, Error **errp)
Michael Rothd5f3c292011-07-19 14:50:35 -050027{
Markus Armbruster012d4c92020-07-07 18:05:45 +020028 return true;
Michael Rothd5f3c292011-07-19 14:50:35 -050029}
30
Eric Blake1158bb22016-06-09 10:48:34 -060031static void qapi_dealloc_end_struct(Visitor *v, void **obj)
Michael Rothd5f3c292011-07-19 14:50:35 -050032{
Michael Rothd5f3c292011-07-19 14:50:35 -050033 if (obj) {
Anthony Liguori7267c092011-08-20 22:09:37 -050034 g_free(*obj);
Michael Rothd5f3c292011-07-19 14:50:35 -050035 }
36}
37
Eric Blake1158bb22016-06-09 10:48:34 -060038static void qapi_dealloc_end_alternate(Visitor *v, void **obj)
Wenchao Xia3dce9ca2013-11-06 02:35:50 +080039{
Wenchao Xia3dce9ca2013-11-06 02:35:50 +080040 if (obj) {
41 g_free(*obj);
42 }
43}
44
Markus Armbruster012d4c92020-07-07 18:05:45 +020045static bool qapi_dealloc_start_list(Visitor *v, const char *name,
Eric Blaked9f62dd2016-04-28 15:45:31 -060046 GenericList **list, size_t size,
47 Error **errp)
Michael Rothd5f3c292011-07-19 14:50:35 -050048{
Markus Armbruster012d4c92020-07-07 18:05:45 +020049 return true;
Michael Rothd5f3c292011-07-19 14:50:35 -050050}
51
Eric Blaked9f62dd2016-04-28 15:45:31 -060052static GenericList *qapi_dealloc_next_list(Visitor *v, GenericList *tail,
Eric Blakee65d89b2016-02-17 23:48:23 -070053 size_t size)
Michael Rothd5f3c292011-07-19 14:50:35 -050054{
Eric Blaked9f62dd2016-04-28 15:45:31 -060055 GenericList *next = tail->next;
56 g_free(tail);
57 return next;
Michael Rothd5f3c292011-07-19 14:50:35 -050058}
59
Eric Blake1158bb22016-06-09 10:48:34 -060060static void qapi_dealloc_end_list(Visitor *v, void **obj)
Michael Rothd5f3c292011-07-19 14:50:35 -050061{
62}
63
Markus Armbruster012d4c92020-07-07 18:05:45 +020064static bool qapi_dealloc_type_str(Visitor *v, const char *name, char **obj,
Michael Rothd5f3c292011-07-19 14:50:35 -050065 Error **errp)
66{
Peter Lievenb690d672014-05-08 18:03:15 +020067 if (obj) {
68 g_free(*obj);
69 }
Markus Armbruster012d4c92020-07-07 18:05:45 +020070 return true;
Michael Rothd5f3c292011-07-19 14:50:35 -050071}
72
Markus Armbruster012d4c92020-07-07 18:05:45 +020073static bool qapi_dealloc_type_int64(Visitor *v, const char *name, int64_t *obj,
Eric Blake4c403142016-01-29 06:48:49 -070074 Error **errp)
Michael Rothd5f3c292011-07-19 14:50:35 -050075{
Markus Armbruster012d4c92020-07-07 18:05:45 +020076 return true;
Michael Rothd5f3c292011-07-19 14:50:35 -050077}
78
Markus Armbruster012d4c92020-07-07 18:05:45 +020079static bool qapi_dealloc_type_uint64(Visitor *v, const char *name,
Eric Blake0b2a0d62016-01-29 06:48:56 -070080 uint64_t *obj, Error **errp)
Eric Blakef755dea2016-01-29 06:48:50 -070081{
Markus Armbruster012d4c92020-07-07 18:05:45 +020082 return true;
Eric Blakef755dea2016-01-29 06:48:50 -070083}
84
Markus Armbruster012d4c92020-07-07 18:05:45 +020085static bool qapi_dealloc_type_bool(Visitor *v, const char *name, bool *obj,
Michael Rothd5f3c292011-07-19 14:50:35 -050086 Error **errp)
87{
Markus Armbruster012d4c92020-07-07 18:05:45 +020088 return true;
Michael Rothd5f3c292011-07-19 14:50:35 -050089}
90
Markus Armbruster012d4c92020-07-07 18:05:45 +020091static bool qapi_dealloc_type_number(Visitor *v, const char *name, double *obj,
Michael Rothd5f3c292011-07-19 14:50:35 -050092 Error **errp)
93{
Markus Armbruster012d4c92020-07-07 18:05:45 +020094 return true;
Michael Rothd5f3c292011-07-19 14:50:35 -050095}
96
Markus Armbruster012d4c92020-07-07 18:05:45 +020097static bool qapi_dealloc_type_anything(Visitor *v, const char *name,
Eric Blake0b2a0d62016-01-29 06:48:56 -070098 QObject **obj, Error **errp)
Markus Armbruster28770e02015-09-16 13:06:24 +020099{
100 if (obj) {
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200101 qobject_unref(*obj);
Markus Armbruster28770e02015-09-16 13:06:24 +0200102 }
Markus Armbruster012d4c92020-07-07 18:05:45 +0200103 return true;
Markus Armbruster28770e02015-09-16 13:06:24 +0200104}
105
Markus Armbruster012d4c92020-07-07 18:05:45 +0200106static bool qapi_dealloc_type_null(Visitor *v, const char *name,
Markus Armbrusterd2f95f42017-06-26 18:22:59 +0200107 QNull **obj, Error **errp)
Eric Blake3bc97fd2016-04-28 15:45:22 -0600108{
Markus Armbrusterd2f95f42017-06-26 18:22:59 +0200109 if (obj) {
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200110 qobject_unref(*obj);
Markus Armbrusterd2f95f42017-06-26 18:22:59 +0200111 }
Markus Armbruster012d4c92020-07-07 18:05:45 +0200112 return true;
Eric Blake3bc97fd2016-04-28 15:45:22 -0600113}
114
Eric Blake2c0ef9f2016-06-09 10:48:35 -0600115static void qapi_dealloc_free(Visitor *v)
Michael Rothd5f3c292011-07-19 14:50:35 -0500116{
Eric Blake2c0ef9f2016-06-09 10:48:35 -0600117 g_free(container_of(v, QapiDeallocVisitor, visitor));
Michael Rothd5f3c292011-07-19 14:50:35 -0500118}
119
Eric Blake2c0ef9f2016-06-09 10:48:35 -0600120Visitor *qapi_dealloc_visitor_new(void)
Michael Rothd5f3c292011-07-19 14:50:35 -0500121{
122 QapiDeallocVisitor *v;
123
Anthony Liguori7267c092011-08-20 22:09:37 -0500124 v = g_malloc0(sizeof(*v));
Michael Rothd5f3c292011-07-19 14:50:35 -0500125
Eric Blake983f52d2016-04-28 15:45:09 -0600126 v->visitor.type = VISITOR_DEALLOC;
Michael Rothd5f3c292011-07-19 14:50:35 -0500127 v->visitor.start_struct = qapi_dealloc_start_struct;
128 v->visitor.end_struct = qapi_dealloc_end_struct;
Eric Blakedbf11922016-02-17 23:48:29 -0700129 v->visitor.end_alternate = qapi_dealloc_end_alternate;
Michael Rothd5f3c292011-07-19 14:50:35 -0500130 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;
Eric Blake4c403142016-01-29 06:48:49 -0700133 v->visitor.type_int64 = qapi_dealloc_type_int64;
Eric Blakef755dea2016-01-29 06:48:50 -0700134 v->visitor.type_uint64 = qapi_dealloc_type_uint64;
Michael Rothd5f3c292011-07-19 14:50:35 -0500135 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;
Markus Armbruster28770e02015-09-16 13:06:24 +0200138 v->visitor.type_any = qapi_dealloc_type_anything;
Eric Blake3bc97fd2016-04-28 15:45:22 -0600139 v->visitor.type_null = qapi_dealloc_type_null;
Eric Blake2c0ef9f2016-06-09 10:48:35 -0600140 v->visitor.free = qapi_dealloc_free;
Michael Rothd5f3c292011-07-19 14:50:35 -0500141
Eric Blake2c0ef9f2016-06-09 10:48:35 -0600142 return &v->visitor;
Michael Rothd5f3c292011-07-19 14:50:35 -0500143}