All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: "Kővágó, Zoltán" <dirty.ice.hu@gmail.com>
To: qemu-devel@nongnu.org
Cc: Michael Roth <mdroth@linux.vnet.ibm.com>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Markus Armbruster <armbru@redhat.com>
Subject: [Qemu-devel] [PATCH v2 4/6] qapi: AllocVisitor
Date: Tue, 16 Jun 2015 14:49:07 +0200	[thread overview]
Message-ID: <fe9bed0d895eaceef6b4c26e4654345e315c800a.1434458391.git.DirtY.iCE.hu@gmail.com> (raw)
In-Reply-To: <cover.1434458391.git.DirtY.iCE.hu@gmail.com>

Simple visitor that recursively allocates structures with only optional
variables. Unions are initialized to the first type specified. Other non
optional types are not supported.

Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com>
---
 include/qapi/alloc-visitor.h | 18 +++++++++++++
 qapi/Makefile.objs           |  1 +
 qapi/alloc-visitor.c         | 62 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 81 insertions(+)
 create mode 100644 include/qapi/alloc-visitor.h
 create mode 100644 qapi/alloc-visitor.c

diff --git a/include/qapi/alloc-visitor.h b/include/qapi/alloc-visitor.h
new file mode 100644
index 0000000..3d54295
--- /dev/null
+++ b/include/qapi/alloc-visitor.h
@@ -0,0 +1,18 @@
+/*
+ * Alloc Visitor.
+ * Recursively allocates structs, leaving all optional fields unset. In case of
+ * a non-optional field it fails.
+ */
+
+#ifndef ALLOC_VISITOR_H
+#define ALLOC_VISITOR_H
+
+#include "qapi/visitor.h"
+
+typedef struct AllocVisitor AllocVisitor;
+
+AllocVisitor *alloc_visitor_new(void);
+void alloc_visitor_cleanup(AllocVisitor *v);
+Visitor *alloc_visitor_get_visitor(AllocVisitor *v);
+
+#endif
diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs
index 2278970..7bc26a3 100644
--- a/qapi/Makefile.objs
+++ b/qapi/Makefile.objs
@@ -4,3 +4,4 @@ util-obj-y += string-input-visitor.o string-output-visitor.o
 util-obj-y += opts-visitor.o
 util-obj-y += qmp-event.o
 util-obj-y += qapi-util.o
+util-obj-y += alloc-visitor.o
diff --git a/qapi/alloc-visitor.c b/qapi/alloc-visitor.c
new file mode 100644
index 0000000..dbb83af
--- /dev/null
+++ b/qapi/alloc-visitor.c
@@ -0,0 +1,62 @@
+#include "qapi/alloc-visitor.h"
+#include "qemu-common.h"
+#include "qapi/visitor-impl.h"
+
+struct AllocVisitor {
+    Visitor visitor;
+};
+
+static void alloc_start_struct(Visitor *v, void **obj, const char* kind,
+                               const char *name, size_t size, Error **errp)
+{
+    if (obj) {
+        *obj = g_malloc0(size);
+    }
+}
+
+static void alloc_end_struct(Visitor *v, Error **errp)
+{
+}
+
+static void alloc_start_implicit_struct(Visitor *v, void **obj, size_t size,
+                                        Error **errp)
+{
+    if (obj) {
+        *obj = g_malloc0(size);
+    }
+}
+
+static void alloc_end_implicit_struct(Visitor *v, Error **errp)
+{
+}
+
+static void alloc_type_enum(Visitor *v, int *obj, const char *strings[],
+                            const char *kind, const char *name, Error **errp)
+{
+    assert(*strings); /* there is at least one valid enum value... */
+    *obj = 0;
+}
+
+AllocVisitor *alloc_visitor_new(void)
+{
+    AllocVisitor *v = g_malloc0(sizeof(AllocVisitor));
+
+    v->visitor.start_struct = alloc_start_struct;
+    v->visitor.end_struct = alloc_end_struct;
+    v->visitor.start_implicit_struct = alloc_start_implicit_struct;
+    v->visitor.end_implicit_struct = alloc_end_implicit_struct;
+
+    v->visitor.type_enum = alloc_type_enum;
+
+    return v;
+}
+
+void alloc_visitor_cleanup(AllocVisitor *v)
+{
+    g_free(v);
+}
+
+Visitor *alloc_visitor_get_visitor(AllocVisitor *v)
+{
+    return &v->visitor;
+}
-- 
2.4.3

  parent reply	other threads:[~2015-06-16 12:49 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-16 12:49 [Qemu-devel] [PATCH v2 0/6] -audiodev option Kővágó, Zoltán
2015-06-16 12:49 ` [Qemu-devel] [PATCH v2 1/6] qapi: qapi for audio backends Kővágó, Zoltán
2015-06-17  7:46   ` Markus Armbruster
2015-06-17 10:54     ` Kővágó Zoltán
2015-06-17 11:48       ` Markus Armbruster
2015-06-17 12:07         ` Kővágó Zoltán
2015-06-17 13:37           ` Markus Armbruster
2015-06-17 13:53             ` Kővágó Zoltán
2015-06-17 16:06               ` Markus Armbruster
2015-06-18  0:21                 ` Kővágó Zoltán
2015-06-18  8:51                   ` Markus Armbruster
2015-06-17 15:50         ` Eric Blake
2015-06-16 12:49 ` [Qemu-devel] [PATCH v2 2/6] qapi: support nested structs in OptsVisitor Kővágó, Zoltán
2015-06-17  7:50   ` Markus Armbruster
2015-06-17  8:41     ` Gerd Hoffmann
2015-06-17 11:01       ` Kővágó Zoltán
2015-06-17 11:50         ` Markus Armbruster
2015-06-17 15:47         ` Eric Blake
2015-06-17 11:18       ` Markus Armbruster
2015-06-17 12:11         ` Kővágó Zoltán
2015-06-17 13:41           ` Markus Armbruster
2015-06-17 14:02             ` Kővágó Zoltán
2015-06-17 16:10               ` Markus Armbruster
2015-06-16 12:49 ` [Qemu-devel] [PATCH v2 3/6] opts: do not print separator before first item in qemu_opts_print Kővágó, Zoltán
2015-06-17  7:53   ` Markus Armbruster
2015-06-17  9:02   ` Kevin Wolf
2015-06-16 12:49 ` Kővágó, Zoltán [this message]
2015-06-17  7:56   ` [Qemu-devel] [PATCH v2 4/6] qapi: AllocVisitor Markus Armbruster
2015-06-17 12:01     ` Kővágó Zoltán
2015-06-17 13:42       ` Markus Armbruster
2015-06-16 12:49 ` [Qemu-devel] [PATCH v2 5/6] audio: use qapi AudioFormat instead of audfmt_e Kővágó, Zoltán
2015-06-17  8:01   ` Markus Armbruster
2015-06-17 11:05     ` Kővágó Zoltán
2015-06-17 11:51       ` Markus Armbruster
2015-06-17 16:01         ` Eric Blake
2015-06-16 12:49 ` [Qemu-devel] [PATCH v2 6/6] audio: -audiodev command line option Kővágó, Zoltán
2015-06-17  8:13   ` Markus Armbruster
2015-06-17 11:18     ` Kővágó Zoltán
2015-06-17 12:27       ` Markus Armbruster
2015-06-17 13:25         ` Kővágó Zoltán
2015-06-17 16:13           ` Markus Armbruster
2015-06-18  6:54             ` Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fe9bed0d895eaceef6b4c26e4654345e315c800a.1434458391.git.DirtY.iCE.hu@gmail.com \
    --to=dirty.ice.hu@gmail.com \
    --cc=armbru@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.