qapi-dealloc-visitor.c 3.3 KB

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