Browse Source
...or an array of dictionaries. Although we have to cater to existing commands, returning a non-dictionary means the command is not extensible (no new name/value pairs can be added if more information must be returned in parallel). By making the whitelist explicit, any new command that falls foul of this practice will have to be self-documenting, which will encourage developers to either justify the action or rework the design to use a dictionary after all. It's a little bit sloppy that we share a single whitelist among three clients (it's too permissive for each). If this is a problem, a future patch could tighten things by having the generator take the whitelist as an argument (as in scripts/qapi-commands.py --legacy-returns=...), or by having the generator output C code that requires explicit use of the whitelist (as in: #ifndef FROBNICATE_LEGACY_RETURN_OK # error Command 'frobnicate' should return a dictionary #endif then having the callers define appropriate macros). But until we need such fine-grained separation (if ever), this patch does the job just fine. Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>pull/23/head
committed by
Markus Armbruster
11 changed files with 37 additions and 20 deletions
@ -0,0 +1 @@ |
|||
tests/qapi-schema/returns-alternate.json:3: 'returns' for command 'oops' cannot use alternate type 'Alt' |
|||
@ -1 +1 @@ |
|||
0 |
|||
1 |
|||
|
|||
@ -1,3 +1,3 @@ |
|||
# FIXME: we should reject returns if it is an alternate type |
|||
# we reject returns if it is an alternate type |
|||
{ 'alternate': 'Alt', 'data': { 'a': 'int', 'b': 'str' } } |
|||
{ 'command': 'oops', 'returns': 'Alt' } |
|||
|
|||
@ -1,4 +0,0 @@ |
|||
[OrderedDict([('alternate', 'Alt'), ('data', OrderedDict([('a', 'int'), ('b', 'str')]))]), |
|||
OrderedDict([('command', 'oops'), ('returns', 'Alt')])] |
|||
[{'enum_name': 'AltKind', 'enum_values': None}] |
|||
[] |
|||
@ -1,2 +1,3 @@ |
|||
# It is okay (although not extensible) to return a non-dictionary |
|||
{ 'command': 'okay', 'returns': 'int' } |
|||
# But to make it work, the name must be in a whitelist |
|||
{ 'command': 'guest-get-time', 'returns': 'int' } |
|||
|
|||
@ -1,3 +1,3 @@ |
|||
[OrderedDict([('command', 'okay'), ('returns', 'int')])] |
|||
[OrderedDict([('command', 'guest-get-time'), ('returns', 'int')])] |
|||
[] |
|||
[] |
|||
|
|||
@ -0,0 +1 @@ |
|||
tests/qapi-schema/returns-whitelist.json:10: 'returns' for command 'no-way-this-will-get-whitelisted' cannot use built-in type 'array of int' |
|||
@ -1 +1 @@ |
|||
0 |
|||
1 |
|||
|
|||
@ -1,7 +0,0 @@ |
|||
[OrderedDict([('command', 'human-monitor-command'), ('data', OrderedDict([('command-line', 'str'), ('*cpu-index', 'int')])), ('returns', 'str')]), |
|||
OrderedDict([('enum', 'TpmModel'), ('data', ['tpm-tis'])]), |
|||
OrderedDict([('command', 'query-tpm-models'), ('returns', ['TpmModel'])]), |
|||
OrderedDict([('command', 'guest-get-time'), ('returns', 'int')]), |
|||
OrderedDict([('command', 'no-way-this-will-get-whitelisted'), ('returns', ['int'])])] |
|||
[{'enum_name': 'TpmModel', 'enum_values': ['tpm-tis']}] |
|||
[] |
|||
Loading…
Reference in new issue