QAPI patches
Subsystems (3)
[Qemu-devel] [PULL v2 03/25] qapi: More idiomatic string operations
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
Rather than slicing the end of a string, we can use python's endswith(). And rather than creating a set of characters, we can search for a character within a string.
Message-Id: <[email protected]>
--- scripts/qapi.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
scripts/qapi.py +3 -3
@@ -172,7 +172,7 @@ class QAPISchemaParser(object): if self.tok == '#': self.cursor = self.src.find('\n', self.cursor) - elif self.tok in ['{', '}', ':', ',', '[', ']']: + elif self.tok in "{}:,[]": return elif self.tok == "'": string = ''
@@ -390,7 +390,7 @@ def add_name(name, info, meta, implicit=False): raise QAPIExprError(info, "%s '%s' is already defined" % (all_names[name], name)) - if not implicit and name[-4:] == 'Kind': + if not implicit and name.endswith('Kind'): raise QAPIExprError(info, "%s '%s' should not end in 'Kind'" % (meta, name))
@@ -910,7 +910,7 @@ class QAPISchemaEnumType(QAPISchemaType): def is_implicit(self): # See QAPISchema._make_implicit_enum_type() - return self.name[-4:] == 'Kind' + return self.name.endswith('Kind') def c_type(self, is_param=False): return c_name(self.name)
Signature · 1 line
2.4.3
[Qemu-devel] [PULL v2 04/25] qapi: More robust conditions for when labels are needed
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
We were using regular expressions to see if ret included any earlier text that emitted a 'goto out;' line, to decide whether we needed to output an 'out:' label. But this is fragile, if the ret text can possibly combine more than one generated function body, where the first function used a goto but the second does not. Change the code to just check for the known conditions which cause an error check to be needed. Besides, it's slightly more efficient to use plain checks than regular expression searching.
No change to generated code.
Message-Id: <[email protected]>
--- scripts/qapi-commands.py | 4 +++- scripts/qapi-visit.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-)
scripts/qapi-commands.py +3 -1
@@ -175,7 +175,9 @@ def gen_marshal(name, arg_type, ret_type): ret += gen_marshal_input_visit(arg_type) ret += gen_call(name, arg_type, ret_type) - if re.search('^ *goto out;', ret, re.MULTILINE): + # 'goto out' produced by gen_marshal_input_visit->gen_visit_fields() + # for each arg_type member, and by gen_call() for ret_type + if (arg_type and arg_type.members) or ret_type: ret += mcgen(''' out:
scripts/qapi-visit.py +2 -1
@@ -87,7 +87,8 @@ static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s **obj, Error **e ret += gen_visit_fields(members, prefix='(*obj)->') - if re.search('^ *goto out;', ret, re.MULTILINE): + # 'goto out' produced for base, and by gen_visit_fields() for each member + if base or members: ret += mcgen(''' out:
Signature · 1 line
2.4.3
[Qemu-devel] [PULL v2 09/25] qapi-types: Refactor base fields output
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
Move code from gen_union() into gen_struct_fields() in order for a later patch to share code when enumerating inherited fields for struct types.
No change to generated code.
Message-Id: <[email protected]>
--- scripts/qapi-types.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
scripts/qapi-types.py +14 -10
@@ -51,10 +51,21 @@ def gen_struct_field(name, typ, optional): return ret -def gen_struct_fields(members): +def gen_struct_fields(local_members, base=None): ret = '' - for memb in members: + if base: + ret += mcgen(''' + /* Members inherited from %(c_name)s: */ +''', + c_name=base.c_name()) + for memb in base.members: + ret += gen_struct_field(memb.name, memb.type, memb.optional) + ret += mcgen(''' + /* Own members: */ +''') + + for memb in local_members: ret += gen_struct_field(memb.name, memb.type, memb.optional) return ret
@@ -126,14 +137,7 @@ struct %(c_name)s { ''', c_name=c_name(name)) if base: - ret += mcgen(''' - /* Members inherited from %(c_name)s: */ -''', - c_name=c_name(base.name)) - ret += gen_struct_fields(base.members) - ret += mcgen(''' - /* Own members: */ -''') + ret += gen_struct_fields([], base) else: ret += mcgen(''' %(c_type)s kind;
Signature · 1 line
2.4.3
[Qemu-devel] [PULL v2 01/25] qapi-schema: mark InetSocketAddress as mandatory again
In reply to Markus ArmbrusterFrom: "Daniel P. Berrange" <[email protected]>
Revert the qapi-schema.json change done in:
commit 0983f5e6af76d5df8c6346cbdfff9d8305fb6da0
Author: Daniel P. Berrange <[email protected]>
Date: Tue Sep 1 14:46:50 2015 +0100
sockets: allow port to be NULL when listening on IP address
Switching "port" from mandatory to optional causes the QAPI code generator to add a 'has_port' field to the InetSocketAddress struct. No code that created InetSocketAddress objects was updated to set 'has_port = true', which caused the non-NULL port strings to be silently dropped when copying InetSocketAddress objects.
Message-Id: <[email protected]>
--- qapi-schema.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
qapi-schema.json +2 -4
@@ -2614,9 +2614,7 @@ # # @host: host part of the address # -# @port: port part of the address, or lowest port if @to is present. -# Kernel selects a free port if omitted for listener addresses. -# #optional +# @port: port part of the address, or lowest port if @to is present # # @to: highest port to try #
@@ -2631,7 +2629,7 @@ { 'struct': 'InetSocketAddress', 'data': { 'host': 'str', - '*port': 'str', + 'port': 'str', '*to': 'uint16', '*ipv4': 'bool', '*ipv6': 'bool' } }
Signature · 1 line
2.4.3
[Qemu-devel] [PULL v2 08/25] qapi-visit: Split off visit_type_FOO_fields forward decl
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
We generate a static visit_type_FOO_fields() for every type FOO. However, sometimes we need a forward declaration. Split the code to generate the forward declaration out of gen_visit_implicit_struct() into a new gen_visit_fields_decl(), and also prepare for a forward declaration to be emitted during gen_visit_struct(), so that a future patch can switch from using visit_type_FOO_implicit() to the simpler visit_type_FOO_fields() as part of unboxing the base class of a struct.
No change to generated code.
Message-Id: <[email protected]>
--- scripts/qapi-visit.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)
scripts/qapi-visit.py +18 -8
@@ -15,7 +15,12 @@ from qapi import * import re +# visit_type_FOO_implicit() is emitted as needed; track if it has already +# been output. implicit_structs_seen = set() + +# visit_type_FOO_fields() is always emitted; track if a forward declaration +# or implementation has already been output. struct_fields_seen = set()
@@ -29,19 +34,24 @@ void visit_type_%(c_name)s(Visitor *v, %(c_type)sobj, const char *name, Error ** c_name=c_name(name), c_type=c_type) +def gen_visit_fields_decl(typ): + ret = '' + if typ.name not in struct_fields_seen: + ret += mcgen(''' + +static void visit_type_%(c_type)s_fields(Visitor *v, %(c_type)s **obj, Error **errp); +''', + c_type=typ.c_name()) + struct_fields_seen.add(typ.name) + return ret + + def gen_visit_implicit_struct(typ): if typ in implicit_structs_seen: return '' implicit_structs_seen.add(typ) - ret = '' - if typ.name not in struct_fields_seen: - # Need a forward declaration - ret += mcgen(''' - -static void visit_type_%(c_type)s_fields(Visitor *v, %(c_type)s **obj, Error **errp); -''', - c_type=typ.c_name()) + ret = gen_visit_fields_decl(typ) ret += mcgen('''
Signature · 1 line
2.4.3
v2:
* Squashed Eric's build fix.
* Moved Dan's fix to the front, to make merging it easier in case something's still wrong with Eric's patches.
The following changes since commit 3a958f559ecd0511583d27b10011fa7f3cf79b63:
Merge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' into staging (2015-10-30 19:47:47 +0000)
are available in the git repository at:
git://repo.or.cz/qemu/armbru.git tags/pull-qapi-2015-11-02
for you to fetch changes up to 32bc6879beea0b0cac6196cb15a71d206401e96d:
qapi: Simplify gen_struct_field() (2015-11-02 08:30:28 +0100)
----------------------------------------------------------------
QAPI patches
----------------------------------------------------------------
Daniel P. Berrange (1):
qapi-schema: mark InetSocketAddress as mandatory again
Eric Blake (24):
tests/qapi-schema: Test for reserved names, empty struct
qapi: More idiomatic string operations
qapi: More robust conditions for when labels are needed
qapi: Reserve '*List' type names for list types
qapi: Reserve 'q_*' and 'has_*' member names
vnc: Hoist allocation of VncBasicInfo to callers
qapi-visit: Split off visit_type_FOO_fields forward decl
qapi-types: Refactor base fields output
qapi: Prefer typesafe upcasts to qapi base classes
qapi: Unbox base members
qapi-visit: Remove redundant functions for flat union base
qapi: Start converting to new qapi union layout
qapi-visit: Convert to new qapi union layout
tests: Convert to new qapi union layout
block: Convert to new qapi union layout
sockets: Convert to new qapi union layout
net: Convert to new qapi union layout
char: Convert to new qapi union layout
input: Convert to new qapi union layout
memory: Convert to new qapi union layout
tpm: Convert to new qapi union layout
qapi: Finish converting to new qapi union layout
qapi: Reserve 'u' member name
qapi: Simplify gen_struct_field()
block/nbd.c | 18 +--
block/qcow2.c | 10 +-
block/vmdk.c | 6 +-
blockdev.c | 47 +++---
docs/qapi-code-gen.txt | 14 +-
hmp.c | 26 ++--
hw/char/escc.c | 12 +-
hw/input/hid.c | 32 ++--
hw/input/ps2.c | 24 +--
hw/input/virtio-input-hid.c | 27 ++--
hw/mem/pc-dimm.c | 6 +-
net/dump.c | 4 +-
net/hub.c | 4 +-
net/l2tpv3.c | 4 +-
net/net.c | 24 +--
net/slirp.c | 4 +-
net/socket.c | 4 +-
net/tap-win32.c | 4 +-
net/tap.c | 8 +-
net/vde.c | 4 +-
net/vhost-user.c | 4 +-
numa.c | 8 +-
qapi-schema.json | 6 +-
qemu-char.c | 164 ++++++++++-----------
qemu-nbd.c | 16 +-
scripts/qapi-commands.py | 4 +-
scripts/qapi-types.py | 68 +++++----
scripts/qapi-visit.py | 90 +++++------
scripts/qapi.py | 25 ++--
spice-qemu-char.c | 12 +-
tests/Makefile | 8 +-
tests/qapi-schema/enum-union-clash.err | 1 -
tests/qapi-schema/qapi-schema-test.json | 4 +
tests/qapi-schema/qapi-schema-test.out | 3 +
tests/qapi-schema/reserved-command-q.err | 1 +
...um-union-clash.exit => reserved-command-q.exit} | 0
tests/qapi-schema/reserved-command-q.json | 5 +
...-base-clash-base.err => reserved-command-q.out} | 0
tests/qapi-schema/reserved-member-has.err | 1 +
tests/qapi-schema/reserved-member-has.exit | 1 +
tests/qapi-schema/reserved-member-has.json | 5 +
...num-union-clash.out => reserved-member-has.out} | 0
tests/qapi-schema/reserved-member-q.err | 1 +
tests/qapi-schema/reserved-member-q.exit | 1 +
tests/qapi-schema/reserved-member-q.json | 4 +
tests/qapi-schema/reserved-member-q.out | 0
tests/qapi-schema/reserved-member-u.err | 1 +
tests/qapi-schema/reserved-member-u.exit | 1 +
tests/qapi-schema/reserved-member-u.json | 7 +
tests/qapi-schema/reserved-member-u.out | 0
tests/qapi-schema/reserved-type-kind.err | 1 +
tests/qapi-schema/reserved-type-kind.exit | 1 +
...um-union-clash.json => reserved-type-kind.json} | 2 -
tests/qapi-schema/reserved-type-kind.out | 0
tests/qapi-schema/reserved-type-list.err | 1 +
tests/qapi-schema/reserved-type-list.exit | 1 +
tests/qapi-schema/reserved-type-list.json | 5 +
tests/qapi-schema/reserved-type-list.out | 0
tests/qapi-schema/struct-base-clash-base.exit | 1 -
tests/qapi-schema/struct-base-clash-base.json | 9 --
tests/qapi-schema/struct-base-clash-base.out | 5 -
tests/test-qmp-commands.c | 19 +--
tests/test-qmp-event.c | 8 +-
tests/test-qmp-input-visitor.c | 87 +++++------
tests/test-qmp-output-visitor.c | 55 ++++---
tests/test-visitor-serialization.c | 14 +-
tpm.c | 4 +-
ui/console.c | 20 +--
ui/input-keymap.c | 20 +--
ui/input-legacy.c | 21 +--
ui/input.c | 84 +++++------
ui/spice-core.c | 23 +--
ui/vnc.c | 114 +++++++-------
util/qemu-sockets.c | 62 ++++----
74 files changed, 668 insertions(+), 612 deletions(-)
delete mode 100644 tests/qapi-schema/enum-union-clash.err
create mode 100644 tests/qapi-schema/reserved-command-q.err
rename tests/qapi-schema/{enum-union-clash.exit => reserved-command-q.exit} (100%)
create mode 100644 tests/qapi-schema/reserved-command-q.json
rename tests/qapi-schema/{struct-base-clash-base.err => reserved-command-q.out} (100%)
create mode 100644 tests/qapi-schema/reserved-member-has.err
create mode 100644 tests/qapi-schema/reserved-member-has.exit
create mode 100644 tests/qapi-schema/reserved-member-has.json
rename tests/qapi-schema/{enum-union-clash.out => reserved-member-has.out} (100%)
create mode 100644 tests/qapi-schema/reserved-member-q.err
create mode 100644 tests/qapi-schema/reserved-member-q.exit
create mode 100644 tests/qapi-schema/reserved-member-q.json
create mode 100644 tests/qapi-schema/reserved-member-q.out
create mode 100644 tests/qapi-schema/reserved-member-u.err
create mode 100644 tests/qapi-schema/reserved-member-u.exit
create mode 100644 tests/qapi-schema/reserved-member-u.json
create mode 100644 tests/qapi-schema/reserved-member-u.out
create mode 100644 tests/qapi-schema/reserved-type-kind.err
create mode 100644 tests/qapi-schema/reserved-type-kind.exit
rename tests/qapi-schema/{enum-union-clash.json => reserved-type-kind.json} (69%)
create mode 100644 tests/qapi-schema/reserved-type-kind.out
create mode 100644 tests/qapi-schema/reserved-type-list.err
create mode 100644 tests/qapi-schema/reserved-type-list.exit
create mode 100644 tests/qapi-schema/reserved-type-list.json
create mode 100644 tests/qapi-schema/reserved-type-list.out
delete mode 100644 tests/qapi-schema/struct-base-clash-base.exit
delete mode 100644 tests/qapi-schema/struct-base-clash-base.json
delete mode 100644 tests/qapi-schema/struct-base-clash-base.outDaniel P. Berrange (1):
qapi-schema: mark InetSocketAddress as mandatory again
Eric Blake (24):
tests/qapi-schema: Test for reserved names, empty struct
qapi: More idiomatic string operations
qapi: More robust conditions for when labels are needed
qapi: Reserve '*List' type names for list types
qapi: Reserve 'q_*' and 'has_*' member names
vnc: Hoist allocation of VncBasicInfo to callers
qapi-visit: Split off visit_type_FOO_fields forward decl
qapi-types: Refactor base fields output
qapi: Prefer typesafe upcasts to qapi base classes
qapi: Unbox base members
qapi-visit: Remove redundant functions for flat union base
qapi: Start converting to new qapi union layout
qapi-visit: Convert to new qapi union layout
tests: Convert to new qapi union layout
block: Convert to new qapi union layout
sockets: Convert to new qapi union layout
net: Convert to new qapi union layout
char: Convert to new qapi union layout
input: Convert to new qapi union layout
memory: Convert to new qapi union layout
tpm: Convert to new qapi union layout
qapi: Finish converting to new qapi union layout
qapi: Reserve 'u' member name
qapi: Simplify gen_struct_field()
block/nbd.c | 18 +--
block/qcow2.c | 10 +-
block/vmdk.c | 6 +-
blockdev.c | 47 +++---
docs/qapi-code-gen.txt | 14 +-
hmp.c | 26 ++--
hw/char/escc.c | 12 +-
hw/input/hid.c | 32 ++--
hw/input/ps2.c | 24 +--
hw/input/virtio-input-hid.c | 27 ++--
hw/mem/pc-dimm.c | 6 +-
net/dump.c | 4 +-
net/hub.c | 4 +-
net/l2tpv3.c | 4 +-
net/net.c | 24 +--
net/slirp.c | 4 +-
net/socket.c | 4 +-
net/tap-win32.c | 4 +-
net/tap.c | 8 +-
net/vde.c | 4 +-
net/vhost-user.c | 4 +-
numa.c | 8 +-
qapi-schema.json | 6 +-
qemu-char.c | 164 ++++++++++-----------
qemu-nbd.c | 16 +-
scripts/qapi-commands.py | 4 +-
scripts/qapi-types.py | 68 +++++----
scripts/qapi-visit.py | 90 +++++------
scripts/qapi.py | 25 ++--
spice-qemu-char.c | 12 +-
tests/Makefile | 8 +-
tests/qapi-schema/enum-union-clash.err | 1 -
tests/qapi-schema/qapi-schema-test.json | 4 +
tests/qapi-schema/qapi-schema-test.out | 3 +
tests/qapi-schema/reserved-command-q.err | 1 +
...um-union-clash.exit => reserved-command-q.exit} | 0
tests/qapi-schema/reserved-command-q.json | 5 +
...-base-clash-base.err => reserved-command-q.out} | 0
tests/qapi-schema/reserved-member-has.err | 1 +
tests/qapi-schema/reserved-member-has.exit | 1 +
tests/qapi-schema/reserved-member-has.json | 5 +
...num-union-clash.out => reserved-member-has.out} | 0
tests/qapi-schema/reserved-member-q.err | 1 +
tests/qapi-schema/reserved-member-q.exit | 1 +
tests/qapi-schema/reserved-member-q.json | 4 +
tests/qapi-schema/reserved-member-q.out | 0
tests/qapi-schema/reserved-member-u.err | 1 +
tests/qapi-schema/reserved-member-u.exit | 1 +
tests/qapi-schema/reserved-member-u.json | 7 +
tests/qapi-schema/reserved-member-u.out | 0
tests/qapi-schema/reserved-type-kind.err | 1 +
tests/qapi-schema/reserved-type-kind.exit | 1 +
...um-union-clash.json => reserved-type-kind.json} | 2 -
tests/qapi-schema/reserved-type-kind.out | 0
tests/qapi-schema/reserved-type-list.err | 1 +
tests/qapi-schema/reserved-type-list.exit | 1 +
tests/qapi-schema/reserved-type-list.json | 5 +
tests/qapi-schema/reserved-type-list.out | 0
tests/qapi-schema/struct-base-clash-base.exit | 1 -
tests/qapi-schema/struct-base-clash-base.json | 9 --
tests/qapi-schema/struct-base-clash-base.out | 5 -
tests/test-qmp-commands.c | 19 +--
tests/test-qmp-event.c | 8 +-
tests/test-qmp-input-visitor.c | 87 +++++------
tests/test-qmp-output-visitor.c | 55 ++++---
tests/test-visitor-serialization.c | 14 +-
tpm.c | 4 +-
ui/console.c | 20 +--
ui/input-keymap.c | 20 +--
ui/input-legacy.c | 21 +--
ui/input.c | 84 +++++------
ui/spice-core.c | 23 +--
ui/vnc.c | 114 +++++++-------
util/qemu-sockets.c | 62 ++++----
74 files changed, 668 insertions(+), 612 deletions(-)
delete mode 100644 tests/qapi-schema/enum-union-clash.err
create mode 100644 tests/qapi-schema/reserved-command-q.err
rename tests/qapi-schema/{enum-union-clash.exit => reserved-command-q.exit} (100%)
create mode 100644 tests/qapi-schema/reserved-command-q.json
rename tests/qapi-schema/{struct-base-clash-base.err => reserved-command-q.out} (100%)
create mode 100644 tests/qapi-schema/reserved-member-has.err
create mode 100644 tests/qapi-schema/reserved-member-has.exit
create mode 100644 tests/qapi-schema/reserved-member-has.json
rename tests/qapi-schema/{enum-union-clash.out => reserved-member-has.out} (100%)
create mode 100644 tests/qapi-schema/reserved-member-q.err
create mode 100644 tests/qapi-schema/reserved-member-q.exit
create mode 100644 tests/qapi-schema/reserved-member-q.json
create mode 100644 tests/qapi-schema/reserved-member-q.out
create mode 100644 tests/qapi-schema/reserved-member-u.err
create mode 100644 tests/qapi-schema/reserved-member-u.exit
create mode 100644 tests/qapi-schema/reserved-member-u.json
create mode 100644 tests/qapi-schema/reserved-member-u.out
create mode 100644 tests/qapi-schema/reserved-type-kind.err
create mode 100644 tests/qapi-schema/reserved-type-kind.exit
rename tests/qapi-schema/{enum-union-clash.json => reserved-type-kind.json} (69%)
create mode 100644 tests/qapi-schema/reserved-type-kind.out
create mode 100644 tests/qapi-schema/reserved-type-list.err
create mode 100644 tests/qapi-schema/reserved-type-list.exit
create mode 100644 tests/qapi-schema/reserved-type-list.json
create mode 100644 tests/qapi-schema/reserved-type-list.out
delete mode 100644 tests/qapi-schema/struct-base-clash-base.exit
delete mode 100644 tests/qapi-schema/struct-base-clash-base.json
delete mode 100644 tests/qapi-schema/struct-base-clash-base.outSignature · 1 line
2.4.3
[Qemu-devel] [PULL v2 02/25] tests/qapi-schema: Test for reserved names, empty struct
From: Eric Blake <[email protected]>
Add some testsuite coverage to ensure future patches are on the right track:
Our current C representation of qapi arrays is done by appending 'List' to the element name; but we are not preventing the creation of an object type with the same name. Add reserved-type-list.json to test this. Then rename enum-union-clash.json to reserved-type-kind.json to cover the reservation that we DO detect, and shorten it to match the fact that the name is reserved even if there is no clash.
We are failing to detect a collision between a dictionary member and the implicit 'has_*' flag for another optional member. The easiest fix would be for a future patch to reserve the entire "has[-_]" namespace for member names (the collision is also possible for branch names within flat unions, but only as long as branch names can collide with (non-variant) members; however, since future patches are about to remove that, it is not worth testing here). Add reserved-member-has.json to test this.
A similar collision exists between a dictionary member where c_name() munges what might otherwise be a reserved name to start with 'q_', and another member explicitly starts with "q[-_]". Again, the easiest solution for a future patch will be reserving the entire namespace, but here for commands as well as members. Add reserved-member-q.json and reserved-command-q.json to test this; separate tests since arguably our munging of command 'unix' to 'qmp_q_unix()' could be done without a q_, which is different than the munging of a member 'unix' to 'foo.q_unix'.
Finally, our testsuite does not have any compilation coverage of struct inheritance with empty qapi structs. Update qapi-schema-test.json to test this.
Note that there is currently no technical reason to forbid type name patterns from member names, or member name patterns from types, since the two are not in the same namespace in C and won't collide; but it's not worth adding positive tests of these corner cases at this time, especially while there is other churn pending in patches that rearrange which collisions actually happen.
Message-Id: <[email protected]>
---
tests/Makefile | 6 +++++-
tests/qapi-schema/enum-union-clash.err | 1 -
tests/qapi-schema/qapi-schema-test.json | 4 ++++
tests/qapi-schema/qapi-schema-test.out | 3 +++
tests/qapi-schema/{enum-union-clash.out => reserved-command-q.err} | 0
tests/qapi-schema/reserved-command-q.exit | 1 +
tests/qapi-schema/reserved-command-q.json | 7 +++++++
tests/qapi-schema/reserved-command-q.out | 5 +++++
tests/qapi-schema/reserved-member-has.err | 0
tests/qapi-schema/reserved-member-has.exit | 1 +
tests/qapi-schema/reserved-member-has.json | 6 ++++++
tests/qapi-schema/reserved-member-has.out | 6 ++++++
tests/qapi-schema/reserved-member-q.err | 0
tests/qapi-schema/reserved-member-q.exit | 1 +
tests/qapi-schema/reserved-member-q.json | 6 ++++++
tests/qapi-schema/reserved-member-q.out | 4 ++++
tests/qapi-schema/reserved-type-kind.err | 1 +
.../qapi-schema/{enum-union-clash.exit => reserved-type-kind.exit} | 0
.../qapi-schema/{enum-union-clash.json => reserved-type-kind.json} | 2 --
tests/qapi-schema/reserved-type-kind.out | 0
tests/qapi-schema/reserved-type-list.err | 0
tests/qapi-schema/reserved-type-list.exit | 1 +
tests/qapi-schema/reserved-type-list.json | 5 +++++
tests/qapi-schema/reserved-type-list.out | 3 +++
24 files changed, 59 insertions(+), 4 deletions(-)
delete mode 100644 tests/qapi-schema/enum-union-clash.err
rename tests/qapi-schema/{enum-union-clash.out => reserved-command-q.err} (100%)
create mode 100644 tests/qapi-schema/reserved-command-q.exit
create mode 100644 tests/qapi-schema/reserved-command-q.json
create mode 100644 tests/qapi-schema/reserved-command-q.out
create mode 100644 tests/qapi-schema/reserved-member-has.err
create mode 100644 tests/qapi-schema/reserved-member-has.exit
create mode 100644 tests/qapi-schema/reserved-member-has.json
create mode 100644 tests/qapi-schema/reserved-member-has.out
create mode 100644 tests/qapi-schema/reserved-member-q.err
create mode 100644 tests/qapi-schema/reserved-member-q.exit
create mode 100644 tests/qapi-schema/reserved-member-q.json
create mode 100644 tests/qapi-schema/reserved-member-q.out
create mode 100644 tests/qapi-schema/reserved-type-kind.err
rename tests/qapi-schema/{enum-union-clash.exit => reserved-type-kind.exit} (100%)
rename tests/qapi-schema/{enum-union-clash.json => reserved-type-kind.json} (69%)
create mode 100644 tests/qapi-schema/reserved-type-kind.out
create mode 100644 tests/qapi-schema/reserved-type-list.err
create mode 100644 tests/qapi-schema/reserved-type-list.exit
create mode 100644 tests/qapi-schema/reserved-type-list.json
create mode 100644 tests/qapi-schema/reserved-type-list.outtests/Makefile +5 -1
@@ -265,7 +265,6 @@ qapi-schema += enum-dict-member.json qapi-schema += enum-int-member.json qapi-schema += enum-max-member.json qapi-schema += enum-missing-data.json -qapi-schema += enum-union-clash.json qapi-schema += enum-wrong-data.json qapi-schema += escape-outside-string.json qapi-schema += escape-too-big.json
@@ -316,6 +315,11 @@ qapi-schema += redefined-builtin.json qapi-schema += redefined-command.json qapi-schema += redefined-event.json qapi-schema += redefined-type.json +qapi-schema += reserved-command-q.json +qapi-schema += reserved-member-has.json +qapi-schema += reserved-member-q.json +qapi-schema += reserved-type-kind.json +qapi-schema += reserved-type-list.json qapi-schema += returns-alternate.json qapi-schema += returns-array-bad.json qapi-schema += returns-dict.json
tests/qapi-schema/enum-union-clash.err deleted +0 -1
@@ -1 +0,0 @@ -tests/qapi-schema/enum-union-clash.json:2: enum 'UnionKind' should not end in 'Kind'
tests/qapi-schema/qapi-schema-test.json +4 -0
@@ -11,6 +11,10 @@ # An empty enum, although unusual, is currently acceptable { 'enum': 'MyEnum', 'data': [ ] } +# Likewise for an empty struct, including an empty base +{ 'struct': 'Empty1', 'data': { } } +{ 'struct': 'Empty2', 'base': 'Empty1', 'data': { } } + # for testing override of default naming heuristic { 'enum': 'QEnumTwo', 'prefix': 'QENUM_TWO',
tests/qapi-schema/qapi-schema-test.out +3 -0
@@ -81,6 +81,9 @@ event EVENT_A None event EVENT_B None event EVENT_C :obj-EVENT_C-arg event EVENT_D :obj-EVENT_D-arg +object Empty1 +object Empty2 + base Empty1 enum EnumOne ['value1', 'value2', 'value3'] object EventStructOne member struct1: UserDefOne optional=False
tests/qapi-schema/reserved-command-q.err renamed from tests/qapi-schema/enum-union-clash.out +0 -0
tests/qapi-schema/reserved-command-q.exit new file +1 -0
@@ -0,0 +1 @@ +0
tests/qapi-schema/reserved-command-q.json new file +7 -0
@@ -0,0 +1,7 @@ +# C entity name collision +# FIXME - This parses, but fails to compile, because it attempts to declare +# two 'qmp_q_unix' functions (one for 'q-unix', the other because c_name() +# munges 'unix' to 'q_unix' to avoid reserved word collisions). We should +# reject attempts to explicitly use 'q_' names, to reserve it for qapi. +{ 'command': 'unix' } +{ 'command': 'q-unix' }
tests/qapi-schema/reserved-command-q.out new file +5 -0
@@ -0,0 +1,5 @@ +object :empty +command q-unix None -> None + gen=True success_response=True +command unix None -> None + gen=True success_response=True
tests/qapi-schema/reserved-member-has.err new file +0 -0
tests/qapi-schema/reserved-member-has.exit new file +1 -0
@@ -0,0 +1 @@ +0
tests/qapi-schema/reserved-member-has.json new file +6 -0
@@ -0,0 +1,6 @@ +# C member name collision +# FIXME - This parses, but fails to compile, because the C struct is given +# two 'has_a' members, one from the flag for optional 'a', and the other +# from member 'has-a'. Either reject this at parse time, or munge the C +# names to avoid the collision. +{ 'command': 'oops', 'data': { '*a': 'str', 'has-a': 'str' } }
tests/qapi-schema/reserved-member-has.out new file +6 -0
@@ -0,0 +1,6 @@ +object :empty +object :obj-oops-arg + member a: str optional=True + member has-a: str optional=False +command oops :obj-oops-arg -> None + gen=True success_response=True
tests/qapi-schema/reserved-member-q.err new file +0 -0
tests/qapi-schema/reserved-member-q.exit new file +1 -0
@@ -0,0 +1 @@ +0
tests/qapi-schema/reserved-member-q.json new file +6 -0
@@ -0,0 +1,6 @@ +# C member name collision +# FIXME - This parses, but fails to compile, because it attempts to declare +# two 'q_unix' members (one for 'q-unix', the other because c_name() +# munges 'unix' to 'q_unix' to avoid reserved word collisions). We should +# reject attempts to explicitly use 'q_' names, to reserve it for qapi. +{ 'struct': 'Foo', 'data': { 'unix':'int', 'q-unix':'bool' } }
tests/qapi-schema/reserved-member-q.out new file +4 -0
@@ -0,0 +1,4 @@ +object :empty +object Foo + member unix: int optional=False + member q-unix: bool optional=False
tests/qapi-schema/reserved-type-kind.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/reserved-type-kind.json:2: enum 'UnionKind' should not end in 'Kind'
tests/qapi-schema/reserved-type-kind.exit renamed from tests/qapi-schema/enum-union-clash.exit +0 -0
tests/qapi-schema/reserved-type-kind.json renamed from tests/qapi-schema/enum-union-clash.json +0 -2
@@ -1,4 +1,2 @@ # we reject types that would conflict with implicit union enum { 'enum': 'UnionKind', 'data': [ 'oops' ] } -{ 'union': 'Union', - 'data': { 'a': 'int' } }
tests/qapi-schema/reserved-type-kind.out new file +0 -0
tests/qapi-schema/reserved-type-list.err new file +0 -0
tests/qapi-schema/reserved-type-list.exit new file +1 -0
@@ -0,0 +1 @@ +0
tests/qapi-schema/reserved-type-list.json new file +5 -0
@@ -0,0 +1,5 @@ +# Potential C name collision +# FIXME - This parses and compiles on its own, but prevents the user from +# creating a type named 'Foo' and using ['Foo'] for an array. We should +# reject the use of any type names ending in 'List'. +{ 'struct': 'FooList', 'data': { 's': 'str' } }
tests/qapi-schema/reserved-type-list.out new file +3 -0
@@ -0,0 +1,3 @@ +object :empty +object FooList + member s: str optional=False
Signature · 1 line
2.4.3
[Qemu-devel] [PULL v2 05/25] qapi: Reserve '*List' type names for list types
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
Type names ending in 'List' can clash with qapi list types in generated C. We don't currently use such names. It is easier to outlaw them now than to worry about how to resolve such a clash in the future. For precedence, see commit 4dc2e69, which did the same for names ending in 'Kind' versus implicit enum types for qapi unions.
Update the testsuite to match.
Message-Id: <[email protected]>
--- docs/qapi-code-gen.txt | 3 ++- scripts/qapi.py | 10 ++++------ tests/qapi-schema/reserved-type-list.err | 1 + tests/qapi-schema/reserved-type-list.exit | 2 +- tests/qapi-schema/reserved-type-list.json | 6 +++--- tests/qapi-schema/reserved-type-list.out | 3 --- 6 files changed, 11 insertions(+), 14 deletions(-)
docs/qapi-code-gen.txt +2 -1
@@ -106,7 +106,8 @@ Types, commands, and events share a common namespace. Therefore, generally speaking, type definitions should always use CamelCase for user-defined type names, while built-in types are lowercase. Type definitions should not end in 'Kind', as this namespace is used for -creating implicit C enums for visiting union types. Command names, +creating implicit C enums for visiting union types, or in 'List', as +this namespace is used for creating array types. Command names, and field names within a type, should be all lower case with words separated by a hyphen. However, some existing older commands and complex types use underscore; when extending such expressions,
scripts/qapi.py +4 -6
@@ -390,10 +390,10 @@ def add_name(name, info, meta, implicit=False): raise QAPIExprError(info, "%s '%s' is already defined" % (all_names[name], name)) - if not implicit and name.endswith('Kind'): + if not implicit and (name.endswith('Kind') or name.endswith('List')): raise QAPIExprError(info, - "%s '%s' should not end in 'Kind'" - % (meta, name)) + "%s '%s' should not end in '%s'" + % (meta, name, name[-4:])) all_names[name] = meta
@@ -1196,9 +1196,7 @@ class QAPISchema(object): return name def _make_array_type(self, element_type, info): - # TODO fooList namespace is not reserved; user can create collisions, - # or abuse our type system with ['fooList'] for 2D array - name = element_type + 'List' + name = element_type + 'List' # Use namespace reserved by add_name() if not self.lookup_type(name): self._def_entity(QAPISchemaArrayType(name, info, element_type)) return name
tests/qapi-schema/reserved-type-list.err +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/reserved-type-list.json:5: struct 'FooList' should not end in 'List'
tests/qapi-schema/reserved-type-list.exit +1 -1
@@ -1 +1 @@ -0 +1
tests/qapi-schema/reserved-type-list.json +3 -3
@@ -1,5 +1,5 @@ # Potential C name collision -# FIXME - This parses and compiles on its own, but prevents the user from -# creating a type named 'Foo' and using ['Foo'] for an array. We should -# reject the use of any type names ending in 'List'. +# We reserve names ending in 'List' for use by array types. +# TODO - we could choose array names to avoid collision with user types, +# in order to let this compile { 'struct': 'FooList', 'data': { 's': 'str' } }
tests/qapi-schema/reserved-type-list.out +0 -3
@@ -1,3 +0,0 @@ -object :empty -object FooList - member s: str optional=False
Signature · 1 line
2.4.3
[Qemu-devel] [PULL v2 07/25] vnc: Hoist allocation of VncBasicInfo to callers
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
A future qapi patch will rework generated structs with a base class to be unboxed. In preparation for that, change the code that allocates then populates an info struct to instead merely populate the fields of an info field passed in as a parameter (renaming vnc_basic_info_get* to vnc_init_basic_info*). Add rudimentary Error handling at the lowest levels for cases where the old code returned NULL; but rather than plumb Error all the way through the stack, the callers drop the error and return NULL as before.
Message-Id: <[email protected]>
--- ui/vnc.c | 57 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 23 deletions(-)
ui/vnc.c +34 -23
@@ -156,10 +156,11 @@ char *vnc_socket_remote_addr(const char *format, int fd) {return addr_to_string (format, &sa, salen); } -static VncBasicInfo *vnc_basic_info_get (struct sockaddr_storage *sa, -socklen_t salen) +static void vnc_init_basic_info (struct sockaddr_storage *sa, +socklen_t salen, +VncBasicInfo *info, +Error **errp) { -VncBasicInfo *info;char host[NI_MAXHOST ];char serv[NI_MAXSERV ];int err;
@@ -168,42 +169,44 @@ static VncBasicInfo *vnc_basic_info_get(struct sockaddr_storage *sa, host, sizeof(host), serv, sizeof(serv), NI_NUMERICHOST | NI_NUMERICSERV)) != 0) { -VNC_DEBUG ("Cannot resolve address %d: %s\n" , - err,gai_strerror (err)); -return NULL ; +error_setg (errp,"Cannot resolve address: %s" , +gai_strerror (err)); +return ; } - info =g_malloc0 (sizeof (VncBasicInfo)); info->host =g_strdup (host); info->service =g_strdup (serv); info->family =inet_netfamily (sa->ss_family); -return info; } -static VncBasicInfo *vnc_basic_info_get_from_server_addr (int fd) +static void vnc_init_basic_info_from_server_addr (int fd,VncBasicInfo *info, +Error **errp) {struct sockaddr_storage sa;socklen_t salen; salen =sizeof (sa);if (getsockname (fd, (struct sockaddr *)&sa, &salen) <0 ) { -return NULL ; +error_setg_errno (errp, errno,"getsockname failed" ); +return ; } -return vnc_basic_info_get (&sa, salen); +vnc_init_basic_info (&sa, salen, info, errp); } -static VncBasicInfo *vnc_basic_info_get_from_remote_addr (int fd) +static void vnc_init_basic_info_from_remote_addr (int fd,VncBasicInfo *info, +Error **errp) {struct sockaddr_storage sa;socklen_t salen; salen =sizeof (sa);if (getpeername (fd, (struct sockaddr *)&sa, &salen) <0 ) { -return NULL ; +error_setg_errno (errp, errno,"getpeername failed" ); +return ; } -return vnc_basic_info_get (&sa, salen); +vnc_init_basic_info (&sa, salen, info, errp); }static const char *vnc_auth_name (VncDisplay *vd) {
@@ -256,15 +259,18 @@ static const char *vnc_auth_name(VncDisplay *vd) {static VncServerInfo *vnc_server_info_get (VncDisplay *vd) {VncServerInfo *info; -VncBasicInfo *bi =vnc_basic_info_get_from_server_addr (vd->lsock); -if (!bi) { -return NULL ; - } +Error *err =NULL ; info =g_malloc (sizeof (*info)); - info->base = bi; + info->base =g_malloc (sizeof (*info->base)); +vnc_init_basic_info_from_server_addr (vd->lsock, info->base, &err); info->has_auth = true; info->auth =g_strdup (vnc_auth_name (vd)); +if (err) { +qapi_free_VncServerInfo (info); + info =NULL ; +error_free (err); + }return info; }
@@ -291,11 +297,16 @@ static void vnc_client_cache_auth(VncState *client)static void vnc_client_cache_addr (VncState *client) { -VncBasicInfo *bi =vnc_basic_info_get_from_remote_addr (client->csock); +Error *err =NULL ; -if (bi) { - client->info =g_malloc0 (sizeof (*client->info)); - client->info->base = bi; + client->info =g_malloc0 (sizeof (*client->info)); + client->info->base =g_malloc0 (sizeof (*client->info->base)); +vnc_init_basic_info_from_remote_addr (client->csock, client->info->base, + &err); +if (err) { +qapi_free_VncClientInfo (client->info); + client->info =NULL ; +error_free (err); } }
Signature · 1 line
2.4.3
[Qemu-devel] [PULL v2 10/25] qapi: Prefer typesafe upcasts to qapi base classes
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
A previous patch (commit 1e6c1616) made it possible to directly cast from a qapi flat union type to its base type. However, it requires the use of a C cast, which turns off compiler type-safety checks. Fortunately, no such casts exist, just yet.
Regardless, add inline type-safe wrappers named qapi_FOO_base() for any union type FOO that has a base, which can be used for a safer upcast, and enhance the testsuite to cover the new functionality.
A future patch will extend the upcast support to structs, where such conversions do exist already.
Note that C makes const-correct upcasts annoying because it lacks overloads; these functions cast away const so that they can accept user pointers whether const or not, and the result in turn can be assigned to normal or const pointers. Alternatively, this could have been done with macros, but type-safe macros are hairy, and not worthwhile here.
This patch just adds upcasts. None of our code needed to downcast from a base qapi class to a child. Also, in the case of grandchildren (such as BlockdevOptionsQcow2), the caller will need to call two functions to get to the inner base (although it wouldn't be too hard to generate a qapi_FOO_base_base() if desired). If a user changes qapi to alter the base class hierarchy, such as going from 'A -> C' to 'A -> B -> C', it will change the type of 'qapi_C_base()', and the compiler will point out the places that are affected by the new base.
One alternative was proposed, but was deemed too ugly to use in practice: the generators could output redundant information using anonymous types:
| struct Child {
| union {
| struct {
| Type1 parent_member1;
| Type2 parent_member2;
| };
| Parent base;
| };
| };With that ugly proposal, for a given qapi type, obj->member and obj->base.member would refer to the same storage; allowing convenience in working with members without needing 'base.' allowing typesafe upcast without needing a C cast by accessing '&obj->base', and allowing downcasts from the parent back to the child possible through container_of(obj, Child, base).
Message-Id: <[email protected]>
--- scripts/qapi-types.py | 16 ++++++++++++++++ tests/test-qmp-input-visitor.c | 5 +++++ 2 files changed, 21 insertions(+)
scripts/qapi-types.py +16 -0
@@ -98,6 +98,19 @@ struct %(c_name)s { return ret +def gen_upcast(name, base): + # C makes const-correctness ugly. We have to cast away const to let + # this function work for both const and non-const obj. + return mcgen(''' + +static inline %(base)s *qapi_%(c_name)s_base(const %(c_name)s *obj) +{ + return (%(base)s *)obj; +} +''', + c_name=c_name(name), base=base.c_name()) + + def gen_alternate_qtypes_decl(name): return mcgen('''
@@ -267,6 +280,9 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): if variants: assert not members # not implemented self.decl += gen_union(name, base, variants) + # TODO Use gen_upcast on structs too, once they have sane layout + if base: + self.decl += gen_upcast(name, base) else: self.decl += gen_struct(name, base, members) self._gen_type_cleanup(name)
tests/test-qmp-input-visitor.c +5 -0
@@ -347,6 +347,7 @@ static void test_visitor_in_union_flat(TestInputVisitorData *data,Visitor *v;Error *err =NULL ;UserDefFlatUnion *tmp; +UserDefUnionBase *base; v =visitor_input_test_init (data, "{ 'enum1': 'value1', "
@@ -360,6 +361,10 @@ static void test_visitor_in_union_flat(TestInputVisitorData *data, g_assert_cmpstr(tmp->string, ==, "str"); g_assert_cmpint(tmp->integer, ==, 41); g_assert_cmpint(tmp->value1->boolean, ==, true); + + base =qapi_UserDefFlatUnion_base (tmp); +g_assert (&base->enum1 == &tmp->enum1); +qapi_free_UserDefFlatUnion (tmp); }
Signature · 1 line
2.4.3
[Qemu-devel] [PULL v2 13/25] qapi: Start converting to new qapi union layout
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
We have two issues with our qapi union layout:
1) Even though the QMP wire format spells the tag 'type', the C code spells it 'kind', requiring some hacks in the generator.
2) The C struct uses an anonymous union, which places all tag values in the same namespace as all non-variant members. This leads to spurious collisions if a tag value matches a non-variant member's name.
This patch is the front end for a series that converts to a saner qapi union layout. By the end of the series, we will no longer have the type/kind mismatch, and all tag values will be under a named union, which requires clients to access 'obj->u.value' instead of 'obj->value'. But since the conversion touches a number of files, it is easiest if we temporarily support BOTH layouts simultaneously.
Given a simple union qapi type:
{ 'union':'Foo', 'data': { 'a':'int', 'b':'bool' } }
make the following changes in generated qapi-types.h:
| struct Foo {
|- FooKind kind;
|- union { /* union tag is @kind */
|+ union {
|+ FooKind kind;
|+ FooKind type;
|+ };
|+ union { /* union tag is @type */
| void *data;
| int64_t a;
| bool b;
|+ union { /* union tag is @type */
|+ void *data;
|+ int64_t a;
|+ bool b;
|+ } u;
| };
| };Flat unions do not need the anonymous union for the tag member, as we already fixed that to use the member name instead of 'kind' back in commit 0f61af3e.
One additional change is needed in qapi.py: check_union() now needs to check for collisions with 'type' in addition to those with 'kind'.
Later, when the conversions are complete, we will remove the duplication hacks, and also drop the check_union() restrictions.
Note, however, that we do not rename the generated enum, which is still 'FooKind'. A further patch could generate implicit enums as 'FooType', but while the generator already reserved the '*Kind' namespace (commit 4dc2e69), there are already QMP constructs with '*Type' naming, which means changing our reservation namespace would have lots of churn to C code to deal with a forced name change.
Message-Id: <[email protected]>
--- scripts/qapi-types.py | 26 +++++++++++++++++++------- scripts/qapi.py | 3 ++- 2 files changed, 21 insertions(+), 8 deletions(-)
scripts/qapi-types.py +19 -7
@@ -149,11 +149,23 @@ struct %(c_name)s { if base: ret += gen_struct_fields([], base) else: + # TODO As a hack, we emit both 'kind' and 'type'. Ultimately, we + # want to use only 'type', but the conversion is large enough to + # require staging over several commits. ret += mcgen(''' - %(c_type)s kind; + union { + %(c_type)s kind; + %(c_type)s type; + }; ''', c_type=c_name(variants.tag_member.type.name)) + # TODO As a hack, we emit the union twice, once as an anonymous union + # and once as a named union. Ultimately, we want to use only the + # named union version (as it avoids conflicts between tag values as + # branch names competing with non-variant QMP names), but the conversion + # is large enough to require staging over several commits. + tmp = '' # FIXME: What purpose does data serve, besides preventing a union that # has a branch named 'data'? We use it in qapi-visit.py to decide # whether to bypass the switch statement if visiting the discriminator
@@ -162,25 +174,25 @@ struct %(c_name)s { # should not be any data leaks even without a data pointer. Or, if # 'data' is merely added to guarantee we don't have an empty union, # shouldn't we enforce that at .json parse time? - ret += mcgen(''' + tmp += mcgen(''' union { /* union tag is @%(c_name)s */ void *data; ''', - # TODO ugly special case for simple union - # Use same tag name in C as on the wire to get rid of - # it, then: c_name=c_name(variants.tag_member.name) - c_name=c_name(variants.tag_name or 'kind')) + c_name=c_name(variants.tag_member.name)) for var in variants.variants: # Ugly special case for simple union TODO get rid of it typ = var.simple_union_type() or var.type - ret += mcgen(''' + tmp += mcgen(''' %(c_type)s %(c_name)s; ''', c_type=typ.c_type(), c_name=c_name(var.name)) + ret += tmp + ret += ' ' + '\n '.join(tmp.split('\n')) ret += mcgen(''' + } u; }; }; ''')
scripts/qapi.py +2 -1
@@ -548,7 +548,8 @@ def check_union(expr, expr_info): base = expr.get('base') discriminator = expr.get('discriminator') members = expr['data'] - values = {'MAX': '(automatic)', 'KIND': '(automatic)'} + values = {'MAX': '(automatic)', 'KIND': '(automatic)', + 'TYPE': '(automatic)'} # Two types of unions, determined by discriminator.
Signature · 1 line
2.4.3
[Qemu-devel] [PULL v2 14/25] qapi-visit: Convert to new qapi union layout
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
We have two issues with our qapi union layout:
1) Even though the QMP wire format spells the tag 'type', the C code spells it 'kind', requiring some hacks in the generator.
2) The C struct uses an anonymous union, which places all tag values in the same namespace as all non-variant members. This leads to spurious collisions if a tag value matches a non-variant member's name.
Make the conversion to the new layout for qapi-visit.py.
Generated code changes look like:
|@@ -4912,16 +4912,16 @@ void visit_type_MemoryDeviceInfo(Visitor
| if (!*obj) {
| goto out_obj;
| }
|- visit_type_MemoryDeviceInfoKind(v, &(*obj)->kind, "type", &err);
|+ visit_type_MemoryDeviceInfoKind(v, &(*obj)->type, "type", &err);
| if (err) {
| goto out_obj;
| }
|- if (!visit_start_union(v, !!(*obj)->data, &err) || err) {
|+ if (!visit_start_union(v, !!(*obj)->u.data, &err) || err) {
| goto out_obj;
| }
|- switch ((*obj)->kind) {
|+ switch ((*obj)->type) {
| case MEMORY_DEVICE_INFO_KIND_DIMM:
|- visit_type_PCDIMMDeviceInfo(v, &(*obj)->dimm, "data", &err);
|+ visit_type_PCDIMMDeviceInfo(v, &(*obj)->u.dimm, "data", &err);
| break;
| default:
| abort();
|@@ -4930,7 +4930,7 @@ out_obj:
| error_propagate(errp, err);
| err = NULL;
| if (*obj) {
|- visit_end_union(v, !!(*obj)->data, &err);
|+ visit_end_union(v, !!(*obj)->u.data, &err);
| }
| error_propagate(errp, err);
| err = NULL;Message-Id: <[email protected]>
--- scripts/qapi-visit.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-)
scripts/qapi-visit.py +9 -15
@@ -189,18 +189,18 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error if (err) { goto out; } - visit_get_next_type(v, (int*) &(*obj)->kind, %(c_name)s_qtypes, name, &err); + visit_get_next_type(v, (int*) &(*obj)->type, %(c_name)s_qtypes, name, &err); if (err) { goto out_obj; } - switch ((*obj)->kind) { + switch ((*obj)->type) { ''', c_name=c_name(name)) for var in variants.variants: ret += mcgen(''' case %(case)s: - visit_type_%(c_type)s(v, &(*obj)->%(c_name)s, name, &err); + visit_type_%(c_type)s(v, &(*obj)->u.%(c_name)s, name, &err); break; ''', case=c_enum_const(variants.tag_member.type.name,
@@ -261,22 +261,16 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error visit_type_%(c_type)s(v, &(*obj)->%(c_name)s, "%(name)s", &err); ''', c_type=variants.tag_member.type.c_name(), - # TODO ugly special case for simple union - # Use same tag name in C as on the wire to get rid of - # it, then: c_name=c_name(variants.tag_member.name) - c_name='kind', + c_name=c_name(variants.tag_member.name), name=variants.tag_member.name) ret += gen_err_check(label='out_obj') ret += mcgen(''' - if (!visit_start_union(v, !!(*obj)->data, &err) || err) { + if (!visit_start_union(v, !!(*obj)->u.data, &err) || err) { goto out_obj; } switch ((*obj)->%(c_name)s) { ''', - # TODO ugly special case for simple union - # Use same tag name in C as on the wire to get rid of - # it, then: c_name=c_name(variants.tag_member.name) - c_name=c_name(variants.tag_name or 'kind')) + c_name=c_name(variants.tag_member.name)) for var in variants.variants: # TODO ugly special case for simple union
@@ -288,13 +282,13 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error var.name)) if simple_union_type: ret += mcgen(''' - visit_type_%(c_type)s(v, &(*obj)->%(c_name)s, "data", &err); + visit_type_%(c_type)s(v, &(*obj)->u.%(c_name)s, "data", &err); ''', c_type=simple_union_type.c_name(), c_name=c_name(var.name)) else: ret += mcgen(''' - visit_type_implicit_%(c_type)s(v, &(*obj)->%(c_name)s, &err); + visit_type_implicit_%(c_type)s(v, &(*obj)->u.%(c_name)s, &err); ''', c_type=var.type.c_name(), c_name=c_name(var.name))
@@ -310,7 +304,7 @@ out_obj: error_propagate(errp, err); err = NULL; if (*obj) { - visit_end_union(v, !!(*obj)->data, &err); + visit_end_union(v, !!(*obj)->u.data, &err); } error_propagate(errp, err); err = NULL;
Signature · 1 line
2.4.3
[Qemu-devel] [PULL v2 12/25] qapi-visit: Remove redundant functions for flat union base
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
The code for visiting the base class of a child struct created visit_type_Base_fields() which covers all fields of Base; while the code for visiting the base class of a flat union created visit_type_Union_fields() covering all fields of the base except the discriminator. But since the base class includes the discriminator of a flat union, we can just visit the entire base, without needing a separate visit of the discriminator. Not only is consistently visiting all fields easier to understand, it lets us share code.
The generated code in qapi-visit.c loses several now-unused visit_type_UNION_fields(), along with changes like:
|@@ -1654,11 +1557,7 @@ void visit_type_BlockdevOptions(Visitor
| if (!*obj) {
| goto out_obj;
| }
|- visit_type_BlockdevOptions_fields(v, obj, &err);
|- if (err) {
|- goto out_obj;
|- }
|- visit_type_BlockdevDriver(v, &(*obj)->driver, "driver", &err);
|+ visit_type_BlockdevOptionsBase_fields(v, (BlockdevOptionsBase **)obj, &err);
| if (err) {
| goto out_obj;
| }and forward declarations where needed. Note that the cast of obj to BASE ** is necessary to call visit_type_BASE_fields() (and we can't use our upcast wrappers, because those work on pointers while we have a pointer-to-pointer).
Message-Id: <[email protected]>
--- scripts/qapi-visit.py | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-)
scripts/qapi-visit.py +15 -17
@@ -228,8 +228,7 @@ def gen_visit_union(name, base, variants): ret = '' if base: - members = [m for m in base.members if m != variants.tag_member] - ret += gen_visit_struct_fields(name, None, members) + ret += gen_visit_fields_decl(base) for var in variants.variants: # Ugly special case for simple union TODO get rid of it
@@ -254,31 +253,30 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error if base: ret += mcgen(''' - visit_type_%(c_name)s_fields(v, obj, &err); + visit_type_%(c_name)s_fields(v, (%(c_name)s **)obj, &err); ''', - c_name=c_name(name)) - ret += gen_err_check(label='out_obj') - - tag_key = variants.tag_member.name - if not variants.tag_name: - # we pointlessly use a different key for simple unions - tag_key = 'type' - ret += mcgen(''' + c_name=base.c_name()) + else: + ret += mcgen(''' visit_type_%(c_type)s(v, &(*obj)->%(c_name)s, "%(name)s", &err); - if (err) { - goto out_obj; - } +''', + c_type=variants.tag_member.type.c_name(), + # TODO ugly special case for simple union + # Use same tag name in C as on the wire to get rid of + # it, then: c_name=c_name(variants.tag_member.name) + c_name='kind', + name=variants.tag_member.name) + ret += gen_err_check(label='out_obj') + ret += mcgen(''' if (!visit_start_union(v, !!(*obj)->data, &err) || err) { goto out_obj; } switch ((*obj)->%(c_name)s) { ''', - c_type=variants.tag_member.type.c_name(), # TODO ugly special case for simple union # Use same tag name in C as on the wire to get rid of # it, then: c_name=c_name(variants.tag_member.name) - c_name=c_name(variants.tag_name or 'kind'), - name=tag_key) + c_name=c_name(variants.tag_name or 'kind')) for var in variants.variants: # TODO ugly special case for simple union
Signature · 1 line
2.4.3
[Qemu-devel] [PULL v2 22/25] tpm: Convert to new qapi union layout
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
We have two issues with our qapi union layout:
1) Even though the QMP wire format spells the tag 'type', the C code spells it 'kind', requiring some hacks in the generator.
2) The C struct uses an anonymous union, which places all tag values in the same namespace as all non-variant members. This leads to spurious collisions if a tag value matches a non-variant member's name.
Make the conversion to the new layout for TPM-related code.
Message-Id: <[email protected]>
--- hmp.c | 6 +++--- tpm.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-)
hmp.c +3 -3
@@ -841,11 +841,11 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict) c, TpmModel_lookup[ti->model]);monitor_printf (mon," \\ %s: type=%s" , - ti->id, TpmTypeOptionsKind_lookup[ti->options->kind]); + ti->id, TpmTypeOptionsKind_lookup[ti->options->type]); -switch (ti->options->kind) { +switch (ti->options->type) {case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH : - tpo = ti->options->passthrough; + tpo = ti->options->u.passthrough; monitor_printf(mon, "%s%s%s%s", tpo->has_path ? ",path=" : "", tpo->has_path ? tpo->path : "",
tpm.c +2 -2
@@ -260,9 +260,9 @@ static TPMInfo *qmp_query_tpm_inst(TPMBackend *drv)switch (drv->ops->type) {case TPM_TYPE_PASSTHROUGH : - res->options->kind =TPM_TYPE_OPTIONS_KIND_PASSTHROUGH ; + res->options->type =TPM_TYPE_OPTIONS_KIND_PASSTHROUGH ; tpo =g_new0 (TPMPassthroughOptions,1 ); - res->options->passthrough = tpo; + res->options->u.passthrough = tpo;if (drv->path) { tpo->path =g_strdup (drv->path); tpo->has_path = true;
Signature · 1 line
2.4.3
[Qemu-devel] [PULL v2 06/25] qapi: Reserve 'q_*' and 'has_*' member names
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
c_name() produces names starting with 'q_' when protecting a dictionary member name that would fail to directly compile, but in doing so can cause clashes with any member name already beginning with 'q-' or 'q_'. Likewise, we create a C name 'has_' for any optional member that can clash with any member name beginning with 'has-' or 'has_'.
Technically, rather than blindly reserving the namespace, we could try to complain about user names only when an actual collision occurs, or even teach c_name() how to munge names to avoid collisions. But it is not trivial, especially when collisions can occur across multiple types (such as via inheritance or flat unions). Besides, no existing .json files are trying to use these names. So it's easier to just outright forbid the potential for collision. We can always relax things in the future if a real need arises for QMP to express member names that have been forbidden here.
'has_' only has to be reserved for struct/union member names, while 'q_' is reserved everywhere (matching the fact that only members can be optional, while we use c_name() for munging both members and entities). Note that we could relax 'q_' restrictions on entities independently from member names; for example, c_name('qmp_' + 'unix') would result in a different function name than our current 'qmp_' + c_name('unix').
Update and add tests to cover the new error messages.
Message-Id: <[email protected]> [Consistently pass protect=False to c_name(); commit message tweaked slightly]
--- docs/qapi-code-gen.txt | 11 +++++++---- scripts/qapi.py | 8 +++++++- tests/qapi-schema/reserved-command-q.err | 1 + tests/qapi-schema/reserved-command-q.exit | 2 +- tests/qapi-schema/reserved-command-q.json | 6 ++---- tests/qapi-schema/reserved-command-q.out | 5 ----- tests/qapi-schema/reserved-member-has.err | 1 + tests/qapi-schema/reserved-member-has.exit | 2 +- tests/qapi-schema/reserved-member-has.json | 7 +++---- tests/qapi-schema/reserved-member-has.out | 6 ------ tests/qapi-schema/reserved-member-q.err | 1 + tests/qapi-schema/reserved-member-q.exit | 2 +- tests/qapi-schema/reserved-member-q.json | 6 ++---- tests/qapi-schema/reserved-member-q.out | 4 ---- 14 files changed, 27 insertions(+), 35 deletions(-)
docs/qapi-code-gen.txt +7 -4
@@ -112,7 +112,9 @@ and field names within a type, should be all lower case with words separated by a hyphen. However, some existing older commands and complex types use underscore; when extending such expressions, consistency is preferred over blindly avoiding underscore. Event -names should be ALL_CAPS with words separated by underscore. +names should be ALL_CAPS with words separated by underscore. Field +names cannot start with 'has-' or 'has_', as this is reserved for +tracking optional fields. Any name (command, event, type, field, or enum value) beginning with "x-" is marked experimental, and may be withdrawn or changed
@@ -123,9 +125,10 @@ vendor), even if the rest of the name uses dash (example: __com.redhat_drive-mirror). Other than downstream extensions (with leading underscore and the use of dots), all names should begin with a letter, and contain only ASCII letters, digits, dash, and underscore. -It is okay to reuse names that match C keywords; the generator will -rename a field named "default" in the QAPI to "q_default" in the -generated C code. +Names beginning with 'q_' are reserved for the generator: QMP names +that resemble C keywords or other problematic strings will be munged +in C to use this prefix. For example, a field named "default" in +qapi becomes "q_default" in the generated C code. In the rest of this document, usage lines are given for each expression type, with literal strings written in lower case and
scripts/qapi.py +7 -1
@@ -376,7 +376,9 @@ def check_name(expr_info, source, name, allow_optional=False, # code always prefixes it with the enum name if enum_member: membername = '_' + membername - if not valid_name.match(membername): + # Reserve the entire 'q_' namespace for c_name() + if not valid_name.match(membername) or \ + c_name(membername, False).startswith('q_'): raise QAPIExprError(expr_info, "%s uses invalid name '%s'" % (source, name))
@@ -488,6 +490,10 @@ def check_type(expr_info, source, value, allow_array=False, for (key, arg) in value.items(): check_name(expr_info, "Member of %s" % source, key, allow_optional=allow_optional) + if c_name(key, False).startswith('has_'): + raise QAPIExprError(expr_info, + "Member of %s uses reserved name '%s'" + % (source, key)) # Todo: allow dictionaries to represent default values of # an optional argument. check_type(expr_info, "Member '%s' of %s" % (key, source), arg,
tests/qapi-schema/reserved-command-q.err +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/reserved-command-q.json:5: 'command' uses invalid name 'q-unix'
tests/qapi-schema/reserved-command-q.exit +1 -1
@@ -1 +1 @@ -0 +1
tests/qapi-schema/reserved-command-q.json +2 -4
@@ -1,7 +1,5 @@ # C entity name collision -# FIXME - This parses, but fails to compile, because it attempts to declare -# two 'qmp_q_unix' functions (one for 'q-unix', the other because c_name() -# munges 'unix' to 'q_unix' to avoid reserved word collisions). We should -# reject attempts to explicitly use 'q_' names, to reserve it for qapi. +# We reject names like 'q-unix', because they can collide with the mangled +# name for 'unix' in generated C. { 'command': 'unix' } { 'command': 'q-unix' }
tests/qapi-schema/reserved-command-q.out +0 -5
@@ -1,5 +0,0 @@ -object :empty -command q-unix None -> None - gen=True success_response=True -command unix None -> None - gen=True success_response=True
tests/qapi-schema/reserved-member-has.err +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/reserved-member-has.json:5: Member of 'data' for command 'oops' uses reserved name 'has-a'
tests/qapi-schema/reserved-member-has.exit +1 -1
@@ -1 +1 @@ -0 +1
tests/qapi-schema/reserved-member-has.json +3 -4
@@ -1,6 +1,5 @@ # C member name collision -# FIXME - This parses, but fails to compile, because the C struct is given -# two 'has_a' members, one from the flag for optional 'a', and the other -# from member 'has-a'. Either reject this at parse time, or munge the C -# names to avoid the collision. +# We reject names like 'has-a', because they can collide with the flag +# for an optional 'a' in generated C. +# TODO we could munge the optional flag name to avoid the collision. { 'command': 'oops', 'data': { '*a': 'str', 'has-a': 'str' } }
tests/qapi-schema/reserved-member-has.out +0 -6
@@ -1,6 +0,0 @@ -object :empty -object :obj-oops-arg - member a: str optional=True - member has-a: str optional=False -command oops :obj-oops-arg -> None - gen=True success_response=True
tests/qapi-schema/reserved-member-q.err +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/reserved-member-q.json:4: Member of 'data' for struct 'Foo' uses invalid name 'q-unix'
tests/qapi-schema/reserved-member-q.exit +1 -1
@@ -1 +1 @@ -0 +1
tests/qapi-schema/reserved-member-q.json +2 -4
@@ -1,6 +1,4 @@ # C member name collision -# FIXME - This parses, but fails to compile, because it attempts to declare -# two 'q_unix' members (one for 'q-unix', the other because c_name() -# munges 'unix' to 'q_unix' to avoid reserved word collisions). We should -# reject attempts to explicitly use 'q_' names, to reserve it for qapi. +# We reject names like 'q-unix', because they can collide with the mangled +# name for 'unix' in generated C. { 'struct': 'Foo', 'data': { 'unix':'int', 'q-unix':'bool' } }
tests/qapi-schema/reserved-member-q.out +0 -4
@@ -1,4 +0,0 @@ -object :empty -object Foo - member unix: int optional=False - member q-unix: bool optional=False
Signature · 1 line
2.4.3
[Qemu-devel] [PULL v2 11/25] qapi: Unbox base members
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
Rather than storing a base class as a pointer to a box, just store the fields of that base class in the same order, so that a child struct can be directly cast to its parent. This gives less malloc overhead, less pointer dereferencing, and even less generated code. Compare to the earlier commit 1e6c1616a "qapi:
Generate a nicer struct for flat unions" (although that patch had fewer places to change, as less of qemu was directly using qapi structs for flat unions). It also allows us to turn on automatic type-safe wrappers for upcasting to the base class of a struct.
Changes to the generated code look like this in qapi-types.h:
| struct SpiceChannel {
|- SpiceBasicInfo *base;
|+ /* Members inherited from SpiceBasicInfo: */
|+ char *host;
|+ char *port;
|+ NetworkAddressFamily family;
|+ /* Own members: */
| int64_t connection_id;as well as additional upcast functions like qapi_SpiceChannel_base(). Meanwhile, changes to qapi-visit.c look like:
| static void visit_type_SpiceChannel_fields(Visitor *v, SpiceChannel **obj, Error **errp)
| {
| Error *err = NULL;
|
|- visit_type_implicit_SpiceBasicInfo(v, &(*obj)->base, &err);
|+ visit_type_SpiceBasicInfo_fields(v, (SpiceBasicInfo **)obj, &err);
| if (err) {(the cast is necessary, since our upcast wrappers only deal with a single pointer, not pointer-to-pointer); plus the wholesale elimination of some now-unused visit_type_implicit_FOO() functions.
Without boxing, the corner case of one empty struct having another empty struct as its base type now requires inserting a dummy member (previously, the 'Base *base' member sufficed).
And now that we no longer consume a 'base' member in the generated C struct, we can delete the former negative struct-base-clash-base test.
Message-Id: <[email protected]>
--- hmp.c | 6 +++--- scripts/qapi-types.py | 12 ++++-------- scripts/qapi-visit.py | 15 +++++++-------- tests/Makefile | 1 - tests/qapi-schema/struct-base-clash-base.err | 0 tests/qapi-schema/struct-base-clash-base.exit | 1 - tests/qapi-schema/struct-base-clash-base.json | 9 --------- tests/qapi-schema/struct-base-clash-base.out | 5 ----- tests/test-qmp-commands.c | 15 +++++---------- tests/test-qmp-event.c | 8 ++------ tests/test-qmp-input-visitor.c | 4 ++-- tests/test-qmp-output-visitor.c | 13 +++++-------- tests/test-visitor-serialization.c | 14 ++++++-------- ui/spice-core.c | 23 +++++++++++++---------- ui/vnc.c | 21 ++++++++++----------- 15 files changed, 57 insertions(+), 90 deletions(-) delete mode 100644 tests/qapi-schema/struct-base-clash-base.err delete mode 100644 tests/qapi-schema/struct-base-clash-base.exit delete mode 100644 tests/qapi-schema/struct-base-clash-base.json delete mode 100644 tests/qapi-schema/struct-base-clash-base.out
hmp.c +3 -3
@@ -569,8 +569,8 @@ void hmp_info_vnc(Monitor *mon, const QDict *qdict)for (client = info->clients; client; client = client->next) {monitor_printf (mon,"Client:\n" );monitor_printf (mon," address: %s:%s\n" , - client->value->base->host, - client->value->base->service); + client->value->host, + client->value->service);monitor_printf (mon," x509_dname: %s\n" , client->value->x509_dname ? client->value->x509_dname :"none" );
@@ -638,7 +638,7 @@ void hmp_info_spice(Monitor *mon, const QDict *qdict)for (chan = info->channels; chan; chan = chan->next) {monitor_printf (mon,"Channel:\n" );monitor_printf (mon," address: %s:%s%s\n" , - chan->value->base->host, chan->value->base->port, + chan->value->host, chan->value->port, chan->value->tls ?" [tls]" :"" );monitor_printf (mon," session: %" PRId64"\n" , chan->value->connection_id);
scripts/qapi-types.py +4 -8
@@ -77,16 +77,13 @@ struct %(c_name)s { ''', c_name=c_name(name)) - if base: - ret += gen_struct_field('base', base, False) - - ret += gen_struct_fields(members) + ret += gen_struct_fields(members, base) # Make sure that all structs have at least one field; this avoids # potential issues with attempting to malloc space for zero-length # structs in C, and also incompatibility with C++ (where an empty # struct is size 1). - if not base and not members: + if not (base and base.members) and not members: ret += mcgen(''' char qapi_dummy_field_for_empty_struct; ''')
@@ -280,11 +277,10 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): if variants: assert not members # not implemented self.decl += gen_union(name, base, variants) - # TODO Use gen_upcast on structs too, once they have sane layout - if base: - self.decl += gen_upcast(name, base) else: self.decl += gen_struct(name, base, members) + if base: + self.decl += gen_upcast(name, base) self._gen_type_cleanup(name) def visit_alternate_type(self, name, info, variants):
scripts/qapi-visit.py +7 -8
@@ -72,13 +72,12 @@ static void visit_type_implicit_%(c_type)s(Visitor *v, %(c_type)s **obj, Error * def gen_visit_struct_fields(name, base, members): + ret = '' + + if base: + ret += gen_visit_fields_decl(base) + struct_fields_seen.add(name) - - ret = '' - - if base: - ret += gen_visit_implicit_struct(base) - ret += mcgen(''' static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s **obj, Error **errp)
@@ -90,9 +89,9 @@ static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s **obj, Error **e if base: ret += mcgen(''' - visit_type_implicit_%(c_type)s(v, &(*obj)->%(c_name)s, &err); + visit_type_%(c_type)s_fields(v, (%(c_type)s **)obj, &err); ''', - c_type=base.c_name(), c_name=c_name('base')) + c_type=base.c_name()) ret += gen_err_check() ret += gen_visit_fields(members, prefix='(*obj)->')
tests/Makefile +0 -1
@@ -325,7 +325,6 @@ qapi-schema += returns-array-bad.json qapi-schema += returns-dict.json qapi-schema += returns-unknown.json qapi-schema += returns-whitelist.json -qapi-schema += struct-base-clash-base.json qapi-schema += struct-base-clash-deep.json qapi-schema += struct-base-clash.json qapi-schema += struct-data-invalid.json
tests/qapi-schema/struct-base-clash-base.err deleted +0 -0
tests/qapi-schema/struct-base-clash-base.exit deleted +0 -1
@@ -1 +0,0 @@ -0
tests/qapi-schema/struct-base-clash-base.json deleted +0 -9
@@ -1,9 +0,0 @@ -# Struct member 'base' -# FIXME: this parses, but then fails to compile due to a duplicate 'base' -# (one explicit in QMP, the other used to box the base class members). -# We should either reject the collision at parse time, or change the -# generated struct to allow this to compile. -{ 'struct': 'Base', 'data': {} } -{ 'struct': 'Sub', - 'base': 'Base', - 'data': { 'base': 'str' } }
tests/qapi-schema/struct-base-clash-base.out deleted +0 -5
@@ -1,5 +0,0 @@ -object :empty -object Base -object Sub - base Base - member base: str optional=False
tests/test-qmp-commands.c +5 -10
@@ -25,11 +25,9 @@ UserDefTwo *qmp_user_def_cmd2(UserDefOne *ud1a,UserDefOne *ud1d =g_malloc0 (sizeof (UserDefOne)); ud1c->string =strdup (ud1a->string); - ud1c->base =g_new0 (UserDefZero,1 ); - ud1c->base->integer = ud1a->base->integer; + ud1c->integer = ud1a->integer; ud1d->string =strdup (has_udb1 ? ud1b->string :"blah0" ); - ud1d->base =g_new0 (UserDefZero,1 ); - ud1d->base->integer = has_udb1 ? ud1b->base->integer :0 ; + ud1d->integer = has_udb1 ? ud1b->integer :0 ; ret =g_new0 (UserDefTwo,1 ); ret->string0 =strdup ("blah1" );
@@ -176,20 +174,17 @@ static void test_dealloc_types(void)UserDefOneList *ud1list; ud1test =g_malloc0 (sizeof (UserDefOne)); - ud1test->base =g_new0 (UserDefZero,1 ); - ud1test->base->integer =42 ; + ud1test->integer =42 ; ud1test->string =g_strdup ("hi there 42" );qapi_free_UserDefOne (ud1test); ud1a =g_malloc0 (sizeof (UserDefOne)); - ud1a->base =g_new0 (UserDefZero,1 ); - ud1a->base->integer =43 ; + ud1a->integer =43 ; ud1a->string =g_strdup ("hi there 43" ); ud1b =g_malloc0 (sizeof (UserDefOne)); - ud1b->base =g_new0 (UserDefZero,1 ); - ud1b->base->integer =44 ; + ud1b->integer =44 ; ud1b->string =g_strdup ("hi there 44" ); ud1list =g_malloc0 (sizeof (UserDefOneList));
tests/test-qmp-event.c +2 -6
@@ -179,9 +179,7 @@ static void test_event_c(TestEventData *data,QDict *d, *d_data, *d_b;UserDefOne b; -UserDefZero z; - z.integer =2 ; - b.base = &z; + b.integer =2 ; b.string =g_strdup ("test1" ); b.has_enum1 = false;
@@ -209,11 +207,9 @@ static void test_event_d(TestEventData *data, {UserDefOne struct1;EventStructOne a; -UserDefZero z;QDict *d, *d_data, *d_a, *d_struct1; - z.integer =2 ; - struct1.base = &z; + struct1.integer =2 ; struct1.string =g_strdup ("test1" ); struct1.has_enum1 = true; struct1.enum1 =ENUM_ONE_VALUE1 ;
tests/test-qmp-input-visitor.c +2 -2
@@ -262,7 +262,7 @@ static void test_visitor_in_struct_nested(TestInputVisitorData *data,check_and_free_str (udp->string0,"string0" );check_and_free_str (udp->dict1->string1,"string1" ); - g_assert_cmpint(udp->dict1->dict2->userdef->base->integer, ==, 42); + g_assert_cmpint(udp->dict1->dict2->userdef->integer, ==, 42);check_and_free_str (udp->dict1->dict2->userdef->string,"string" );check_and_free_str (udp->dict1->dict2->string,"string2" );g_assert (udp->dict1->has_dict3 == false);
@@ -292,7 +292,7 @@ static void test_visitor_in_list(TestInputVisitorData *data,snprintf (string,sizeof (string),"string%d" , i); g_assert_cmpstr(item->value->string, ==, string); - g_assert_cmpint(item->value->base->integer, ==, 42 + i); + g_assert_cmpint(item->value->integer, ==, 42 + i); }qapi_free_UserDefOneList (head);
tests/test-qmp-output-visitor.c +5 -8
@@ -250,16 +250,14 @@ static void test_visitor_out_struct_nested(TestOutputVisitorData *data, ud2->dict1->dict2 =g_malloc0 (sizeof (*ud2->dict1->dict2)); ud2->dict1->dict2->userdef =g_new0 (UserDefOne,1 ); ud2->dict1->dict2->userdef->string =g_strdup (string); - ud2->dict1->dict2->userdef->base =g_new0 (UserDefZero,1 ); - ud2->dict1->dict2->userdef->base->integer = value; + ud2->dict1->dict2->userdef->integer = value; ud2->dict1->dict2->string =g_strdup (strings[2 ]); ud2->dict1->dict3 =g_malloc0 (sizeof (*ud2->dict1->dict3)); ud2->dict1->has_dict3 = true; ud2->dict1->dict3->userdef =g_new0 (UserDefOne,1 ); ud2->dict1->dict3->userdef->string =g_strdup (string); - ud2->dict1->dict3->userdef->base =g_new0 (UserDefZero,1 ); - ud2->dict1->dict3->userdef->base->integer = value; + ud2->dict1->dict3->userdef->integer = value; ud2->dict1->dict3->string =g_strdup (strings[3 ]);visit_type_UserDefTwo (data->ov, &ud2,"unused" , &err);
@@ -301,8 +299,8 @@ static void test_visitor_out_struct_errors(TestOutputVisitorData *data, const void *unused) {EnumOne bad_values[] = {ENUM_ONE_MAX ,-1 }; -UserDefZero b; -UserDefOne u = { .base = &b }, *pu = &u; +UserDefOne u = {0 }; +UserDefOne *pu = &u;Error *err;int i;
@@ -416,8 +414,7 @@ static void test_visitor_out_list_qapi_free(TestOutputVisitorData *data, p->value->dict1->dict2 =g_new0 (UserDefTwoDictDict,1 ); p->value->dict1->dict2->userdef =g_new0 (UserDefOne,1 ); p->value->dict1->dict2->userdef->string =g_strdup (string); - p->value->dict1->dict2->userdef->base =g_new0 (UserDefZero,1 ); - p->value->dict1->dict2->userdef->base->integer =42 ; + p->value->dict1->dict2->userdef->integer =42 ; p->value->dict1->dict2->string =g_strdup (string); p->value->dict1->has_dict3 = false;
tests/test-visitor-serialization.c +6 -8
@@ -258,15 +258,13 @@ static UserDefTwo *nested_struct_create(void) udnp->dict1->string1 =strdup ("test_string1" ); udnp->dict1->dict2 =g_malloc0 (sizeof (*udnp->dict1->dict2)); udnp->dict1->dict2->userdef =g_new0 (UserDefOne,1 ); - udnp->dict1->dict2->userdef->base =g_new0 (UserDefZero,1 ); - udnp->dict1->dict2->userdef->base->integer =42 ; + udnp->dict1->dict2->userdef->integer =42 ; udnp->dict1->dict2->userdef->string =strdup ("test_string" ); udnp->dict1->dict2->string =strdup ("test_string2" ); udnp->dict1->dict3 =g_malloc0 (sizeof (*udnp->dict1->dict3)); udnp->dict1->has_dict3 = true; udnp->dict1->dict3->userdef =g_new0 (UserDefOne,1 ); - udnp->dict1->dict3->userdef->base =g_new0 (UserDefZero,1 ); - udnp->dict1->dict3->userdef->base->integer =43 ; + udnp->dict1->dict3->userdef->integer =43 ; udnp->dict1->dict3->userdef->string =strdup ("test_string" ); udnp->dict1->dict3->string =strdup ("test_string3" );return udnp;
@@ -278,15 +276,15 @@ static void nested_struct_compare(UserDefTwo *udnp1, UserDefTwo *udnp2)g_assert (udnp2); g_assert_cmpstr(udnp1->string0, ==, udnp2->string0); g_assert_cmpstr(udnp1->dict1->string1, ==, udnp2->dict1->string1); - g_assert_cmpint(udnp1->dict1->dict2->userdef->base->integer, ==, - udnp2->dict1->dict2->userdef->base->integer); + g_assert_cmpint(udnp1->dict1->dict2->userdef->integer, ==, + udnp2->dict1->dict2->userdef->integer); g_assert_cmpstr(udnp1->dict1->dict2->userdef->string, ==, udnp2->dict1->dict2->userdef->string); g_assert_cmpstr(udnp1->dict1->dict2->string, ==, udnp2->dict1->dict2->string);g_assert (udnp1->dict1->has_dict3 == udnp2->dict1->has_dict3); - g_assert_cmpint(udnp1->dict1->dict3->userdef->base->integer, ==, - udnp2->dict1->dict3->userdef->base->integer); + g_assert_cmpint(udnp1->dict1->dict3->userdef->integer, ==, + udnp2->dict1->dict3->userdef->integer); g_assert_cmpstr(udnp1->dict1->dict3->userdef->string, ==, udnp2->dict1->dict3->userdef->string); g_assert_cmpstr(udnp1->dict1->dict3->string, ==,
ui/spice-core.c +13 -10
@@ -200,8 +200,6 @@ static void channel_event(int event, SpiceChannelEventInfo *info) {SpiceServerInfo *server =g_malloc0 (sizeof (*server));SpiceChannel *client =g_malloc0 (sizeof (*client)); - server->base =g_malloc0 (sizeof (*server->base)); - client->base =g_malloc0 (sizeof (*client->base));/* * Spice server might have called us from spice worker thread
@@ -218,9 +216,11 @@ static void channel_event(int event, SpiceChannelEventInfo *info) }if (info->flags &SPICE_CHANNEL_EVENT_FLAG_ADDR_EXT ) { -add_addr_info (client->base, (struct sockaddr *)&info->paddr_ext, +add_addr_info (qapi_SpiceChannel_base (client), + (struct sockaddr *)&info->paddr_ext, info->plen_ext); -add_addr_info (server->base, (struct sockaddr *)&info->laddr_ext, +add_addr_info (qapi_SpiceServerInfo_base (server), + (struct sockaddr *)&info->laddr_ext, info->llen_ext); }else { error_report("spice: %s, extended address is expected",
@@ -229,7 +229,9 @@ static void channel_event(int event, SpiceChannelEventInfo *info)switch (event) {case SPICE_CHANNEL_EVENT_CONNECTED : -qapi_event_send_spice_connected (server->base, client->base, &error_abort); +qapi_event_send_spice_connected (qapi_SpiceServerInfo_base (server), +qapi_SpiceChannel_base (client), + &error_abort);break ;case SPICE_CHANNEL_EVENT_INITIALIZED :if (auth) {
@@ -242,7 +244,9 @@ static void channel_event(int event, SpiceChannelEventInfo *info)break ;case SPICE_CHANNEL_EVENT_DISCONNECTED :channel_list_del (info); -qapi_event_send_spice_disconnected (server->base, client->base, &error_abort); +qapi_event_send_spice_disconnected (qapi_SpiceServerInfo_base (server), +qapi_SpiceChannel_base (client), + &error_abort);break ;default :break ;
@@ -378,16 +382,15 @@ static SpiceChannelList *qmp_query_spice_channels(void) chan =g_malloc0 (sizeof (*chan)); chan->value =g_malloc0 (sizeof (*chan->value)); - chan->value->base =g_malloc0 (sizeof (*chan->value->base)); paddr = (struct sockaddr *)&item->info->paddr_ext; plen = item->info->plen_ext;getnameinfo (paddr, plen, host,sizeof (host), port,sizeof (port),NI_NUMERICHOST |NI_NUMERICSERV ); - chan->value->base->host =g_strdup (host); - chan->value->base->port =g_strdup (port); - chan->value->base->family =inet_netfamily (paddr->sa_family); + chan->value->host =g_strdup (host); + chan->value->port =g_strdup (port); + chan->value->family =inet_netfamily (paddr->sa_family); chan->value->connection_id = item->info->connection_id; chan->value->channel_type = item->info->type;
ui/vnc.c +10 -11
@@ -262,8 +262,8 @@ static VncServerInfo *vnc_server_info_get(VncDisplay *vd)Error *err =NULL ; info =g_malloc (sizeof (*info)); - info->base =g_malloc (sizeof (*info->base)); -vnc_init_basic_info_from_server_addr (vd->lsock, info->base, &err); +vnc_init_basic_info_from_server_addr (vd->lsock, +qapi_VncServerInfo_base (info), &err); info->has_auth = true; info->auth =g_strdup (vnc_auth_name (vd));if (err) {
@@ -300,8 +300,8 @@ static void vnc_client_cache_addr(VncState *client)Error *err =NULL ; client->info =g_malloc0 (sizeof (*client->info)); - client->info->base =g_malloc0 (sizeof (*client->info->base)); -vnc_init_basic_info_from_remote_addr (client->csock, client->info->base, +vnc_init_basic_info_from_remote_addr (client->csock, +qapi_VncClientInfo_base (client->info), &err);if (err) {qapi_free_VncClientInfo (client->info);
@@ -317,7 +317,6 @@ static void vnc_qmp_event(VncState *vs, QAPIEvent event)if (!vs->info) {return ; } -g_assert (vs->info->base); si =vnc_server_info_get (vs->vd);if (!si) {
@@ -326,7 +325,8 @@ static void vnc_qmp_event(VncState *vs, QAPIEvent event)switch (event) {case QAPI_EVENT_VNC_CONNECTED : -qapi_event_send_vnc_connected (si, vs->info->base, &error_abort); +qapi_event_send_vnc_connected (si,qapi_VncClientInfo_base (vs->info), + &error_abort);break ;case QAPI_EVENT_VNC_INITIALIZED :qapi_event_send_vnc_initialized (si, vs->info, &error_abort);
@@ -361,11 +361,10 @@ static VncClientInfo *qmp_query_vnc_client(const VncState *client) } info =g_malloc0 (sizeof (*info)); - info->base =g_malloc0 (sizeof (*info->base)); - info->base->host =g_strdup (host); - info->base->service =g_strdup (serv); - info->base->family =inet_netfamily (sa.ss_family); - info->base->websocket = client->websocket; + info->host =g_strdup (host); + info->service =g_strdup (serv); + info->family =inet_netfamily (sa.ss_family); + info->websocket = client->websocket;if (client->tls) { info->x509_dname =qcrypto_tls_session_get_peer_name (client->tls);
Signature · 1 line
2.4.3
[Qemu-devel] [PULL v2 15/25] tests: Convert to new qapi union layout
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
We have two issues with our qapi union layout:
1) Even though the QMP wire format spells the tag 'type', the C code spells it 'kind', requiring some hacks in the generator.
2) The C struct uses an anonymous union, which places all tag values in the same namespace as all non-variant members. This leads to spurious collisions if a tag value matches a non-variant member's name.
Make the conversion to the new layout for testsuite code.
Message-Id: <[email protected]>
--- tests/test-qmp-commands.c | 4 +-- tests/test-qmp-input-visitor.c | 78 ++++++++++++++++++++--------------------- tests/test-qmp-output-visitor.c | 42 +++++++++++----------- 3 files changed, 62 insertions(+), 62 deletions(-)
tests/test-qmp-commands.c +2 -2
@@ -62,8 +62,8 @@ __org_qemu_x_Union1 *qmp___org_qemu_x_command(__org_qemu_x_EnumList *a, {__org_qemu_x_Union1 *ret =g_new0 (__org_qemu_x_Union1,1 ); - ret->kind =ORG_QEMU_X_UNION1_KIND___ORG_QEMU_X_BRANCH ; - ret->__org_qemu_x_branch =strdup ("blah1" ); + ret->type =ORG_QEMU_X_UNION1_KIND___ORG_QEMU_X_BRANCH ; + ret->u.__org_qemu_x_branch =strdup ("blah1" );return ret; }
tests/test-qmp-input-visitor.c +39 -39
223 lines not on this page · raw message
tests/test-qmp-output-visitor.c +21 -21
145 lines not on this page · raw message
Signature · 1 line
2.4.3
[Qemu-devel] [PULL v2 17/25] sockets: Convert to new qapi union layout
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
We have two issues with our qapi union layout:
1) Even though the QMP wire format spells the tag 'type', the C code spells it 'kind', requiring some hacks in the generator.
2) The C struct uses an anonymous union, which places all tag values in the same namespace as all non-variant members. This leads to spurious collisions if a tag value matches a non-variant member's name.
Make the conversion to the new layout for socket-related code.
Message-Id: <[email protected]>
--- qemu-nbd.c | 16 +++++++------- ui/vnc.c | 44 ++++++++++++++++++------------------- util/qemu-sockets.c | 62 ++++++++++++++++++++++++++--------------------------- 3 files changed, 61 insertions(+), 61 deletions(-)
qemu-nbd.c +8 -8
@@ -362,17 +362,17 @@ static SocketAddress *nbd_build_socket_address(const char *sockpath, saddr =g_new0 (SocketAddress,1 );if (sockpath) { - saddr->kind =SOCKET_ADDRESS_KIND_UNIX ; - saddr->q_unix =g_new0 (UnixSocketAddress,1 ); - saddr->q_unix->path =g_strdup (sockpath); + saddr->type =SOCKET_ADDRESS_KIND_UNIX ; + saddr->u.q_unix =g_new0 (UnixSocketAddress,1 ); + saddr->u.q_unix->path =g_strdup (sockpath); }else { - saddr->kind =SOCKET_ADDRESS_KIND_INET ; - saddr->inet =g_new0 (InetSocketAddress,1 ); - saddr->inet->host =g_strdup (bindto); + saddr->type =SOCKET_ADDRESS_KIND_INET ; + saddr->u.inet =g_new0 (InetSocketAddress,1 ); + saddr->u.inet->host =g_strdup (bindto);if (port) { - saddr->inet->port =g_strdup (port); + saddr->u.inet->port =g_strdup (port); }else { - saddr->inet->port =g_strdup_printf ("%d" ,NBD_DEFAULT_PORT ); + saddr->u.inet->port =g_strdup_printf ("%d" ,NBD_DEFAULT_PORT ); } }
ui/vnc.c +22 -22
85 lines not on this page · raw message
util/qemu-sockets.c +31 -31
129 lines not on this page · raw message
Signature · 1 line
2.4.3
[Qemu-devel] [PULL v2 18/25] net: Convert to new qapi union layout
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
We have two issues with our qapi union layout:
1) Even though the QMP wire format spells the tag 'type', the C code spells it 'kind', requiring some hacks in the generator.
2) The C struct uses an anonymous union, which places all tag values in the same namespace as all non-variant members. This leads to spurious collisions if a tag value matches a non-variant member's name.
Make the conversion to the new layout for net-related code.
Message-Id: <[email protected]>
--- net/dump.c | 4 ++-- net/hub.c | 4 ++-- net/l2tpv3.c | 4 ++-- net/net.c | 24 ++++++++++++------------ net/slirp.c | 4 ++-- net/socket.c | 4 ++-- net/tap-win32.c | 4 ++-- net/tap.c | 8 ++++---- net/vde.c | 4 ++-- net/vhost-user.c | 4 ++-- 10 files changed, 32 insertions(+), 32 deletions(-)
net/dump.c +2 -2
@@ -187,8 +187,8 @@ int net_init_dump(const NetClientOptions *opts, const char *name,NetClientState *nc;DumpNetClient *dnc; -assert (opts->kind ==NET_CLIENT_OPTIONS_KIND_DUMP ); - dump = opts->dump; +assert (opts->type ==NET_CLIENT_OPTIONS_KIND_DUMP ); + dump = opts->u.dump;assert (peer);
net/hub.c +2 -2
@@ -285,9 +285,9 @@ int net_init_hubport(const NetClientOptions *opts, const char *name, {const NetdevHubPortOptions *hubport; -assert (opts->kind ==NET_CLIENT_OPTIONS_KIND_HUBPORT ); +assert (opts->type ==NET_CLIENT_OPTIONS_KIND_HUBPORT );assert (!peer); - hubport = opts->hubport; + hubport = opts->u.hubport;net_hub_add_port (hubport->hubid, name);return 0 ;
net/l2tpv3.c +2 -2
@@ -545,8 +545,8 @@ int net_init_l2tpv3(const NetClientOptions *opts, s->queue_tail =0 ; s->header_mismatch = false; -assert (opts->kind ==NET_CLIENT_OPTIONS_KIND_L2TPV3 ); - l2tpv3 = opts->l2tpv3; +assert (opts->type ==NET_CLIENT_OPTIONS_KIND_L2TPV3 ); + l2tpv3 = opts->u.l2tpv3;if (l2tpv3->has_ipv6 && l2tpv3->ipv6) { s->ipv6 = l2tpv3->ipv6;
net/net.c +12 -12
@@ -882,8 +882,8 @@ static int net_init_nic(const NetClientOptions *opts, const char *name,NICInfo *nd;const NetLegacyNicOptions *nic; -assert (opts->kind ==NET_CLIENT_OPTIONS_KIND_NIC ); - nic = opts->nic; +assert (opts->type ==NET_CLIENT_OPTIONS_KIND_NIC ); + nic = opts->u.nic; idx =nic_get_free_idx ();if (idx ==-1 || nb_nics >=MAX_NICS ) {
@@ -984,9 +984,9 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp) opts = netdev->opts; name = netdev->id; -if (opts->kind ==NET_CLIENT_OPTIONS_KIND_DUMP || - opts->kind ==NET_CLIENT_OPTIONS_KIND_NIC || - !net_client_init_fun[opts->kind]) { +if (opts->type ==NET_CLIENT_OPTIONS_KIND_DUMP || + opts->type ==NET_CLIENT_OPTIONS_KIND_NIC || + !net_client_init_fun[opts->type]) {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"type" ,"a netdev backend type" );return -1 ;
@@ -997,16 +997,16 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)/* missing optional values have been initialized to "all bits zero" */ name = net->has_id ? net->id : net->name; -if (opts->kind ==NET_CLIENT_OPTIONS_KIND_NONE ) { +if (opts->type ==NET_CLIENT_OPTIONS_KIND_NONE ) {return 0 ;/* nothing to do */ } -if (opts->kind ==NET_CLIENT_OPTIONS_KIND_HUBPORT ) { +if (opts->type ==NET_CLIENT_OPTIONS_KIND_HUBPORT ) {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"type" ,"a net type" );return -1 ; } -if (!net_client_init_fun[opts->kind]) { +if (!net_client_init_fun[opts->type]) {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"type" ,"a net backend type (maybe it is not compiled " "into this binary)" );
@@ -1014,17 +1014,17 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp) }/* Do not add to a vlan if it's a nic with a netdev= parameter. */ -if (opts->kind !=NET_CLIENT_OPTIONS_KIND_NIC || - !opts->nic->has_netdev) { +if (opts->type !=NET_CLIENT_OPTIONS_KIND_NIC || + !opts->u.nic->has_netdev) { peer =net_hub_add_port (net->has_vlan ? net->vlan :0 ,NULL ); } } -if (net_client_init_fun[opts->kind](opts, name, peer, errp) <0 ) { +if (net_client_init_fun[opts->type](opts, name, peer, errp) <0 ) {/* FIXME drop when all init functions store an Error */ if (errp && !*errp) {error_setg (errp,QERR_DEVICE_INIT_FAILED , - NetClientOptionsKind_lookup[opts->kind]); + NetClientOptionsKind_lookup[opts->type]); }return -1 ; }
net/slirp.c +2 -2
@@ -746,8 +746,8 @@ int net_init_slirp(const NetClientOptions *opts, const char *name,const NetdevUserOptions *user;const char **dnssearch; -assert (opts->kind ==NET_CLIENT_OPTIONS_KIND_USER ); - user = opts->user; +assert (opts->type ==NET_CLIENT_OPTIONS_KIND_USER ); + user = opts->u.user; vnet = user->has_net ?g_strdup (user->net) : user->has_ip ? g_strdup_printf("%s/24", user->ip) :
net/socket.c +2 -2
@@ -706,8 +706,8 @@ int net_init_socket(const NetClientOptions *opts, const char *name,Error *err =NULL ;const NetdevSocketOptions *sock; -assert (opts->kind ==NET_CLIENT_OPTIONS_KIND_SOCKET ); - sock = opts->socket; +assert (opts->type ==NET_CLIENT_OPTIONS_KIND_SOCKET ); + sock = opts->u.socket;if (sock->has_fd + sock->has_listen + sock->has_connect + sock->has_mcast + sock->has_udp !=1 ) {
net/tap-win32.c +2 -2
@@ -767,8 +767,8 @@ int net_init_tap(const NetClientOptions *opts, const char *name,/* FIXME error_setg(errp, ...) on failure */ const NetdevTapOptions *tap; -assert (opts->kind ==NET_CLIENT_OPTIONS_KIND_TAP ); - tap = opts->tap; +assert (opts->type ==NET_CLIENT_OPTIONS_KIND_TAP ); + tap = opts->u.tap;if (!tap->has_ifname) {error_report ("tap: no interface name" );
net/tap.c +4 -4
@@ -565,8 +565,8 @@ int net_init_bridge(const NetClientOptions *opts, const char *name,TAPState *s;int fd, vnet_hdr; -assert (opts->kind ==NET_CLIENT_OPTIONS_KIND_BRIDGE ); - bridge = opts->bridge; +assert (opts->type ==NET_CLIENT_OPTIONS_KIND_BRIDGE ); + bridge = opts->u.bridge; helper = bridge->has_helper ? bridge->helper :DEFAULT_BRIDGE_HELPER ; br = bridge->has_br ? bridge->br :DEFAULT_BRIDGE_INTERFACE ;
@@ -728,8 +728,8 @@ int net_init_tap(const NetClientOptions *opts, const char *name,const char *vhostfdname;char ifname[128 ]; -assert (opts->kind ==NET_CLIENT_OPTIONS_KIND_TAP ); - tap = opts->tap; +assert (opts->type ==NET_CLIENT_OPTIONS_KIND_TAP ); + tap = opts->u.tap; queues = tap->has_queues ? tap->queues :1 ; vhostfdname = tap->has_vhostfd ? tap->vhostfd :NULL ;
net/vde.c +2 -2
@@ -115,8 +115,8 @@ int net_init_vde(const NetClientOptions *opts, const char *name,/* FIXME error_setg(errp, ...) on failure */ const NetdevVdeOptions *vde; -assert (opts->kind ==NET_CLIENT_OPTIONS_KIND_VDE ); - vde = opts->vde; +assert (opts->type ==NET_CLIENT_OPTIONS_KIND_VDE ); + vde = opts->u.vde;/* missing optional values have been initialized to "all bits zero" */ if (net_vde_init(peer, "vde", name, vde->sock, vde->port, vde->group,
net/vhost-user.c +2 -2
@@ -301,8 +301,8 @@ int net_init_vhost_user(const NetClientOptions *opts, const char *name,const NetdevVhostUserOptions *vhost_user_opts;CharDriverState *chr; -assert (opts->kind ==NET_CLIENT_OPTIONS_KIND_VHOST_USER ); - vhost_user_opts = opts->vhost_user; +assert (opts->type ==NET_CLIENT_OPTIONS_KIND_VHOST_USER ); + vhost_user_opts = opts->u.vhost_user; chr =net_vhost_parse_chardev (vhost_user_opts, errp);if (!chr) {
Signature · 1 line
2.4.3
[Qemu-devel] [PULL v2 19/25] char: Convert to new qapi union layout
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
We have two issues with our qapi union layout:
1) Even though the QMP wire format spells the tag 'type', the C code spells it 'kind', requiring some hacks in the generator.
2) The C struct uses an anonymous union, which places all tag values in the same namespace as all non-variant members. This leads to spurious collisions if a tag value matches a non-variant member's name.
Make the conversion to the new layout for character-related code.
Message-Id: <[email protected]>
--- qemu-char.c | 164 +++++++++++++++++++++++++++--------------------------- spice-qemu-char.c | 12 ++-- 2 files changed, 88 insertions(+), 88 deletions(-)
qemu-char.c +82 -82
@@ -97,18 +97,18 @@ static int SocketAddress_to_str(char *dest, int max_len, const char *prefix, SocketAddress *addr, bool is_listen, bool is_telnet) { - switch (addr->kind) { + switch (addr->type) { case SOCKET_ADDRESS_KIND_INET: return snprintf(dest, max_len, "%s%s:%s:%s%s", prefix, - is_telnet ?"telnet" :"tcp" , addr->inet->host, - addr->inet->port, is_listen ? ",server" : ""); + is_telnet ?"telnet" :"tcp" , addr->u.inet->host, + addr->u.inet->port, is_listen ? ",server" : "");break ;case SOCKET_ADDRESS_KIND_UNIX :return snprintf (dest, max_len,"%sunix:%s%s" , prefix, - addr->q_unix->path, is_listen ?",server" :"" ); + addr->u.q_unix->path, is_listen ?",server" :"" );break ;case SOCKET_ADDRESS_KIND_FD : -return snprintf (dest, max_len,"%sfd:%s%s" , prefix, addr->fd->str, +return snprintf (dest, max_len,"%sfd:%s%s" , prefix, addr->u.fd->str, is_listen ?",server" :"" );break ;default :
@@ -661,7 +661,7 @@ static CharDriverState *qemu_chr_open_mux(const char *id, ChardevBackend *backend, ChardevReturn *ret, Error **errp) { -ChardevMux *mux = backend->mux; +ChardevMux *mux = backend->u.mux;CharDriverState *chr, *drv;MuxDriver *d;
@@ -1070,7 +1070,7 @@ static CharDriverState *qemu_chr_open_pipe(const char *id, ChardevReturn *ret, Error **errp) { -ChardevHostdev *opts = backend->pipe; +ChardevHostdev *opts = backend->u.pipe;int fd_in, fd_out;char filename_in[CHR_MAX_FILENAME_SIZE ];char filename_out[CHR_MAX_FILENAME_SIZE ];
@@ -1148,7 +1148,7 @@ static CharDriverState *qemu_chr_open_stdio(const char *id, ChardevReturn *ret, Error **errp) { -ChardevStdio *opts = backend->stdio; +ChardevStdio *opts = backend->u.stdio;CharDriverState *chr;struct sigaction act;
@@ -2147,7 +2147,7 @@ static CharDriverState *qemu_chr_open_pipe(const char *id, ChardevReturn *ret, Error **errp) { -ChardevHostdev *opts = backend->pipe; +ChardevHostdev *opts = backend->u.pipe;const char *filename = opts->device;CharDriverState *chr;WinCharState *s;
@@ -3202,7 +3202,7 @@ static CharDriverState *qemu_chr_open_ringbuf(const char *id, ChardevReturn *ret, Error **errp) { -ChardevRingbuf *opts = backend->ringbuf; +ChardevRingbuf *opts = backend->u.ringbuf;CharDriverState *chr;RingBufCharDriver *d;
@@ -3477,16 +3477,16 @@ static void qemu_chr_parse_file_out(QemuOpts *opts, ChardevBackend *backend,error_setg (errp,"chardev: file: no filename given" );return ; } - backend->file =g_new0 (ChardevFile,1 ); - backend->file->out =g_strdup (path); + backend->u.file =g_new0 (ChardevFile,1 ); + backend->u.file->out =g_strdup (path); }static void qemu_chr_parse_stdio (QemuOpts *opts,ChardevBackend *backend,Error **errp) { - backend->stdio =g_new0 (ChardevStdio,1 ); - backend->stdio->has_signal = true; - backend->stdio->signal =qemu_opt_get_bool (opts,"signal" , true); + backend->u.stdio =g_new0 (ChardevStdio,1 ); + backend->u.stdio->has_signal = true; + backend->u.stdio->signal =qemu_opt_get_bool (opts,"signal" , true); }#ifdef HAVE_CHARDEV_SERIAL
@@ -3499,8 +3499,8 @@ static void qemu_chr_parse_serial(QemuOpts *opts, ChardevBackend *backend,error_setg (errp,"chardev: serial/tty: no device path given" ); return; } - backend->serial =g_new0 (ChardevHostdev,1 ); - backend->serial->device =g_strdup (device); + backend->u.serial =g_new0 (ChardevHostdev,1 ); + backend->u.serial->device =g_strdup (device); }#endif
@@ -3514,8 +3514,8 @@ static void qemu_chr_parse_parallel(QemuOpts *opts, ChardevBackend *backend,error_setg (errp,"chardev: parallel: no device path given" ); return; } - backend->parallel =g_new0 (ChardevHostdev,1 ); - backend->parallel->device =g_strdup (device); + backend->u.parallel =g_new0 (ChardevHostdev,1 ); + backend->u.parallel->device =g_strdup (device); }#endif
@@ -3528,8 +3528,8 @@ static void qemu_chr_parse_pipe(QemuOpts *opts, ChardevBackend *backend,error_setg (errp,"chardev: pipe: no device path given" );return ; } - backend->pipe =g_new0 (ChardevHostdev,1 ); - backend->pipe->device =g_strdup (device); + backend->u.pipe =g_new0 (ChardevHostdev,1 ); + backend->u.pipe->device =g_strdup (device); } static void qemu_chr_parse_ringbuf(QemuOpts *opts, ChardevBackend *backend,
@@ -3537,12 +3537,12 @@ static void qemu_chr_parse_ringbuf(QemuOpts *opts, ChardevBackend *backend, {int val; - backend->ringbuf =g_new0 (ChardevRingbuf,1 ); + backend->u.ringbuf =g_new0 (ChardevRingbuf,1 ); val =qemu_opt_get_size (opts,"size" ,0 );if (val !=0 ) { - backend->ringbuf->has_size = true; - backend->ringbuf->size = val; + backend->u.ringbuf->has_size = true; + backend->u.ringbuf->size = val; } }
@@ -3555,8 +3555,8 @@ static void qemu_chr_parse_mux(QemuOpts *opts, ChardevBackend *backend,error_setg (errp,"chardev: mux: no chardev given" );return ; } - backend->mux =g_new0 (ChardevMux,1 ); - backend->mux->chardev =g_strdup (chardev); + backend->u.mux =g_new0 (ChardevMux,1 ); + backend->u.mux->chardev =g_strdup (chardev); } static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend,
@@ -3583,37 +3583,37 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend, } } - backend->socket =g_new0 (ChardevSocket,1 ); + backend->u.socket =g_new0 (ChardevSocket,1 ); - backend->socket->has_nodelay = true; - backend->socket->nodelay = do_nodelay; - backend->socket->has_server = true; - backend->socket->server = is_listen; - backend->socket->has_telnet = true; - backend->socket->telnet = is_telnet; - backend->socket->has_wait = true; - backend->socket->wait = is_waitconnect; - backend->socket->has_reconnect = true; - backend->socket->reconnect = reconnect; + backend->u.socket->has_nodelay = true; + backend->u.socket->nodelay = do_nodelay; + backend->u.socket->has_server = true; + backend->u.socket->server = is_listen; + backend->u.socket->has_telnet = true; + backend->u.socket->telnet = is_telnet; + backend->u.socket->has_wait = true; + backend->u.socket->wait = is_waitconnect; + backend->u.socket->has_reconnect = true; + backend->u.socket->reconnect = reconnect; addr =g_new0 (SocketAddress,1 );if (path) { - addr->kind =SOCKET_ADDRESS_KIND_UNIX ; - addr->q_unix =g_new0 (UnixSocketAddress,1 ); - addr->q_unix->path =g_strdup (path); + addr->type =SOCKET_ADDRESS_KIND_UNIX ; + addr->u.q_unix =g_new0 (UnixSocketAddress,1 ); + addr->u.q_unix->path =g_strdup (path); }else { - addr->kind =SOCKET_ADDRESS_KIND_INET ; - addr->inet =g_new0 (InetSocketAddress,1 ); - addr->inet->host =g_strdup (host); - addr->inet->port =g_strdup (port); - addr->inet->has_to =qemu_opt_get (opts,"to" ); - addr->inet->to =qemu_opt_get_number (opts,"to" ,0 ); - addr->inet->has_ipv4 =qemu_opt_get (opts,"ipv4" ); - addr->inet->ipv4 =qemu_opt_get_bool (opts,"ipv4" ,0 ); - addr->inet->has_ipv6 =qemu_opt_get (opts,"ipv6" ); - addr->inet->ipv6 =qemu_opt_get_bool (opts,"ipv6" ,0 ); + addr->type =SOCKET_ADDRESS_KIND_INET ; + addr->u.inet =g_new0 (InetSocketAddress,1 ); + addr->u.inet->host =g_strdup (host); + addr->u.inet->port =g_strdup (port); + addr->u.inet->has_to =qemu_opt_get (opts,"to" ); + addr->u.inet->to =qemu_opt_get_number (opts,"to" ,0 ); + addr->u.inet->has_ipv4 =qemu_opt_get (opts,"ipv4" ); + addr->u.inet->ipv4 =qemu_opt_get_bool (opts,"ipv4" ,0 ); + addr->u.inet->has_ipv6 =qemu_opt_get (opts,"ipv6" ); + addr->u.inet->ipv6 =qemu_opt_get_bool (opts,"ipv6" ,0 ); } - backend->socket->addr = addr; + backend->u.socket->addr = addr; } static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend,
@@ -3644,27 +3644,27 @@ static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend, has_local = true; } - backend->udp =g_new0 (ChardevUdp,1 ); + backend->u.udp =g_new0 (ChardevUdp,1 ); addr =g_new0 (SocketAddress,1 ); - addr->kind =SOCKET_ADDRESS_KIND_INET ; - addr->inet =g_new0 (InetSocketAddress,1 ); - addr->inet->host =g_strdup (host); - addr->inet->port =g_strdup (port); - addr->inet->has_ipv4 =qemu_opt_get (opts,"ipv4" ); - addr->inet->ipv4 =qemu_opt_get_bool (opts,"ipv4" ,0 ); - addr->inet->has_ipv6 =qemu_opt_get (opts,"ipv6" ); - addr->inet->ipv6 =qemu_opt_get_bool (opts,"ipv6" ,0 ); - backend->udp->remote = addr; + addr->type =SOCKET_ADDRESS_KIND_INET ; + addr->u.inet =g_new0 (InetSocketAddress,1 ); + addr->u.inet->host =g_strdup (host); + addr->u.inet->port =g_strdup (port); + addr->u.inet->has_ipv4 =qemu_opt_get (opts,"ipv4" ); + addr->u.inet->ipv4 =qemu_opt_get_bool (opts,"ipv4" ,0 ); + addr->u.inet->has_ipv6 =qemu_opt_get (opts,"ipv6" ); + addr->u.inet->ipv6 =qemu_opt_get_bool (opts,"ipv6" ,0 ); + backend->u.udp->remote = addr;if (has_local) { - backend->udp->has_local = true; + backend->u.udp->has_local = true; addr =g_new0 (SocketAddress,1 ); - addr->kind =SOCKET_ADDRESS_KIND_INET ; - addr->inet =g_new0 (InetSocketAddress,1 ); - addr->inet->host =g_strdup (localaddr); - addr->inet->port =g_strdup (localport); - backend->udp->local = addr; + addr->type =SOCKET_ADDRESS_KIND_INET ; + addr->u.inet =g_new0 (InetSocketAddress,1 ); + addr->u.inet->host =g_strdup (localaddr); + addr->u.inet->port =g_strdup (localport); + backend->u.udp->local = addr; } }
@@ -3737,7 +3737,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, } chr =NULL ; - backend->kind = cd->kind; + backend->type = cd->kind;if (cd->parse) { cd->parse (opts, backend, &local_err);if (local_err) {
@@ -3754,9 +3754,9 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,qapi_free_ChardevBackend (backend);qapi_free_ChardevReturn (ret); backend =g_new0 (ChardevBackend,1 ); - backend->mux =g_new0 (ChardevMux,1 ); - backend->kind =CHARDEV_BACKEND_KIND_MUX ; - backend->mux->chardev =g_strdup (bid); + backend->u.mux =g_new0 (ChardevMux,1 ); + backend->type =CHARDEV_BACKEND_KIND_MUX ; + backend->u.mux->chardev =g_strdup (bid); ret =qmp_chardev_add (id, backend, errp);if (!ret) { chr =qemu_chr_find (bid);
@@ -4048,7 +4048,7 @@ static CharDriverState *qmp_chardev_open_file(const char *id, ChardevReturn *ret, Error **errp) { -ChardevFile *file = backend->file; +ChardevFile *file = backend->u.file;HANDLE out;if (file->has_in) {
@@ -4070,7 +4070,7 @@ static CharDriverState *qmp_chardev_open_serial(const char *id, ChardevReturn *ret, Error **errp) { -ChardevHostdev *serial = backend->serial; +ChardevHostdev *serial = backend->u.serial;return qemu_chr_open_win_path (serial->device, errp); }
@@ -4093,7 +4093,7 @@ static CharDriverState *qmp_chardev_open_file(const char *id, ChardevReturn *ret, Error **errp) { -ChardevFile *file = backend->file; +ChardevFile *file = backend->u.file;int flags, in =-1 , out; flags =O_WRONLY |O_TRUNC |O_CREAT |O_BINARY ;
@@ -4120,7 +4120,7 @@ static CharDriverState *qmp_chardev_open_serial(const char *id, ChardevReturn *ret, Error **errp) { -ChardevHostdev *serial = backend->serial; +ChardevHostdev *serial = backend->u.serial;int fd; fd =qmp_chardev_open_file_source (serial->device,O_RDWR , errp);
@@ -4138,7 +4138,7 @@ static CharDriverState *qmp_chardev_open_parallel(const char *id, ChardevReturn *ret, Error **errp) { -ChardevHostdev *parallel = backend->parallel; +ChardevHostdev *parallel = backend->u.parallel;int fd; fd =qmp_chardev_open_file_source (parallel->device,O_RDWR , errp);
@@ -4183,7 +4183,7 @@ static CharDriverState *qmp_chardev_open_socket(const char *id, {CharDriverState *chr;TCPCharDriver *s; -ChardevSocket *sock = backend->socket; +ChardevSocket *sock = backend->u.socket;SocketAddress *addr = sock->addr;bool do_nodelay = sock->has_nodelay ? sock->nodelay : false;bool is_listen = sock->has_server ? sock->server : true;
@@ -4196,7 +4196,7 @@ static CharDriverState *qmp_chardev_open_socket(const char *id, s->fd =-1 ; s->listen_fd =-1 ; - s->is_unix = addr->kind ==SOCKET_ADDRESS_KIND_UNIX ; + s->is_unix = addr->type ==SOCKET_ADDRESS_KIND_UNIX ; s->is_listen = is_listen; s->is_telnet = is_telnet; s->do_nodelay = do_nodelay;
@@ -4250,7 +4250,7 @@ static CharDriverState *qmp_chardev_open_udp(const char *id, ChardevReturn *ret, Error **errp) { -ChardevUdp *udp = backend->udp; +ChardevUdp *udp = backend->u.udp;int fd; fd =socket_dgram (udp->remote, udp->local, errp);
@@ -4279,7 +4279,7 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,for (i = backends; i; i = i->next) { cd = i->data; -if (cd->kind == backend->kind) { +if (cd->kind == backend->type) { chr = cd->create (id, backend, ret, &local_err);if (local_err) {error_propagate (errp, local_err);
@@ -4297,9 +4297,9 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend, chr->label =g_strdup (id); chr->avail_connections = - (backend->kind ==CHARDEV_BACKEND_KIND_MUX ) ?MAX_MUX :1 ; + (backend->type ==CHARDEV_BACKEND_KIND_MUX ) ?MAX_MUX :1 ;if (!chr->filename) { - chr->filename =g_strdup (ChardevBackendKind_lookup[backend->kind]); + chr->filename =g_strdup (ChardevBackendKind_lookup[backend->type]); }if (!chr->explicit_be_open) {qemu_chr_be_event (chr,CHR_EVENT_OPENED );
spice-qemu-char.c +6 -6
@@ -301,7 +301,7 @@ static CharDriverState *qemu_chr_open_spice_vmc(const char *id, ChardevReturn *ret, Error **errp) { -const char *type = backend->spicevmc->type; +const char *type = backend->u.spicevmc->type;const char **psubtype =spice_server_char_device_recognized_subtypes ();for (; *psubtype !=NULL ; ++psubtype) {
@@ -324,7 +324,7 @@ static CharDriverState *qemu_chr_open_spice_port(const char *id, ChardevReturn *ret, Error **errp) { -const char *name = backend->spiceport->fqdn; +const char *name = backend->u.spiceport->fqdn;CharDriverState *chr;SpiceCharDriver *s;
@@ -362,8 +362,8 @@ static void qemu_chr_parse_spice_vmc(QemuOpts *opts, ChardevBackend *backend,error_setg (errp,"chardev: spice channel: no name given" );return ; } - backend->spicevmc =g_new0 (ChardevSpiceChannel,1 ); - backend->spicevmc->type =g_strdup (name); + backend->u.spicevmc =g_new0 (ChardevSpiceChannel,1 ); + backend->u.spicevmc->type =g_strdup (name); } static void qemu_chr_parse_spice_port(QemuOpts *opts, ChardevBackend *backend,
@@ -375,8 +375,8 @@ static void qemu_chr_parse_spice_port(QemuOpts *opts, ChardevBackend *backend,error_setg (errp,"chardev: spice port: no name given" );return ; } - backend->spiceport =g_new0 (ChardevSpicePort,1 ); - backend->spiceport->fqdn =g_strdup (name); + backend->u.spiceport =g_new0 (ChardevSpicePort,1 ); + backend->u.spiceport->fqdn =g_strdup (name); }static void register_types (void )
Signature · 1 line
2.4.3
[Qemu-devel] [PULL v2 24/25] qapi: Reserve 'u' member name
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
Now that we have separated union tag values from colliding with non-variant C names, by naming the union 'u', we should reserve this name for our use. Note that we want to forbid 'u' even in a struct with no variants, because it is possible for a future qemu release to extend QMP in a backwards-compatible manner while converting from a struct to a flat union. Fortunately, no existing clients were using this member name. If we ever find the need for QMP to have a member 'u', we could at that time relax things, perhaps by having c_name() munge the QMP member to 'q_u'.
Note that we cannot forbid 'u' everywhere (by adding the rejection code to check_name()), because the existing QKeyCode enum already uses it; therefore we only reserve it as a struct type member name.
Message-Id: <[email protected]>
--- scripts/qapi.py | 2 +- tests/Makefile | 1 + tests/qapi-schema/reserved-member-u.err | 1 + tests/qapi-schema/reserved-member-u.exit | 1 + tests/qapi-schema/reserved-member-u.json | 7 +++++++ tests/qapi-schema/reserved-member-u.out | 0 6 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/qapi-schema/reserved-member-u.err create mode 100644 tests/qapi-schema/reserved-member-u.exit create mode 100644 tests/qapi-schema/reserved-member-u.json create mode 100644 tests/qapi-schema/reserved-member-u.out
scripts/qapi.py +1 -1
@@ -490,7 +490,7 @@ def check_type(expr_info, source, value, allow_array=False, for (key, arg) in value.items(): check_name(expr_info, "Member of %s" % source, key, allow_optional=allow_optional) - if c_name(key, False).startswith('has_'): + if c_name(key, False) == 'u' or c_name(key, False).startswith('has_'): raise QAPIExprError(expr_info, "Member of %s uses reserved name '%s'" % (source, key))
tests/Makefile +1 -0
@@ -318,6 +318,7 @@ qapi-schema += redefined-type.json qapi-schema += reserved-command-q.json qapi-schema += reserved-member-has.json qapi-schema += reserved-member-q.json +qapi-schema += reserved-member-u.json qapi-schema += reserved-type-kind.json qapi-schema += reserved-type-list.json qapi-schema += returns-alternate.json
tests/qapi-schema/reserved-member-u.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/reserved-member-u.json:7: Member of 'data' for struct 'Oops' uses reserved name 'u'
tests/qapi-schema/reserved-member-u.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/reserved-member-u.json new file +7 -0
@@ -0,0 +1,7 @@ +# Potential C member name collision +# We reject use of 'u' as a member name, to allow it for internal use in +# putting union branch members in a separate namespace from QMP members. +# This is true even for non-unions, because it is possible to convert a +# struct to flat union while remaining backwards compatible in QMP. +# TODO - we could munge the member name to 'q_u' to avoid the collision +{ 'struct': 'Oops', 'data': { 'u': 'str' } }
tests/qapi-schema/reserved-member-u.out new file +0 -0
Signature · 1 line
2.4.3
[Qemu-devel] [PULL v2 16/25] block: Convert to new qapi union layout
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
We have two issues with our qapi union layout:
1) Even though the QMP wire format spells the tag 'type', the C code spells it 'kind', requiring some hacks in the generator.
2) The C struct uses an anonymous union, which places all tag values in the same namespace as all non-variant members. This leads to spurious collisions if a tag value matches a non-variant member's name.
Make the conversion to the new layout for block-related code.
Message-Id: <[email protected]>
--- block/nbd.c | 18 +++++++++--------- block/qcow2.c | 10 ++++------ block/vmdk.c | 6 +++--- blockdev.c | 47 ++++++++++++++++++++++++----------------------- 4 files changed, 40 insertions(+), 41 deletions(-)
block/nbd.c +9 -9
@@ -206,24 +206,24 @@ static SocketAddress *nbd_config(BDRVNBDState *s, QDict *options, char **export, saddr =g_new0 (SocketAddress,1 );if (qdict_haskey (options,"path" )) { - saddr->kind =SOCKET_ADDRESS_KIND_UNIX ; - saddr->q_unix =g_new0 (UnixSocketAddress,1 ); - saddr->q_unix->path =g_strdup (qdict_get_str (options,"path" )); + saddr->type =SOCKET_ADDRESS_KIND_UNIX ; + saddr->u.q_unix =g_new0 (UnixSocketAddress,1 ); + saddr->u.q_unix->path =g_strdup (qdict_get_str (options,"path" ));qdict_del (options,"path" ); }else { - saddr->kind =SOCKET_ADDRESS_KIND_INET ; - saddr->inet =g_new0 (InetSocketAddress,1 ); - saddr->inet->host =g_strdup (qdict_get_str (options,"host" )); + saddr->type =SOCKET_ADDRESS_KIND_INET ; + saddr->u.inet =g_new0 (InetSocketAddress,1 ); + saddr->u.inet->host =g_strdup (qdict_get_str (options,"host" ));if (!qdict_get_try_str (options,"port" )) { - saddr->inet->port =g_strdup_printf ("%d" ,NBD_DEFAULT_PORT ); + saddr->u.inet->port =g_strdup_printf ("%d" ,NBD_DEFAULT_PORT ); }else { - saddr->inet->port =g_strdup (qdict_get_str (options,"port" )); + saddr->u.inet->port =g_strdup (qdict_get_str (options,"port" )); }qdict_del (options,"host" );qdict_del (options,"port" ); } - s->client.is_unix = saddr->kind ==SOCKET_ADDRESS_KIND_UNIX ; + s->client.is_unix = saddr->type ==SOCKET_ADDRESS_KIND_UNIX ; *export =g_strdup (qdict_get_try_str (options,"export" ));if (*export) {
block/qcow2.c +4 -6
@@ -2738,18 +2738,16 @@ static ImageInfoSpecific *qcow2_get_specific_info(BlockDriverState *bs)ImageInfoSpecific *spec_info =g_new (ImageInfoSpecific,1 ); *spec_info = (ImageInfoSpecific ){ - .kind =IMAGE_INFO_SPECIFIC_KIND_QCOW2 , - { - .qcow2 =g_new (ImageInfoSpecificQCow2,1 ), - }, + .type =IMAGE_INFO_SPECIFIC_KIND_QCOW2 , + .u.qcow2 =g_new (ImageInfoSpecificQCow2,1 ), };if (s->qcow_version ==2 ) { - *spec_info->qcow2 = (ImageInfoSpecificQCow2 ){ + *spec_info->u.qcow2 = (ImageInfoSpecificQCow2 ){ .compat =g_strdup ("0.10" ), .refcount_bits = s->refcount_bits, }; }else if (s->qcow_version ==3 ) { - *spec_info->qcow2 = (ImageInfoSpecificQCow2 ){ + *spec_info->u.qcow2 = (ImageInfoSpecificQCow2 ){ .compat =g_strdup ("1.1" ), .lazy_refcounts = s->compatible_features &QCOW2_COMPAT_LAZY_REFCOUNTS ,
block/vmdk.c +3 -3
@@ -2161,19 +2161,19 @@ static ImageInfoSpecific *vmdk_get_specific_info(BlockDriverState *bs)ImageInfoList **next; *spec_info = (ImageInfoSpecific ){ - .kind =IMAGE_INFO_SPECIFIC_KIND_VMDK , + .type =IMAGE_INFO_SPECIFIC_KIND_VMDK , { .vmdk =g_new0 (ImageInfoSpecificVmdk,1 ), }, }; - *spec_info->vmdk = (ImageInfoSpecificVmdk ) { + *spec_info->u.vmdk = (ImageInfoSpecificVmdk ) { .create_type =g_strdup (s->create_type), .cid = s->cid, .parent_cid = s->parent_cid, }; - next = &spec_info->vmdk->extents; + next = &spec_info->u.vmdk->extents;for (i =0 ; i < s->num_extents; i++) { *next =g_new0 (ImageInfoList,1 ); (*next)->value =vmdk_get_extent_info (&s->extents[i]);
blockdev.c +24 -23
93 lines not on this page · raw message
Signature · 1 line
2.4.3
[Qemu-devel] [PULL v2 23/25] qapi: Finish converting to new qapi union layout
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
We have two issues with our qapi union layout:
1) Even though the QMP wire format spells the tag 'type', the C code spells it 'kind', requiring some hacks in the generator.
2) The C struct uses an anonymous union, which places all tag values in the same namespace as all non-variant members. This leads to spurious collisions if a tag value matches a non-variant member's name.
This patch is the back end for a series that converts to a saner qapi union layout. Now that all clients have been converted to use 'type' and 'obj->u.value', we can drop the temporary parallel support for 'kind' and 'obj->value'.
Given a simple union qapi type:
{ 'union':'Foo', 'data': { 'a':'int', 'b':'bool' } }
this is the overall effect, when compared to the state before this series of patches:
| struct Foo {
|- FooKind kind;
|- union { /* union tag is @kind */
|+ FooKind type;
|+ union { /* union tag is @type */
| void *data;
| int64_t a;
| bool b;
|- };
|+ } u;
| };The testsuite still contains some examples of artificial restrictions (see flat-union-clash-type.json, for example) that are no longer technically necessary, now that there is no longer a collision between enum tag values and non-variant member names; but fixing this will be done in later patches, in part because some further changes are required to keep QAPISchema*.check() from asserting. Also, a later patch will add a reservation for the member name 'u' to avoid a collision between a user's non-variant names and our internal choice of C union name.
Note, however, that we do not rename the generated enum, which is still 'FooKind'. A further patch could generate implicit enums as 'FooType', but while the generator already reserved the '*Kind' namespace (commit 4dc2e69), there are already QMP constructs with '*Type' naming, which means changing our reservation namespace would have lots of churn to C code to deal with a forced name change.
Message-Id: <[email protected]>
--- scripts/qapi-types.py | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-)
scripts/qapi-types.py +5 -21
@@ -149,23 +149,10 @@ struct %(c_name)s { if base: ret += gen_struct_fields([], base) else: - # TODO As a hack, we emit both 'kind' and 'type'. Ultimately, we - # want to use only 'type', but the conversion is large enough to - # require staging over several commits. - ret += mcgen(''' - union { - %(c_type)s kind; - %(c_type)s type; - }; -''', - c_type=c_name(variants.tag_member.type.name)) + ret += gen_struct_field(variants.tag_member.name, + variants.tag_member.type, + False) - # TODO As a hack, we emit the union twice, once as an anonymous union - # and once as a named union. Ultimately, we want to use only the - # named union version (as it avoids conflicts between tag values as - # branch names competing with non-variant QMP names), but the conversion - # is large enough to require staging over several commits. - tmp = '' # FIXME: What purpose does data serve, besides preventing a union that # has a branch named 'data'? We use it in qapi-visit.py to decide # whether to bypass the switch statement if visiting the discriminator
@@ -174,7 +161,7 @@ struct %(c_name)s { # should not be any data leaks even without a data pointer. Or, if # 'data' is merely added to guarantee we don't have an empty union, # shouldn't we enforce that at .json parse time? - tmp += mcgen(''' + ret += mcgen(''' union { /* union tag is @%(c_name)s */ void *data; ''',
@@ -183,17 +170,14 @@ struct %(c_name)s { for var in variants.variants: # Ugly special case for simple union TODO get rid of it typ = var.simple_union_type() or var.type - tmp += mcgen(''' + ret += mcgen(''' %(c_type)s %(c_name)s; ''', c_type=typ.c_type(), c_name=c_name(var.name)) - ret += tmp - ret += ' ' + '\n '.join(tmp.split('\n')) ret += mcgen(''' } u; - }; }; ''')
Signature · 1 line
2.4.3
[Qemu-devel] [PULL v2 25/25] qapi: Simplify gen_struct_field()
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
Rather than having all callers pass a name, type, and optional flag, have them instead pass a QAPISchemaObjectTypeMember which already has all that information.
No change to generated code.
Message-Id: <[email protected]>
--- scripts/qapi-types.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
scripts/qapi-types.py +7 -9
@@ -36,18 +36,18 @@ struct %(c_name)s { c_name=c_name(name), c_type=element_type.c_type()) -def gen_struct_field(name, typ, optional): +def gen_struct_field(member): ret = '' - if optional: + if member.optional: ret += mcgen(''' bool has_%(c_name)s; ''', - c_name=c_name(name)) + c_name=c_name(member.name)) ret += mcgen(''' %(c_type)s %(c_name)s; ''', - c_type=typ.c_type(), c_name=c_name(name)) + c_type=member.type.c_type(), c_name=c_name(member.name)) return ret
@@ -60,13 +60,13 @@ def gen_struct_fields(local_members, base=None): ''', c_name=base.c_name()) for memb in base.members: - ret += gen_struct_field(memb.name, memb.type, memb.optional) + ret += gen_struct_field(memb) ret += mcgen(''' /* Own members: */ ''') for memb in local_members: - ret += gen_struct_field(memb.name, memb.type, memb.optional) + ret += gen_struct_field(memb) return ret
@@ -149,9 +149,7 @@ struct %(c_name)s { if base: ret += gen_struct_fields([], base) else: - ret += gen_struct_field(variants.tag_member.name, - variants.tag_member.type, - False) + ret += gen_struct_field(variants.tag_member) # FIXME: What purpose does data serve, besides preventing a union that # has a branch named 'data'? We use it in qapi-visit.py to decide
Signature · 1 line
2.4.3
[Qemu-devel] [PULL v2 20/25] input: Convert to new qapi union layout
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
We have two issues with our qapi union layout:
1) Even though the QMP wire format spells the tag 'type', the C code spells it 'kind', requiring some hacks in the generator.
2) The C struct uses an anonymous union, which places all tag values in the same namespace as all non-variant members. This leads to spurious collisions if a tag value matches a non-variant member's name.
Make the conversion to the new layout for input-related code.
Message-Id: <[email protected]>
--- hmp.c | 8 ++--- hw/char/escc.c | 12 +++---- hw/input/hid.c | 32 ++++++++--------- hw/input/ps2.c | 24 ++++++------- hw/input/virtio-input-hid.c | 27 ++++++++------- ui/console.c | 20 +++++------ ui/input-keymap.c | 20 +++++------ ui/input-legacy.c | 21 ++++++------ ui/input.c | 84 ++++++++++++++++++++++----------------------- 9 files changed, 125 insertions(+), 123 deletions(-)
hmp.c +4 -4
@@ -1735,15 +1735,15 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict)if (*endp !='\0' ) { goto err_out; } - keylist->value->kind =KEY_VALUE_KIND_NUMBER ; - keylist->value->number = value; + keylist->value->type =KEY_VALUE_KIND_NUMBER ; + keylist->value->u.number = value; }else {int idx =index_from_key (keyname_buf);if (idx ==Q_KEY_CODE_MAX ) { goto err_out; } - keylist->value->kind =KEY_VALUE_KIND_QCODE ; - keylist->value->qcode = idx; + keylist->value->type =KEY_VALUE_KIND_QCODE ; + keylist->value->u.qcode = idx; }if (!separator) {
hw/char/escc.c +6 -6
@@ -842,13 +842,13 @@ static void sunkbd_handle_event(DeviceState *dev, QemuConsole *src,ChannelState *s = (ChannelState *)dev;int qcode, keycode; -assert (evt->kind ==INPUT_EVENT_KIND_KEY ); - qcode =qemu_input_key_value_to_qcode (evt->key->key); +assert (evt->type ==INPUT_EVENT_KIND_KEY ); + qcode =qemu_input_key_value_to_qcode (evt->u.key->key);trace_escc_sunkbd_event_in (qcode, QKeyCode_lookup[qcode], - evt->key->down); + evt->u.key->down);if (qcode ==Q_KEY_CODE_CAPS_LOCK ) { -if (evt->key->down) { +if (evt->u.key->down) { s->caps_lock_mode ^=1 ;if (s->caps_lock_mode ==2 ) {return ;/* Drop second press */
@@ -862,7 +862,7 @@ static void sunkbd_handle_event(DeviceState *dev, QemuConsole *src, }if (qcode ==Q_KEY_CODE_NUM_LOCK ) { -if (evt->key->down) { +if (evt->u.key->down) { s->num_lock_mode ^=1 ;if (s->num_lock_mode ==2 ) {return ;/* Drop second press */
@@ -876,7 +876,7 @@ static void sunkbd_handle_event(DeviceState *dev, QemuConsole *src, } keycode = qcode_to_keycode[qcode]; -if (!evt->key->down) { +if (!evt->u.key->down) { keycode |=0x80 ; }trace_escc_sunkbd_event_out (keycode);
hw/input/hid.c +16 -16
@@ -119,33 +119,33 @@ static void hid_pointer_event(DeviceState *dev, QemuConsole *src,assert (hs->n <QUEUE_LENGTH ); e = &hs->ptr.queue[(hs->head + hs->n) &QUEUE_MASK ]; -switch (evt->kind) { +switch (evt->type) {case INPUT_EVENT_KIND_REL : -if (evt->rel->axis ==INPUT_AXIS_X ) { - e->xdx += evt->rel->value; - }else if (evt->rel->axis ==INPUT_AXIS_Y ) { - e->ydy += evt->rel->value; +if (evt->u.rel->axis ==INPUT_AXIS_X ) { + e->xdx += evt->u.rel->value; + }else if (evt->u.rel->axis ==INPUT_AXIS_Y ) { + e->ydy += evt->u.rel->value; }break ;case INPUT_EVENT_KIND_ABS : -if (evt->rel->axis ==INPUT_AXIS_X ) { - e->xdx = evt->rel->value; - }else if (evt->rel->axis ==INPUT_AXIS_Y ) { - e->ydy = evt->rel->value; +if (evt->u.rel->axis ==INPUT_AXIS_X ) { + e->xdx = evt->u.rel->value; + }else if (evt->u.rel->axis ==INPUT_AXIS_Y ) { + e->ydy = evt->u.rel->value; }break ;case INPUT_EVENT_KIND_BTN : -if (evt->btn->down) { - e->buttons_state |= bmap[evt->btn->button]; -if (evt->btn->button ==INPUT_BUTTON_WHEEL_UP ) { +if (evt->u.btn->down) { + e->buttons_state |= bmap[evt->u.btn->button]; +if (evt->u.btn->button ==INPUT_BUTTON_WHEEL_UP ) { e->dz--; - }else if (evt->btn->button ==INPUT_BUTTON_WHEEL_DOWN ) { + }else if (evt->u.btn->button ==INPUT_BUTTON_WHEEL_DOWN ) { e->dz++; } }else { - e->buttons_state &= ~bmap[evt->btn->button]; + e->buttons_state &= ~bmap[evt->u.btn->button]; }break ;
@@ -223,8 +223,8 @@ static void hid_keyboard_event(DeviceState *dev, QemuConsole *src,int scancodes[3 ], i, count;int slot; - count =qemu_input_key_value_to_scancode (evt->key->key, - evt->key->down, + count =qemu_input_key_value_to_scancode (evt->u.key->key, + evt->u.key->down, scancodes);if (hs->n + count >QUEUE_LENGTH ) {fprintf (stderr,"usb-kbd: warning: key event queue full\n" );
hw/input/ps2.c +12 -12
@@ -183,8 +183,8 @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src,int scancodes[3 ], i, count;qemu_system_wakeup_request (QEMU_WAKEUP_REASON_OTHER ); - count =qemu_input_key_value_to_scancode (evt->key->key, - evt->key->down, + count =qemu_input_key_value_to_scancode (evt->u.key->key, + evt->u.key->down, scancodes);for (i =0 ; i < count; i++) {ps2_put_keycode (s, scancodes[i]);
@@ -393,25 +393,25 @@ static void ps2_mouse_event(DeviceState *dev, QemuConsole *src,if (!(s->mouse_status &MOUSE_STATUS_ENABLED ))return ; -switch (evt->kind) { +switch (evt->type) {case INPUT_EVENT_KIND_REL : -if (evt->rel->axis ==INPUT_AXIS_X ) { - s->mouse_dx += evt->rel->value; - }else if (evt->rel->axis ==INPUT_AXIS_Y ) { - s->mouse_dy -= evt->rel->value; +if (evt->u.rel->axis ==INPUT_AXIS_X ) { + s->mouse_dx += evt->u.rel->value; + }else if (evt->u.rel->axis ==INPUT_AXIS_Y ) { + s->mouse_dy -= evt->u.rel->value; }break ;case INPUT_EVENT_KIND_BTN : -if (evt->btn->down) { - s->mouse_buttons |= bmap[evt->btn->button]; -if (evt->btn->button ==INPUT_BUTTON_WHEEL_UP ) { +if (evt->u.btn->down) { + s->mouse_buttons |= bmap[evt->u.btn->button]; +if (evt->u.btn->button ==INPUT_BUTTON_WHEEL_UP ) { s->mouse_dz--; - }else if (evt->btn->button ==INPUT_BUTTON_WHEEL_DOWN ) { + }else if (evt->u.btn->button ==INPUT_BUTTON_WHEEL_DOWN ) { s->mouse_dz++; } }else { - s->mouse_buttons &= ~bmap[evt->btn->button]; + s->mouse_buttons &= ~bmap[evt->u.btn->button]; }break ;
hw/input/virtio-input-hid.c +14 -13
@@ -191,44 +191,45 @@ static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src,virtio_input_event event;int qcode; -switch (evt->kind) { +switch (evt->type) {case INPUT_EVENT_KIND_KEY : - qcode =qemu_input_key_value_to_qcode (evt->key->key); + qcode =qemu_input_key_value_to_qcode (evt->u.key->key);if (qcode && keymap_qcode[qcode]) { event.type =cpu_to_le16 (EV_KEY ); event.code =cpu_to_le16 (keymap_qcode[qcode]); - event.value =cpu_to_le32 (evt->key->down ?1 :0 ); + event.value =cpu_to_le32 (evt->u.key->down ?1 :0 );virtio_input_send (vinput, &event); }else { -if (evt->key->down) { +if (evt->u.key->down) {fprintf (stderr,"%s: unmapped key: %d [%s]\n" , __func__, qcode, QKeyCode_lookup[qcode]); } }break ;case INPUT_EVENT_KIND_BTN : -if (keymap_button[evt->btn->button]) { +if (keymap_button[evt->u.btn->button]) { event.type =cpu_to_le16 (EV_KEY ); - event.code =cpu_to_le16 (keymap_button[evt->btn->button]); - event.value =cpu_to_le32 (evt->btn->down ?1 :0 ); + event.code =cpu_to_le16 (keymap_button[evt->u.btn->button]); + event.value =cpu_to_le32 (evt->u.btn->down ?1 :0 );virtio_input_send (vinput, &event); }else { -if (evt->btn->down) { +if (evt->u.btn->down) {fprintf (stderr,"%s: unmapped button: %d [%s]\n" , __func__, - evt->btn->button, InputButton_lookup[evt->btn->button]); + evt->u.btn->button, + InputButton_lookup[evt->u.btn->button]); } }break ;case INPUT_EVENT_KIND_REL : event.type =cpu_to_le16 (EV_REL ); - event.code =cpu_to_le16 (axismap_rel[evt->rel->axis]); - event.value =cpu_to_le32 (evt->rel->value); + event.code =cpu_to_le16 (axismap_rel[evt->u.rel->axis]); + event.value =cpu_to_le32 (evt->u.rel->value);virtio_input_send (vinput, &event);break ;case INPUT_EVENT_KIND_ABS : event.type =cpu_to_le16 (EV_ABS ); - event.code =cpu_to_le16 (axismap_abs[evt->abs->axis]); - event.value =cpu_to_le32 (evt->abs->value); + event.code =cpu_to_le16 (axismap_abs[evt->u.abs->axis]); + event.value =cpu_to_le32 (evt->u.abs->value);virtio_input_send (vinput, &event);break ;default :
ui/console.c +10 -10
@@ -2016,7 +2016,7 @@ static VcHandler *vc_handler = text_console_init;static CharDriverState *vc_init (const char *id,ChardevBackend *backend,ChardevReturn *ret,Error **errp) { -return vc_handler (backend->vc, errp); +return vc_handler (backend->u.vc, errp); }void register_vc_handler (VcHandler *handler)
@@ -2057,30 +2057,30 @@ static void qemu_chr_parse_vc(QemuOpts *opts, ChardevBackend *backend, {int val; - backend->vc =g_new0 (ChardevVC,1 ); + backend->u.vc =g_new0 (ChardevVC,1 ); val =qemu_opt_get_number (opts,"width" ,0 );if (val !=0 ) { - backend->vc->has_width = true; - backend->vc->width = val; + backend->u.vc->has_width = true; + backend->u.vc->width = val; } val =qemu_opt_get_number (opts,"height" ,0 );if (val !=0 ) { - backend->vc->has_height = true; - backend->vc->height = val; + backend->u.vc->has_height = true; + backend->u.vc->height = val; } val =qemu_opt_get_number (opts,"cols" ,0 );if (val !=0 ) { - backend->vc->has_cols = true; - backend->vc->cols = val; + backend->u.vc->has_cols = true; + backend->u.vc->cols = val; } val =qemu_opt_get_number (opts,"rows" ,0 );if (val !=0 ) { - backend->vc->has_rows = true; - backend->vc->rows = val; + backend->u.vc->has_rows = true; + backend->u.vc->rows = val; } }
ui/input-keymap.c +10 -10
@@ -139,11 +139,11 @@ static int number_to_qcode[0x100];int qemu_input_key_value_to_number (const KeyValue *value) { -if (value->kind ==KEY_VALUE_KIND_QCODE ) { -return qcode_to_number[value->qcode]; +if (value->type ==KEY_VALUE_KIND_QCODE ) { +return qcode_to_number[value->u.qcode]; }else { -assert (value->kind ==KEY_VALUE_KIND_NUMBER ); -return value->number; +assert (value->type ==KEY_VALUE_KIND_NUMBER ); +return value->u.number; } }
@@ -166,11 +166,11 @@ int qemu_input_key_number_to_qcode(uint8_t nr)int qemu_input_key_value_to_qcode (const KeyValue *value) { -if (value->kind ==KEY_VALUE_KIND_QCODE ) { -return value->qcode; +if (value->type ==KEY_VALUE_KIND_QCODE ) { +return value->u.qcode; }else { -assert (value->kind ==KEY_VALUE_KIND_NUMBER ); -return qemu_input_key_number_to_qcode (value->number); +assert (value->type ==KEY_VALUE_KIND_NUMBER ); +return qemu_input_key_number_to_qcode (value->u.number); } }
@@ -180,8 +180,8 @@ int qemu_input_key_value_to_scancode(const KeyValue *value, bool down,int keycode =qemu_input_key_value_to_number (value);int count =0 ; -if (value->kind ==KEY_VALUE_KIND_QCODE && - value->qcode ==Q_KEY_CODE_PAUSE ) { +if (value->type ==KEY_VALUE_KIND_QCODE && + value->u.qcode ==Q_KEY_CODE_PAUSE ) {/* specific case */ int v = down ?0 :0x80 ; codes[count++] =0xe1 ;
ui/input-legacy.c +11 -10
@@ -113,8 +113,8 @@ static void legacy_kbd_event(DeviceState *dev, QemuConsole *src,if (!entry || !entry->put_kbd) {return ; } - count =qemu_input_key_value_to_scancode (evt->key->key, - evt->key->down, + count =qemu_input_key_value_to_scancode (evt->u.key->key, + evt->u.key->down, scancodes);for (i =0 ; i < count; i++) { entry->put_kbd (entry->opaque, scancodes[i]);
@@ -150,21 +150,22 @@ static void legacy_mouse_event(DeviceState *dev, QemuConsole *src, };QEMUPutMouseEntry *s = (QEMUPutMouseEntry *)dev; -switch (evt->kind) { +switch (evt->type) {case INPUT_EVENT_KIND_BTN : -if (evt->btn->down) { - s->buttons |= bmap[evt->btn->button]; +if (evt->u.btn->down) { + s->buttons |= bmap[evt->u.btn->button]; }else { - s->buttons &= ~bmap[evt->btn->button]; + s->buttons &= ~bmap[evt->u.btn->button]; } -if (evt->btn->down && evt->btn->button ==INPUT_BUTTON_WHEEL_UP ) { +if (evt->u.btn->down && evt->u.btn->button ==INPUT_BUTTON_WHEEL_UP ) { s->qemu_put_mouse_event (s->qemu_put_mouse_event_opaque, s->axis[INPUT_AXIS_X ], s->axis[INPUT_AXIS_Y ],-1 , s->buttons); } -if (evt->btn->down && evt->btn->button ==INPUT_BUTTON_WHEEL_DOWN ) { +if (evt->u.btn->down && + evt->u.btn->button ==INPUT_BUTTON_WHEEL_DOWN ) { s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque, s->axis[INPUT_AXIS_X], s->axis[INPUT_AXIS_Y],
@@ -173,10 +174,10 @@ static void legacy_mouse_event(DeviceState *dev, QemuConsole *src, }break ;case INPUT_EVENT_KIND_ABS : - s->axis[evt->abs->axis] = evt->abs->value; + s->axis[evt->u.abs->axis] = evt->u.abs->value;break ;case INPUT_EVENT_KIND_REL : - s->axis[evt->rel->axis] += evt->rel->value; + s->axis[evt->u.rel->axis] += evt->u.rel->value;break ;default :break ;
ui/input.c +42 -42
164 lines not on this page · raw message
Signature · 1 line
2.4.3
[Qemu-devel] [PULL v2 21/25] memory: Convert to new qapi union layout
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
We have two issues with our qapi union layout:
1) Even though the QMP wire format spells the tag 'type', the C code spells it 'kind', requiring some hacks in the generator.
2) The C struct uses an anonymous union, which places all tag values in the same namespace as all non-variant members. This leads to spurious collisions if a tag value matches a non-variant member's name.
Make the conversion to the new layout for memory-related code.
Message-Id: <[email protected]>
--- hmp.c | 6 +++--- hw/mem/pc-dimm.c | 6 +++--- numa.c | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-)
hmp.c +3 -3
@@ -1958,12 +1958,12 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) value = info->value;if (value) { -switch (value->kind) { +switch (value->type) {case MEMORY_DEVICE_INFO_KIND_DIMM : - di = value->dimm; + di = value->u.dimm;monitor_printf (mon,"Memory device [%s]: \"%s\"\n" , - MemoryDeviceInfoKind_lookup[value->kind], + MemoryDeviceInfoKind_lookup[value->type], di->id ? di->id :"" );monitor_printf (mon," addr: 0x%" PRIx64"\n" , di->addr);monitor_printf (mon," slot: %" PRId64"\n" , di->slot);
hw/mem/pc-dimm.c +3 -3
@@ -179,7 +179,7 @@ int qmp_pc_dimm_device_list(Object *obj, void *opaque) NULL); di->memdev =object_get_canonical_path (OBJECT (dimm->hostmem)); - info->dimm = di; + info->u.dimm = di; elem->value = info; elem->next =NULL ; **prev = elem;
@@ -203,9 +203,9 @@ ram_addr_t get_current_ram_size(void)MemoryDeviceInfo *value = info->value;if (value) { -switch (value->kind) { +switch (value->type) {case MEMORY_DEVICE_INFO_KIND_DIMM : - size += value->dimm->size; + size += value->u.dimm->size;break ;default :break ;
numa.c +4 -4
@@ -226,9 +226,9 @@ static int parse_numa(void *opaque, QemuOpts *opts, Error **errp) goto error; } -switch (object->kind) { +switch (object->type) {case NUMA_OPTIONS_KIND_NODE : -numa_node_parse (object->node, opts, &err); +numa_node_parse (object->u.node, opts, &err);if (err) { goto error; }
@@ -487,9 +487,9 @@ static void numa_stat_memory_devices(uint64_t node_mem[])MemoryDeviceInfo *value = info->value;if (value) { -switch (value->kind) { +switch (value->type) {case MEMORY_DEVICE_INFO_KIND_DIMM : - node_mem[value->dimm->node] += value->dimm->size; + node_mem[value->u.dimm->node] += value->u.dimm->size;break ;default :break ;
Signature · 1 line
2.4.3
Peter Maydell
AppliedQuoted 11 lines · Markus Armbruster
v2:
* Squashed Eric's build fix.
* Moved Dan's fix to the front, to make merging it easier in case something's still wrong with Eric's patches.The following changes since commit
3a958f559ecd0511583d27b10011fa7f3cf79b63:Merge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' into staging (2015-10-30 19:47:47 +0000)
are available in the git repository at:
Quoted 9 lines
git://repo.or.cz/qemu/armbru.gittags/pull-qapi-2015-11-02for you to fetch changes up to
32bc6879beea0b0cac6196cb15a71d206401e96d:qapi: Simplify
gen_struct_field()(2015-11-02 08:30:28 +0100)----------------------------------------------------------------
QAPI patches
Applied, thanks.
-- PMM