qapi: Fix error handling code on alternate conflict
The conflict check added by commit c0644771 ("qapi: Reject alternates that can't work with keyval_parse()") doesn't work with the following declaration: { 'alternate': 'Alt', 'data': { 'one': 'bool', 'two': 'str' } } It crashes with: Traceback (most recent call last): File "./scripts/qapi-types.py", line 295, in <module> schema = QAPISchema(input_file) File "/home/ehabkost/rh/proj/virt/qemu/scripts/qapi.py", line 1468, in __init__ self.exprs = check_exprs(parser.exprs) File "/home/ehabkost/rh/proj/virt/qemu/scripts/qapi.py", line 958, in check_exprs check_alternate(expr, info) File "/home/ehabkost/rh/proj/virt/qemu/scripts/qapi.py", line 830, in check_alternate % (name, key, types_seen[qtype])) KeyError: 'QTYPE_QSTRING' This happens because the previously-seen conflicting member ('one') can't be found at types_seen[qtype], but at types_seen['QTYPE_BOOL']. Fix the bug by moving the error check to the same loop that adds new items to types_seen, raising an exception if types_seen[qt] is already set. Add two additional test cases that can detect the bug. Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> Message-Id: <20170717180926.14924-1-ehabkost@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
223cd0e13f
commit
fda72ab451
@ -825,11 +825,11 @@ def check_alternate(expr, info):
|
||||
else:
|
||||
conflicting.add('QTYPE_QNUM')
|
||||
conflicting.add('QTYPE_QBOOL')
|
||||
if conflicting & set(types_seen):
|
||||
raise QAPISemError(info, "Alternate '%s' member '%s' can't "
|
||||
"be distinguished from member '%s'"
|
||||
% (name, key, types_seen[qtype]))
|
||||
for qt in conflicting:
|
||||
if qt in types_seen:
|
||||
raise QAPISemError(info, "Alternate '%s' member '%s' can't "
|
||||
"be distinguished from member '%s'"
|
||||
% (name, key, types_seen[qt]))
|
||||
types_seen[qt] = key
|
||||
|
||||
|
||||
|
@ -376,6 +376,8 @@ qapi-schema += alternate-conflict-dict.json
|
||||
qapi-schema += alternate-conflict-enum-bool.json
|
||||
qapi-schema += alternate-conflict-enum-int.json
|
||||
qapi-schema += alternate-conflict-string.json
|
||||
qapi-schema += alternate-conflict-bool-string.json
|
||||
qapi-schema += alternate-conflict-num-string.json
|
||||
qapi-schema += alternate-empty.json
|
||||
qapi-schema += alternate-nested.json
|
||||
qapi-schema += alternate-unknown.json
|
||||
|
1
tests/qapi-schema/alternate-conflict-bool-string.err
Normal file
1
tests/qapi-schema/alternate-conflict-bool-string.err
Normal file
@ -0,0 +1 @@
|
||||
tests/qapi-schema/alternate-conflict-bool-string.json:2: Alternate 'Alt' member 'two' can't be distinguished from member 'one'
|
1
tests/qapi-schema/alternate-conflict-bool-string.exit
Normal file
1
tests/qapi-schema/alternate-conflict-bool-string.exit
Normal file
@ -0,0 +1 @@
|
||||
1
|
4
tests/qapi-schema/alternate-conflict-bool-string.json
Normal file
4
tests/qapi-schema/alternate-conflict-bool-string.json
Normal file
@ -0,0 +1,4 @@
|
||||
# alternate branches of 'str' type conflict with all scalar types
|
||||
{ 'alternate': 'Alt',
|
||||
'data': { 'one': 'bool',
|
||||
'two': 'str' } }
|
1
tests/qapi-schema/alternate-conflict-num-string.err
Normal file
1
tests/qapi-schema/alternate-conflict-num-string.err
Normal file
@ -0,0 +1 @@
|
||||
tests/qapi-schema/alternate-conflict-num-string.json:2: Alternate 'Alt' member 'two' can't be distinguished from member 'one'
|
1
tests/qapi-schema/alternate-conflict-num-string.exit
Normal file
1
tests/qapi-schema/alternate-conflict-num-string.exit
Normal file
@ -0,0 +1 @@
|
||||
1
|
4
tests/qapi-schema/alternate-conflict-num-string.json
Normal file
4
tests/qapi-schema/alternate-conflict-num-string.json
Normal file
@ -0,0 +1,4 @@
|
||||
# alternate branches of 'str' type conflict with all scalar types
|
||||
{ 'alternate': 'Alt',
|
||||
'data': { 'one': 'number',
|
||||
'two': 'str' } }
|
0
tests/qapi-schema/alternate-conflict-num-string.out
Normal file
0
tests/qapi-schema/alternate-conflict-num-string.out
Normal file
Loading…
x
Reference in New Issue
Block a user