cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
218e99
From 19832bf960bb31814a0d950b01fff45e2618be27 Mon Sep 17 00:00:00 2001
218e99
From: Amos Kong <akong@redhat.com>
218e99
Date: Fri, 8 Nov 2013 06:13:57 +0100
218e99
Subject: [PATCH 2/4] qapi: qapi-visit.py, native list support
218e99
218e99
RH-Author: Amos Kong <akong@redhat.com>
218e99
Message-id: <1383891239-29531-3-git-send-email-akong@redhat.com>
218e99
Patchwork-id: 55609
218e99
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 2/4] qapi: qapi-visit.py, native list support
218e99
Bugzilla: 848203
218e99
RH-Acked-by: Vlad Yasevich <vyasevic@redhat.com>
218e99
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
218e99
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
218e99
218e99
From: Michael Roth <mdroth@linux.vnet.ibm.com>
218e99
218e99
Teach visitor generators about native types so they can generate the
218e99
appropriate visitor routines.
218e99
218e99
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
218e99
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
218e99
Reviewed-by: Amos Kong <akong@redhat.com>
218e99
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
218e99
(cherry picked from commit 7c946bc418db6b2a11f89b3465424fef48f714eb)
218e99
---
218e99
 scripts/qapi-visit.py |   34 +++++++++++++++++++++++++++++-----
218e99
 1 files changed, 29 insertions(+), 5 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 scripts/qapi-visit.py |   34 +++++++++++++++++++++++++++++-----
218e99
 1 files changed, 29 insertions(+), 5 deletions(-)
218e99
218e99
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
218e99
index fc2b67a..c39e628 100644
218e99
--- a/scripts/qapi-visit.py
218e99
+++ b/scripts/qapi-visit.py
218e99
@@ -337,12 +337,14 @@ void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **
218e99
 
218e99
     return ret
218e99
 
218e99
-def generate_declaration(name, members, genlist=True):
218e99
-    ret = mcgen('''
218e99
+def generate_declaration(name, members, genlist=True, builtin_type=False):
218e99
+    ret = ""
218e99
+    if not builtin_type:
218e99
+        ret += mcgen('''
218e99
 
218e99
 void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp);
218e99
 ''',
218e99
-                name=name)
218e99
+                    name=name)
218e99
 
218e99
     if genlist:
218e99
         ret += mcgen('''
218e99
@@ -370,8 +372,9 @@ void visit_type_%(name)s(Visitor *m, %(name)s * obj, const char *name, Error **e
218e99
                 name=name)
218e99
 
218e99
 try:
218e99
-    opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:o:",
218e99
-                                   ["source", "header", "prefix=", "output-dir="])
218e99
+    opts, args = getopt.gnu_getopt(sys.argv[1:], "chbp:o:",
218e99
+                                   ["source", "header", "builtins", "prefix=",
218e99
+                                    "output-dir="])
218e99
 except getopt.GetoptError, err:
218e99
     print str(err)
218e99
     sys.exit(1)
218e99
@@ -383,6 +386,7 @@ h_file = 'qapi-visit.h'
218e99
 
218e99
 do_c = False
218e99
 do_h = False
218e99
+do_builtins = False
218e99
 
218e99
 for o, a in opts:
218e99
     if o in ("-p", "--prefix"):
218e99
@@ -393,6 +397,8 @@ for o, a in opts:
218e99
         do_c = True
218e99
     elif o in ("-h", "--header"):
218e99
         do_h = True
218e99
+    elif o in ("-b", "--builtins"):
218e99
+        do_builtins = True
218e99
 
218e99
 if not do_c and not do_h:
218e99
     do_c = True
218e99
@@ -459,11 +465,29 @@ fdecl.write(mcgen('''
218e99
 
218e99
 #include "qapi/visitor.h"
218e99
 #include "%(prefix)sqapi-types.h"
218e99
+
218e99
 ''',
218e99
                   prefix=prefix, guard=guardname(h_file)))
218e99
 
218e99
 exprs = parse_schema(sys.stdin)
218e99
 
218e99
+# to avoid header dependency hell, we always generate declarations
218e99
+# for built-in types in our header files and simply guard them
218e99
+fdecl.write(guardstart("QAPI_VISIT_BUILTIN_VISITOR_DECL"))
218e99
+for typename in builtin_types:
218e99
+    fdecl.write(generate_declaration(typename, None, genlist=True,
218e99
+                                     builtin_type=True))
218e99
+fdecl.write(guardend("QAPI_VISIT_BUILTIN_VISITOR_DECL"))
218e99
+
218e99
+# ...this doesn't work for cases where we link in multiple objects that
218e99
+# have the functions defined, so we use -b option to provide control
218e99
+# over these cases
218e99
+if do_builtins:
218e99
+    fdef.write(guardstart("QAPI_VISIT_BUILTIN_VISITOR_DEF"))
218e99
+    for typename in builtin_types:
218e99
+        fdef.write(generate_visit_list(typename, None))
218e99
+    fdef.write(guardend("QAPI_VISIT_BUILTIN_VISITOR_DEF"))
218e99
+
218e99
 for expr in exprs:
218e99
     if expr.has_key('type'):
218e99
         ret = generate_visit_struct(expr)
218e99
-- 
218e99
1.7.1
218e99