diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2018-06-22 17:08:57 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2018-06-22 17:08:58 +0100 |
commit | 7ed14cbf3cf083f125c079bd02b3215941853830 (patch) | |
tree | a845e5314ea1b5af5aa4a4b9c9af7d9c2aa9605c /scripts | |
parent | 5fce31220003bbe1b4c7faa0dbf92d131b0a413b (diff) | |
parent | be25fcc4d2faeb3ffa8db813272963bae659c4c2 (diff) |
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2018-06-22' into staging
QAPI patches for 2018-06-22
# gpg: Signature made Fri 22 Jun 2018 15:36:22 BST
# gpg: using RSA key 3870B400EB918653
# gpg: Good signature from "Markus Armbruster <armbru@redhat.com>"
# gpg: aka "Markus Armbruster <armbru@pond.sub.org>"
# Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653
* remotes/armbru/tags/pull-qapi-2018-06-22:
MAINTAINERS: Update QAPI stanza for commit fb0bc835e56
qapi/introspect: Eliminate pointless variable in .visit_end()
Revert commit d4e5ec877ca
qapi: Open files with encoding='utf-8'
qapi: remove empty flat union branches and types
qapi: allow empty branches in flat unions
tests: Add QDict clone-flatten test
qdict: Make qdict_flatten() shallow-clone-friendly
qapi/events: generate event enum in main module
qapi/visit: remove useless prefix argument
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/qapi/common.py | 32 | ||||
-rw-r--r-- | scripts/qapi/events.py | 5 | ||||
-rw-r--r-- | scripts/qapi/introspect.py | 5 | ||||
-rw-r--r-- | scripts/qapi/types.py | 2 | ||||
-rw-r--r-- | scripts/qapi/visit.py | 21 |
5 files changed, 43 insertions, 22 deletions
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 2462fc0291..8b6708dbf1 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -16,6 +16,7 @@ import errno import os import re import string +import sys from collections import OrderedDict builtin_types = { @@ -340,7 +341,10 @@ class QAPISchemaParser(object): return None try: - fobj = open(incl_fname, 'r') + if sys.version_info[0] >= 3: + fobj = open(incl_fname, 'r', encoding='utf-8') + else: + fobj = open(incl_fname, 'r') except IOError as e: raise QAPISemError(info, '%s: %s' % (e.strerror, incl_fname)) return QAPISchemaParser(fobj, previously_included, info) @@ -779,13 +783,6 @@ def check_union(expr, info): "enum '%s'" % (key, enum_define['enum'])) - # If discriminator is user-defined, ensure all values are covered - if enum_define: - for value in enum_define['data']: - if value not in members.keys(): - raise QAPISemError(info, "Union '%s' data missing '%s' branch" - % (name, value)) - def check_alternate(expr, info): name = expr['alternate'] @@ -1357,6 +1354,14 @@ class QAPISchemaObjectTypeVariants(object): self.tag_member = seen[c_name(self._tag_name)] assert self._tag_name == self.tag_member.name assert isinstance(self.tag_member.type, QAPISchemaEnumType) + if self._tag_name: # flat union + # branches that are not explicitly covered get an empty type + cases = set([v.name for v in self.variants]) + for val in self.tag_member.type.values: + if val.name not in cases: + v = QAPISchemaObjectTypeVariant(val.name, 'q_empty') + v.set_owner(self.tag_member.owner) + self.variants.append(v) for v in self.variants: v.check(schema) # Union names must match enum values; alternate names are @@ -1492,7 +1497,11 @@ class QAPISchemaEvent(QAPISchemaEntity): class QAPISchema(object): def __init__(self, fname): self._fname = fname - parser = QAPISchemaParser(open(fname, 'r')) + if sys.version_info[0] >= 3: + f = open(fname, 'r', encoding='utf-8') + else: + f = open(fname, 'r') + parser = QAPISchemaParser(f) exprs = check_exprs(parser.exprs) self.docs = parser.docs self._entity_list = [] @@ -2006,7 +2015,10 @@ class QAPIGen(object): if e.errno != errno.EEXIST: raise fd = os.open(pathname, os.O_RDWR | os.O_CREAT, 0o666) - f = os.fdopen(fd, 'r+') + if sys.version_info[0] >= 3: + f = open(fd, 'r+', encoding='utf-8') + else: + f = os.fdopen(fd, 'r+') text = (self._top(fname) + self._preamble + self._body + self._bottom(fname)) oldtext = f.read(len(text) + 1) diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 4426861ff1..5657524688 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -180,8 +180,9 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisitor): types=types)) def visit_end(self): - self._genh.add(gen_enum(self._enum_name, self._event_names)) - self._genc.add(gen_enum_lookup(self._enum_name, self._event_names)) + (genc, genh) = self._module[self._main_module] + genh.add(gen_enum(self._enum_name, self._event_names)) + genc.add(gen_enum_lookup(self._enum_name, self._event_names)) def visit_event(self, name, info, arg_type, boxed): self._genh.add(gen_event_send_decl(name, arg_type, boxed)) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 5b6c72c7b2..6ad198ae5b 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -75,13 +75,10 @@ class QAPISchemaGenIntrospectVisitor(QAPISchemaMonolithicCVisitor): def visit_end(self): # visit the types that are actually used - qlits = self._qlits - self._qlits = [] for typ in self._used_types: typ.visit(self) # generate C # TODO can generate awfully long lines - qlits.extend(self._qlits) name = c_name(self._prefix, protect=False) + 'qmp_schema_qlit' self._genh.add(mcgen(''' #include "qapi/qmp/qlit.h" @@ -93,7 +90,7 @@ extern const QLitObject %(c_name)s; const QLitObject %(c_name)s = %(c_string)s; ''', c_name=c_name(name), - c_string=to_qlit(qlits))) + c_string=to_qlit(self._qlits))) self._schema = None self._qlits = [] self._used_types = [] diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index 64d9c0fb37..a599352e59 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -125,6 +125,8 @@ def gen_variants(variants): c_name=c_name(variants.tag_member.name)) for var in variants.variants: + if var.type.name == 'q_empty': + continue ret += mcgen(''' %(c_type)s %(c_name)s; ''', diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 5d72d8936c..bdcafb64ee 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -81,15 +81,24 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp) c_name=c_name(variants.tag_member.name)) for var in variants.variants: - ret += mcgen(''' + case_str = c_enum_const(variants.tag_member.type.name, + var.name, + variants.tag_member.type.prefix) + if var.type.name == 'q_empty': + # valid variant and nothing to do + ret += mcgen(''' + case %(case)s: + break; +''', + case=case_str) + else: + ret += mcgen(''' case %(case)s: visit_type_%(c_type)s_members(v, &obj->u.%(c_name)s, &err); break; ''', - case=c_enum_const(variants.tag_member.type.name, - var.name, - variants.tag_member.type.prefix), - c_type=var.type.c_name(), c_name=c_name(var.name)) + case=case_str, + c_type=var.type.c_name(), c_name=c_name(var.name)) ret += mcgen(''' default: @@ -293,7 +302,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisitor): #include "qapi/qmp/qerror.h" #include "%(visit)s.h" ''', - visit=visit, prefix=self._prefix)) + visit=visit)) self._genh.preamble_add(mcgen(''' #include "qapi/qapi-builtin-visit.h" #include "%(types)s.h" |