qapi-dealloc-visitor.c 3.6 KB

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