Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Dealloc Visitor |
| 3 | * |
Eric Blake | 08f9541 | 2016-01-29 06:48:59 -0700 | [diff] [blame] | 4 | * Copyright (C) 2012-2016 Red Hat, Inc. |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 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 | |
Peter Maydell | cbf2115 | 2016-01-29 17:49:57 +0000 | [diff] [blame] | 15 | #include "qemu/osdep.h" |
Paolo Bonzini | 7b1b5d1 | 2012-12-17 18:19:43 +0100 | [diff] [blame] | 16 | #include "qapi/dealloc-visitor.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 17 | #include "qemu/queue.h" |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 18 | #include "qemu-common.h" |
Paolo Bonzini | 7b1b5d1 | 2012-12-17 18:19:43 +0100 | [diff] [blame] | 19 | #include "qapi/qmp/types.h" |
| 20 | #include "qapi/visitor-impl.h" |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 21 | |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 22 | struct QapiDeallocVisitor |
| 23 | { |
| 24 | Visitor visitor; |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 25 | }; |
| 26 | |
Eric Blake | 0b2a0d6 | 2016-01-29 06:48:56 -0700 | [diff] [blame] | 27 | static void qapi_dealloc_start_struct(Visitor *v, const char *name, void **obj, |
Eric Blake | 337283d | 2016-01-29 06:48:57 -0700 | [diff] [blame] | 28 | size_t unused, Error **errp) |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 29 | { |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 30 | } |
| 31 | |
Eric Blake | 1158bb2 | 2016-06-09 10:48:34 -0600 | [diff] [blame] | 32 | static void qapi_dealloc_end_struct(Visitor *v, void **obj) |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 33 | { |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 34 | if (obj) { |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 35 | g_free(*obj); |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 36 | } |
| 37 | } |
| 38 | |
Eric Blake | dbf1192 | 2016-02-17 23:48:29 -0700 | [diff] [blame] | 39 | static void qapi_dealloc_start_alternate(Visitor *v, const char *name, |
| 40 | GenericAlternate **obj, size_t size, |
Marc-André Lureau | 60390d2 | 2017-06-07 20:35:59 +0400 | [diff] [blame] | 41 | Error **errp) |
Wenchao Xia | 3dce9ca | 2013-11-06 02:35:50 +0800 | [diff] [blame] | 42 | { |
Wenchao Xia | 3dce9ca | 2013-11-06 02:35:50 +0800 | [diff] [blame] | 43 | } |
| 44 | |
Eric Blake | 1158bb2 | 2016-06-09 10:48:34 -0600 | [diff] [blame] | 45 | static void qapi_dealloc_end_alternate(Visitor *v, void **obj) |
Wenchao Xia | 3dce9ca | 2013-11-06 02:35:50 +0800 | [diff] [blame] | 46 | { |
Wenchao Xia | 3dce9ca | 2013-11-06 02:35:50 +0800 | [diff] [blame] | 47 | if (obj) { |
| 48 | g_free(*obj); |
| 49 | } |
| 50 | } |
| 51 | |
Eric Blake | d9f62dd | 2016-04-28 15:45:31 -0600 | [diff] [blame] | 52 | static void qapi_dealloc_start_list(Visitor *v, const char *name, |
| 53 | GenericList **list, size_t size, |
| 54 | Error **errp) |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 55 | { |
| 56 | } |
| 57 | |
Eric Blake | d9f62dd | 2016-04-28 15:45:31 -0600 | [diff] [blame] | 58 | static GenericList *qapi_dealloc_next_list(Visitor *v, GenericList *tail, |
Eric Blake | e65d89b | 2016-02-17 23:48:23 -0700 | [diff] [blame] | 59 | size_t size) |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 60 | { |
Eric Blake | d9f62dd | 2016-04-28 15:45:31 -0600 | [diff] [blame] | 61 | GenericList *next = tail->next; |
| 62 | g_free(tail); |
| 63 | return next; |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 64 | } |
| 65 | |
Eric Blake | 1158bb2 | 2016-06-09 10:48:34 -0600 | [diff] [blame] | 66 | static void qapi_dealloc_end_list(Visitor *v, void **obj) |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 67 | { |
| 68 | } |
| 69 | |
Eric Blake | 0b2a0d6 | 2016-01-29 06:48:56 -0700 | [diff] [blame] | 70 | static void qapi_dealloc_type_str(Visitor *v, const char *name, char **obj, |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 71 | Error **errp) |
| 72 | { |
Peter Lieven | b690d67 | 2014-05-08 18:03:15 +0200 | [diff] [blame] | 73 | if (obj) { |
| 74 | g_free(*obj); |
| 75 | } |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 76 | } |
| 77 | |
Eric Blake | 0b2a0d6 | 2016-01-29 06:48:56 -0700 | [diff] [blame] | 78 | static void qapi_dealloc_type_int64(Visitor *v, const char *name, int64_t *obj, |
Eric Blake | 4c40314 | 2016-01-29 06:48:49 -0700 | [diff] [blame] | 79 | Error **errp) |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 80 | { |
| 81 | } |
| 82 | |
Eric Blake | 0b2a0d6 | 2016-01-29 06:48:56 -0700 | [diff] [blame] | 83 | static void qapi_dealloc_type_uint64(Visitor *v, const char *name, |
| 84 | uint64_t *obj, Error **errp) |
Eric Blake | f755dea | 2016-01-29 06:48:50 -0700 | [diff] [blame] | 85 | { |
| 86 | } |
| 87 | |
Eric Blake | 0b2a0d6 | 2016-01-29 06:48:56 -0700 | [diff] [blame] | 88 | static void qapi_dealloc_type_bool(Visitor *v, const char *name, bool *obj, |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 89 | Error **errp) |
| 90 | { |
| 91 | } |
| 92 | |
Eric Blake | 0b2a0d6 | 2016-01-29 06:48:56 -0700 | [diff] [blame] | 93 | static void qapi_dealloc_type_number(Visitor *v, const char *name, double *obj, |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 94 | Error **errp) |
| 95 | { |
| 96 | } |
| 97 | |
Eric Blake | 0b2a0d6 | 2016-01-29 06:48:56 -0700 | [diff] [blame] | 98 | static void qapi_dealloc_type_anything(Visitor *v, const char *name, |
| 99 | QObject **obj, Error **errp) |
Markus Armbruster | 28770e0 | 2015-09-16 13:06:24 +0200 | [diff] [blame] | 100 | { |
| 101 | if (obj) { |
| 102 | qobject_decref(*obj); |
| 103 | } |
| 104 | } |
| 105 | |
Eric Blake | 3bc97fd | 2016-04-28 15:45:22 -0600 | [diff] [blame] | 106 | static void qapi_dealloc_type_null(Visitor *v, const char *name, Error **errp) |
| 107 | { |
| 108 | } |
| 109 | |
Eric Blake | 2c0ef9f | 2016-06-09 10:48:35 -0600 | [diff] [blame] | 110 | static void qapi_dealloc_free(Visitor *v) |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 111 | { |
Eric Blake | 2c0ef9f | 2016-06-09 10:48:35 -0600 | [diff] [blame] | 112 | g_free(container_of(v, QapiDeallocVisitor, visitor)); |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 113 | } |
| 114 | |
Eric Blake | 2c0ef9f | 2016-06-09 10:48:35 -0600 | [diff] [blame] | 115 | Visitor *qapi_dealloc_visitor_new(void) |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 116 | { |
| 117 | QapiDeallocVisitor *v; |
| 118 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 119 | v = g_malloc0(sizeof(*v)); |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 120 | |
Eric Blake | 983f52d | 2016-04-28 15:45:09 -0600 | [diff] [blame] | 121 | v->visitor.type = VISITOR_DEALLOC; |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 122 | v->visitor.start_struct = qapi_dealloc_start_struct; |
| 123 | v->visitor.end_struct = qapi_dealloc_end_struct; |
Eric Blake | dbf1192 | 2016-02-17 23:48:29 -0700 | [diff] [blame] | 124 | v->visitor.start_alternate = qapi_dealloc_start_alternate; |
| 125 | v->visitor.end_alternate = qapi_dealloc_end_alternate; |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 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; |
Eric Blake | 4c40314 | 2016-01-29 06:48:49 -0700 | [diff] [blame] | 129 | v->visitor.type_int64 = qapi_dealloc_type_int64; |
Eric Blake | f755dea | 2016-01-29 06:48:50 -0700 | [diff] [blame] | 130 | v->visitor.type_uint64 = qapi_dealloc_type_uint64; |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 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; |
Markus Armbruster | 28770e0 | 2015-09-16 13:06:24 +0200 | [diff] [blame] | 134 | v->visitor.type_any = qapi_dealloc_type_anything; |
Eric Blake | 3bc97fd | 2016-04-28 15:45:22 -0600 | [diff] [blame] | 135 | v->visitor.type_null = qapi_dealloc_type_null; |
Eric Blake | 2c0ef9f | 2016-06-09 10:48:35 -0600 | [diff] [blame] | 136 | v->visitor.free = qapi_dealloc_free; |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 137 | |
Eric Blake | 2c0ef9f | 2016-06-09 10:48:35 -0600 | [diff] [blame] | 138 | return &v->visitor; |
Michael Roth | d5f3c29 | 2011-07-19 14:50:35 -0500 | [diff] [blame] | 139 | } |