qapi: Another round of fixes and cleanups
PATCH 4/26 qapi-event: Clean up how name of enum QAPIEvent is made
In reply to Markus ArmbrusterUse c_name() instead of ad hoc code. Doesn't upcase the -p prefix, which is an improvement in my book. Unbreaks prefix containing '.', but other funny characters remain broken. To be fixed next.
--- docs/qapi-code-gen.txt | 8 ++++---- scripts/qapi-event.py | 2 +- tests/test-qmp-event.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-)
docs/qapi-code-gen.txt +4 -4
@@ -826,7 +826,7 @@ Example: QDECREF(qmp); } - const char *EXAMPLE_QAPIEvent_lookup[] = { + const char *example_QAPIEvent_lookup[] = { "MY_EVENT", NULL, };
@@ -843,11 +843,11 @@ Example: void qapi_event_send_my_event(Error **errp); - extern const char *EXAMPLE_QAPIEvent_lookup[]; - typedef enum EXAMPLE_QAPIEvent + extern const char *example_QAPIEvent_lookup[]; + typedef enum example_QAPIEvent { EXAMPLE_QAPI_EVENT_MY_EVENT = 0, EXAMPLE_QAPI_EVENT_MAX = 1, - } EXAMPLE_QAPIEvent; + } example_QAPIEvent; #endif
scripts/qapi-event.py +1 -1
@@ -267,7 +267,7 @@ fdecl.write(mcgen(''' exprs = parse_schema(input_file) -event_enum_name = prefix.upper().replace('-', '_') + "QAPIEvent" +event_enum_name = c_name(prefix + "QAPIEvent", protect=False) event_enum_values = [] event_enum_strings = []
tests/test-qmp-event.c +1 -1
@@ -94,7 +94,7 @@ static bool qdict_cmp_simple(QDict *a, QDict *b)/* This function is hooked as final emit function, which can verify the correctness. */ -static void event_test_emit (TEST_QAPIEvent event,QDict *d,Error **errp) +static void event_test_emit (test_QAPIEvent event,QDict *d,Error **errp) {QObject *obj;QDict *t;
Signature · 1 line
2.4.3
PATCH 1/26 qapi: Clarify docs on including the same file multiple times
In reply to Markus ArmbrusterIt's idempotent.
While there, update examples to current code.
--- docs/qapi-code-gen.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
docs/qapi-code-gen.txt +2 -2
@@ -163,7 +163,7 @@ The QAPI schema definitions can be modularized using the 'include' directive: The directive is evaluated recursively, and include paths are relative to the file using the directive. Multiple includes of the same file are -safe. No other keys should appear in the expression, and the include +idempotent. No other keys should appear in the expression, and the include value should be a string. As a matter of style, it is a good idea to have all files be
@@ -555,6 +555,7 @@ Example: qapi_dealloc_visitor_cleanup(md); } + void qapi_free_UserDefOne(UserDefOne *obj) { QapiDeallocVisitor *md;
@@ -769,7 +770,6 @@ Example: v = qapi_dealloc_get_visitor(md); visit_type_UserDefOne(v, &arg1, "arg1", NULL); qapi_dealloc_visitor_cleanup(md); - return; } static void qmp_init_marshal(void)
Signature · 1 line
2.4.3
cover qapi: Another round of fixes and cleanups
Previously posted as part of "[PATCH RFC v2 00/47] qapi: QMP introspection". Changes since then:
* Trivially rebased, R-bys retained unless noted otherwise.
* PATCH 01: Squash in update of qapi-code-gen.txt examples to current code.
* PATCH 04: Update qapi-code-gen.txt for the change.
* PATCH 05: Fix typo of --prefix in error message [Eric].
* PATCH 06: Clearer commit message [Eric].
* PATCH 07+08: Old PATCH 07 split up into bug fix and cleanup, crediting Eric for the bug report. Generate comments on member inheritance [Eric], and move generated "union tag is" comment. R-by dropped.
* PATCH 14+15: New, from Eric.
* PATCH 16+18: New.
* PATCH 19: Add note on events to commit message. Drop invalid TODO [Eric]. Straightforward conflicts with new PATCH 18 resolved.
* PATCH 20: Fix events, too [Eric]. R-by dropped.
* PATCH 21+25: New.
* PATCH 26: Restore truncated commit message [Eric]. Update qapi-code-gen.txt for the change.
* Parches not mentioned are identical.
Eric Blake (2):
qapi: Document that input visitor semantics are prone to leaks
qapi: Document shortcoming with union 'data' branch
Markus Armbruster (24):
qapi: Clarify docs on including the same file multiple times
qapi: Clean up cgen() and mcgen()
qapi: Simplify guardname()
qapi-event: Clean up how name of enum QAPIEvent is made
qapi: Reject -p arguments that break qapi-event.py
qapi: Drop unused and useless parameters and variables
qapi: Fix generated code when flat union has member 'kind'
qapi: Generate a nicer struct for flat unions
qapi-visit: Fix generated code when schema has forward refs
qapi-visit: Replace list implicit_structs by set
qapi-visit: Fix two name arguments passed to visitors tests/qapi-schema: Document alternate's enum lacks visit function tests/qapi-schema: Document events with base don't work
qapi: Document flaws in checking of names tests/qapi-schema: Restore test case for flat union base bug tests/qapi-schema: Rename tests from data- to args-
qapi-tests: New tests for union, alternate command arguments
qapi: Fix to reject union command and event arguments
qapi: Command returning anonymous type doesn't work, outlaw
qapi-commands: Fix gen_err_check(e) for e and e != 'local_err'
qapi-commands: Inline gen_marshal_output_call()
qapi-commands: Don't feed output of mcgen() to mcgen() again
qapi-commands: Drop useless initialization
qapi: Generated code cleanup
docs/qapi-code-gen.txt | 41 ++++----
scripts/qapi-commands.py | 109 +++++++++-----------
scripts/qapi-event.py | 6 +-
scripts/qapi-types.py | 110 +++++++++++----------
scripts/qapi-visit.py | 93 ++++++++++-------
scripts/qapi.py | 46 +++++----
tests/Makefile | 9 +-
tests/qapi-schema/args-alternate.err | 1 +
...ted-struct-returns.exit => args-alternate.exit} | 0
tests/qapi-schema/args-alternate.json | 3 +
...ested-struct-returns.out => args-alternate.out} | 0
.../{data-array-empty.err => args-array-empty.err} | 2 +-
.../{data-unknown.exit => args-array-empty.exit} | 0
...data-array-empty.json => args-array-empty.json} | 0
.../{data-unknown.out => args-array-empty.out} | 0
...ta-array-unknown.err => args-array-unknown.err} | 2 +-
...member-unknown.exit => args-array-unknown.exit} | 0
...-array-unknown.json => args-array-unknown.json} | 0
...a-member-unknown.out => args-array-unknown.out} | 0
tests/qapi-schema/args-int.err | 1 +
.../{data-member-array-bad.exit => args-int.exit} | 0
tests/qapi-schema/{data-int.json => args-int.json} | 0
.../{data-member-array.err => args-int.out} | 0
...ber-array-bad.err => args-member-array-bad.err} | 2 +-
.../{data-int.exit => args-member-array-bad.exit} | 0
...r-array-bad.json => args-member-array-bad.json} | 0
...ber-array-bad.out => args-member-array-bad.out} | 0
.../{data-int.out => args-member-array.err} | 0
...ta-member-array.exit => args-member-array.exit} | 0
...ta-member-array.json => args-member-array.json} | 0
...data-member-array.out => args-member-array.out} | 0
tests/qapi-schema/args-member-unknown.err | 1 +
...array-unknown.exit => args-member-unknown.exit} | 0
...ember-unknown.json => args-member-unknown.json} | 0
...a-array-unknown.out => args-member-unknown.out} | 0
tests/qapi-schema/args-union.err | 1 +
.../{data-array-empty.exit => args-union.exit} | 0
tests/qapi-schema/args-union.json | 4 +
.../{data-array-empty.out => args-union.out} | 0
tests/qapi-schema/args-unknown.err | 1 +
tests/qapi-schema/args-unknown.exit | 1 +
.../{data-unknown.json => args-unknown.json} | 0
tests/qapi-schema/args-unknown.out | 0
tests/qapi-schema/data-int.err | 1 -
tests/qapi-schema/data-member-unknown.err | 1 -
tests/qapi-schema/data-unknown.err | 1 -
tests/qapi-schema/nested-struct-returns.err | 1 -
tests/qapi-schema/nested-struct-returns.json | 3 -
tests/qapi-schema/qapi-schema-test.json | 39 +++++---
tests/qapi-schema/qapi-schema-test.out | 14 +--
tests/qapi-schema/returns-dict.err | 1 +
tests/qapi-schema/returns-dict.exit | 1 +
tests/qapi-schema/returns-dict.json | 2 +
tests/qapi-schema/returns-dict.out | 0
tests/test-qmp-event.c | 2 +-
tests/test-qmp-input-visitor.c | 4 +-
tests/test-qmp-output-visitor.c | 2 +-
57 files changed, 271 insertions(+), 234 deletions(-)
create mode 100644 tests/qapi-schema/args-alternate.err
rename tests/qapi-schema/{nested-struct-returns.exit => args-alternate.exit} (100%)
create mode 100644 tests/qapi-schema/args-alternate.json
rename tests/qapi-schema/{nested-struct-returns.out => args-alternate.out} (100%)
rename tests/qapi-schema/{data-array-empty.err => args-array-empty.err} (50%)
rename tests/qapi-schema/{data-unknown.exit => args-array-empty.exit} (100%)
rename tests/qapi-schema/{data-array-empty.json => args-array-empty.json} (100%)
rename tests/qapi-schema/{data-unknown.out => args-array-empty.out} (100%)
rename tests/qapi-schema/{data-array-unknown.err => args-array-unknown.err} (50%)
rename tests/qapi-schema/{data-member-unknown.exit => args-array-unknown.exit} (100%)
rename tests/qapi-schema/{data-array-unknown.json => args-array-unknown.json} (100%)
rename tests/qapi-schema/{data-member-unknown.out => args-array-unknown.out} (100%)
create mode 100644 tests/qapi-schema/args-int.err
rename tests/qapi-schema/{data-member-array-bad.exit => args-int.exit} (100%)
rename tests/qapi-schema/{data-int.json => args-int.json} (100%)
rename tests/qapi-schema/{data-member-array.err => args-int.out} (100%)
rename tests/qapi-schema/{data-member-array-bad.err => args-member-array-bad.err} (52%)
rename tests/qapi-schema/{data-int.exit => args-member-array-bad.exit} (100%)
rename tests/qapi-schema/{data-member-array-bad.json => args-member-array-bad.json} (100%)
rename tests/qapi-schema/{data-member-array-bad.out => args-member-array-bad.out} (100%)
rename tests/qapi-schema/{data-int.out => args-member-array.err} (100%)
rename tests/qapi-schema/{data-member-array.exit => args-member-array.exit} (100%)
rename tests/qapi-schema/{data-member-array.json => args-member-array.json} (100%)
rename tests/qapi-schema/{data-member-array.out => args-member-array.out} (100%)
create mode 100644 tests/qapi-schema/args-member-unknown.err
rename tests/qapi-schema/{data-array-unknown.exit => args-member-unknown.exit} (100%)
rename tests/qapi-schema/{data-member-unknown.json => args-member-unknown.json} (100%)
rename tests/qapi-schema/{data-array-unknown.out => args-member-unknown.out} (100%)
create mode 100644 tests/qapi-schema/args-union.err
rename tests/qapi-schema/{data-array-empty.exit => args-union.exit} (100%)
create mode 100644 tests/qapi-schema/args-union.json
rename tests/qapi-schema/{data-array-empty.out => args-union.out} (100%)
create mode 100644 tests/qapi-schema/args-unknown.err
create mode 100644 tests/qapi-schema/args-unknown.exit
rename tests/qapi-schema/{data-unknown.json => args-unknown.json} (100%)
create mode 100644 tests/qapi-schema/args-unknown.out
delete mode 100644 tests/qapi-schema/data-int.err
delete mode 100644 tests/qapi-schema/data-member-unknown.err
delete mode 100644 tests/qapi-schema/data-unknown.err
delete mode 100644 tests/qapi-schema/nested-struct-returns.err
delete mode 100644 tests/qapi-schema/nested-struct-returns.json
create mode 100644 tests/qapi-schema/returns-dict.err
create mode 100644 tests/qapi-schema/returns-dict.exit
create mode 100644 tests/qapi-schema/returns-dict.json
create mode 100644 tests/qapi-schema/returns-dict.outSignature · 1 line
2.4.3
PATCH 5/26 qapi: Reject -p arguments that break qapi-event.py
qapi-event.py breaks when you ask for a funny prefix like '@'. Protect it.
--- scripts/qapi.py | 6 ++++++ 1 file changed, 6 insertions(+)
scripts/qapi.py +6 -0
@@ -1003,6 +1003,12 @@ def parse_command_line(extra_options = "", extra_long_options = []): for oa in opts: o, a = oa if o in ("-p", "--prefix"): + match = re.match('([A-Za-z_.-][A-Za-z0-9_.-]*)?', a) + if match.end() != len(a): + print >>sys.stderr, \ + "%s: 'funny character '%s' in argument of --prefix" \ + % (sys.argv[0], a[match.end()]) + sys.exit(1) prefix = a elif o in ("-o", "--output-dir"): output_dir = a + "/"
Signature · 1 line
2.4.3
PATCH 8/26 qapi: Generate a nicer struct for flat unions
In reply to Markus ArmbrusterThe struct generated for a flat union is weird: the members of its base are at the end, except for the union tag, which is at the beginning.
Example: qapi-schema-test.json has
{ 'struct': 'UserDefUnionBase',
'data': { 'string': 'str', 'enum1': 'EnumOne' } }
{ 'union': 'UserDefFlatUnion',
'base': 'UserDefUnionBase',
'discriminator': 'enum1',
'data': { 'value1' : 'UserDefA',
'value2' : 'UserDefB',
'value3' : 'UserDefB' } }We generate:
struct UserDefFlatUnion
{
EnumOne enum1;
union {
void *data;
UserDefA *value1;
UserDefB *value2;
UserDefB *value3;
};
char *string;
};Change to put all base members at the beginning, unadulterated. Not only is this easier to understand, it also permits casting the flat union to its base, if that should become useful.
We now generate:
struct UserDefFlatUnion
{
/* Members inherited from UserDefUnionBase: */
char *string;
EnumOne enum1;
/* Own members: */
union { /* union tag is @enum1 */
void *data;
UserDefA *value1;
UserDefB *value2;
UserDefB *value3;
};
};--- scripts/qapi-types.py | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-)
scripts/qapi-types.py +22 -16
@@ -200,13 +200,30 @@ def generate_union(expr, meta): ret = mcgen(''' struct %(name)s { - %(discriminator_type_name)s %(discriminator)s; - union { +''', + name=name) + if base: + ret += mcgen(''' + /* Members inherited from %(c_name)s: */ +''', + c_name=c_name(base)) + base_fields = find_struct(base)['data'] + ret += generate_struct_fields(base_fields) + ret += mcgen(''' + /* Own members: */ +''') + else: + assert not discriminator + ret += mcgen(''' + %(discriminator_type_name)s kind; +''', + discriminator_type_name=c_name(discriminator_type_name)) + + ret += mcgen(''' + union { /* union tag is @%(c_name)s */ void *data; ''', - name=name, - discriminator=c_name(discriminator or 'kind'), - discriminator_type_name=c_name(discriminator_type_name)) + c_name=c_name(discriminator or 'kind')) for key in typeinfo: ret += mcgen('''
@@ -217,17 +234,6 @@ struct %(name)s ret += mcgen(''' }; -''') - - if base: - assert discriminator - base_fields = find_struct(base)['data'].copy() - del base_fields[discriminator] - ret += generate_struct_fields(base_fields) - else: - assert not discriminator - - ret += mcgen(''' }; ''') if meta == 'alternate':
Signature · 1 line
2.4.3
PATCH 10/26 qapi-visit: Replace list implicit_structs by set
In reply to Markus ArmbrusterUse set because that's what it is. While there, rename to implicit_structs_seen.
--- scripts/qapi-visit.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
scripts/qapi-visit.py +3 -4
@@ -16,14 +16,13 @@ from ordereddict import OrderedDict from qapi import * import re -implicit_structs = [] +implicit_structs_seen = set() struct_fields_seen = set() def generate_visit_implicit_struct(type): - global implicit_structs - if type in implicit_structs: + if type in implicit_structs_seen: return '' - implicit_structs.append(type) + implicit_structs_seen.add(type) ret = '' if type not in struct_fields_seen: # Need a forward declaration
Signature · 1 line
2.4.3
PATCH 2/26 qapi: Clean up cgen() and mcgen()
In reply to Markus ArmbrusterCommit 05dfb26 added eatspace stripping to mcgen(). Move it to cgen(), just in case somebody gets tempted to use cgen() directly instead of via mcgen().
cgen() indents blank lines. No such lines get generated right now, but fix it anyway.
We use triple-quoted strings for program text, like this:
'''
Program text
any number of lines
'''Keeps the program text relatively readable, but puts an extra newline at either end. mcgen() "fixes" that by dropping the first and last line outright. Drop only the newlines.
This unmasks a bug in qapi-commands.py: four quotes instead of three. Fix it up.
Output doesn't change
--- scripts/qapi-commands.py | 2 +- scripts/qapi.py | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-)
scripts/qapi-commands.py +1 -1
@@ -56,7 +56,7 @@ def gen_sync_call(name, args, ret_type, indent=0): name=c_name(name), args=arglist, retval=retval).rstrip() if ret_type: ret += "\n" + gen_err_check('local_err') - ret += "\n" + mcgen('''' + ret += "\n" + mcgen(''' %(marshal_output_call)s ''', marshal_output_call=gen_marshal_output_call(name, ret_type)).rstrip()
scripts/qapi.py +12 -7
@@ -943,16 +943,21 @@ def pop_indent(indent_amount=4): global indent_level indent_level -= indent_amount +# Generate @code with @kwds interpolated. +# Obey indent_level, and strip eatspace. def cgen(code, **kwds): - indent = genindent(indent_level) - lines = code.split('\n') - lines = map(lambda x: indent + x, lines) - return '\n'.join(lines) % kwds + '\n' - -def mcgen(code, **kwds): - raw = cgen('\n'.join(code.split('\n')[1:-1]), **kwds) + raw = code % kwds + if indent_level: + indent = genindent(indent_level) + raw = re.subn("^.", indent + '\g<0>', raw, 0, re.MULTILINE) + raw = raw[0] return re.sub(re.escape(eatspace) + ' *', '', raw) +def mcgen(code, **kwds): + if code[0] == '\n': + code = code[1:] + return cgen(code, **kwds) + def basename(filename): return filename.split("/")[-1]
Signature · 1 line
2.4.3
PATCH 7/26 qapi: Fix generated code when flat union has member 'kind'
In reply to Markus ArmbrusterA flat union's tag member gets renamed to 'kind' in the generated code. Breaks when another member is named 'kind' exists.
Example, adapted from qapi-schema-test.json:
{ 'struct': 'UserDefUnionBase',
'data': { 'kind': 'str', 'enum1': 'EnumOne' } }
We generate:
struct UserDefFlatUnion
{
EnumOne kind;
union {
void *data;
UserDefA *value1;
UserDefB *value2;
UserDefB *value3;
};
char *kind;
};Kill the silly rename.
--- scripts/qapi-types.py | 3 ++- scripts/qapi-visit.py | 7 +++++-- tests/test-qmp-input-visitor.c | 2 +- tests/test-qmp-output-visitor.c | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-)
scripts/qapi-types.py +2 -1
@@ -200,11 +200,12 @@ def generate_union(expr, meta): ret = mcgen(''' struct %(name)s { - %(discriminator_type_name)s kind; + %(discriminator_type_name)s %(discriminator)s; union { void *data; ''', name=name, + discriminator=c_name(discriminator or 'kind'), discriminator_type_name=c_name(discriminator_type_name)) for key in typeinfo:
scripts/qapi-visit.py +5 -2
@@ -288,20 +288,23 @@ void visit_type_%(name)s(Visitor *m, %(name)s **obj, const char *name, Error **e name=c_name(name)) if not discriminator: + tag = 'kind' disc_key = "type" else: + tag = discriminator disc_key = discriminator ret += mcgen(''' - visit_type_%(disc_type)s(m, &(*obj)->kind, "%(disc_key)s", &err); + visit_type_%(disc_type)s(m, &(*obj)->%(c_tag)s, "%(disc_key)s", &err); if (err) { goto out_obj; } if (!visit_start_union(m, !!(*obj)->data, &err) || err) { goto out_obj; } - switch ((*obj)->kind) { + switch ((*obj)->%(c_tag)s) { ''', disc_type = disc_type, + c_tag=c_name(tag), disc_key = disc_key) for key in members:
tests/test-qmp-input-visitor.c +1 -1
@@ -313,7 +313,7 @@ static void test_visitor_in_union_flat(TestInputVisitorData *data,visit_type_UserDefFlatUnion (v, &tmp,NULL , &err);g_assert (err ==NULL ); - g_assert_cmpint(tmp->kind, ==, ENUM_ONE_VALUE1); + g_assert_cmpint(tmp->enum1, ==, ENUM_ONE_VALUE1); g_assert_cmpstr(tmp->string, ==, "str");/* TODO g_assert_cmpint(tmp->integer, ==, 41); */ g_assert_cmpint(tmp->value1->boolean, ==, true);
tests/test-qmp-output-visitor.c +1 -1
@@ -437,7 +437,7 @@ static void test_visitor_out_union_flat(TestOutputVisitorData *data,Error *err =NULL ;UserDefFlatUnion *tmp =g_malloc0 (sizeof (UserDefFlatUnion)); - tmp->kind =ENUM_ONE_VALUE1 ; + tmp->enum1 =ENUM_ONE_VALUE1 ; tmp->string =g_strdup ("str" ); tmp->value1 =g_malloc0 (sizeof (UserDefA));/* TODO when generator bug is fixed: tmp->integer = 41; */
Signature · 1 line
2.4.3
PATCH 15/26 qapi: Document shortcoming with union 'data' branch
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
Add a FIXME to remind us to fully audit whether removing the 'void *data' branch of each qapi union type can be done safely.
Message-Id: <[email protected]>
--- scripts/qapi-types.py | 8 ++++++++ 1 file changed, 8 insertions(+)
scripts/qapi-types.py +8 -0
@@ -219,6 +219,14 @@ struct %(name)s ''', discriminator_type_name=c_name(discriminator_type_name)) + # 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 + # failed; but since we 0-initialize structs, and cannot tell what + # branch of the union is in use if the discriminator is invalid, there + # 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(''' union { /* union tag is @%(c_name)s */ void *data;
Signature · 1 line
2.4.3
PATCH 14/26 qapi: Document that input visitor semantics are prone to leaks
In reply to Markus ArmbrusterFrom: Eric Blake <[email protected]>
Most functions that can return a pointer or set an Error ** value are decent enough to guarantee a NULL return when reporting an error. Not so with our generated qapi visitor functions. If the caller is not careful to clean up partially-allocated objects on error, then the caller suffers a memory leak.
Properly fixing it is probably complex enough to save for a later day, so merely document it for now.
Message-Id: <[email protected]>
--- scripts/qapi-visit.py | 4 ++++ tests/test-qmp-input-visitor.c | 2 ++ 2 files changed, 6 insertions(+)
scripts/qapi-visit.py +4 -0
@@ -115,6 +115,10 @@ out: def generate_visit_struct_body(name): + # FIXME: if *obj is NULL on entry, and visit_start_struct() assigns to + # *obj, but then visit_type_FOO_fields() fails, we should clean up *obj + # rather than leaving it non-NULL. As currently written, the caller must + # call qapi_free_FOO() to avoid a memory leak of the partial FOO. ret = mcgen(''' Error *err = NULL;
tests/test-qmp-input-visitor.c +2 -0
@@ -636,6 +636,8 @@ static void test_visitor_in_errors(TestInputVisitorData *data,visit_type_TestStruct (v, &p,NULL , &err);g_assert (err); +/* FIXME - a failed parse should not leave a partially-allocated p +* for us to clean up; this could cause callers to leak memory. */ g_assert (p->string ==NULL );error_free (err);
Signature · 1 line
2.4.3
PATCH 16/26 qapi: Document flaws in checking of names
In reply to Markus ArmbrusterWe don't actually enforce our "other than downstream extensions [...], all names should begin with a letter" rule. Add a FIXME.
We should reject names that differ only in '_' vs. '.' vs. '-', because they're liable to clash in generated C. Add a FIXME.
--- scripts/qapi.py | 4 ++++ 1 file changed, 4 insertions(+)
scripts/qapi.py +4 -0
@@ -341,6 +341,8 @@ def discriminator_find_enum_define(expr): return find_enum(discriminator_type) +# FIXME should enforce "other than downstream extensions [...], all +# names should begin with a letter". valid_name = re.compile('^[a-zA-Z_][a-zA-Z0-9_.-]*$') def check_name(expr_info, source, name, allow_optional = False, enum_member = False):
@@ -367,6 +369,8 @@ def check_name(expr_info, source, name, allow_optional = False, def add_name(name, info, meta, implicit = False): global all_names check_name(info, "'%s'" % meta, name) + # FIXME should reject names that differ only in '_' vs. '.' + # vs. '-', because they're liable to clash in generated C. if name in all_names: raise QAPIExprError(info, "%s '%s' is already defined"
Signature · 1 line
2.4.3
PATCH 17/26 tests/qapi-schema: Restore test case for flat union base bug
In reply to Markus ArmbrusterTest case added in commit 2fc0043, and messed up in commit 5223070.
--- tests/qapi-schema/qapi-schema-test.json | 5 +++-- tests/qapi-schema/qapi-schema-test.out | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-)
tests/qapi-schema/qapi-schema-test.json +3 -2
@@ -31,7 +31,7 @@ 'data': { 'boolean': 'bool' } } { 'struct': 'UserDefB', - 'data': { 'integer': 'int' } } + 'data': { 'intb': 'int' } } { 'union': 'UserDefFlatUnion', 'base': 'UserDefUnionBase', # intentional forward reference
@@ -40,9 +40,10 @@ 'value2' : 'UserDefB', 'value3' : 'UserDefB' } } # FIXME generated struct UserDefFlatUnion has members for direct base -# UserDefOne, but lacks members for indirect base UserDefZero +# UserDefUnionBase, but lacks members for indirect base UserDefZero { 'struct': 'UserDefUnionBase', + 'base': 'UserDefZero', 'data': { 'string': 'str', 'enum1': 'EnumOne' } } # this variant of UserDefFlatUnion defaults to a union that uses fields with
tests/qapi-schema/qapi-schema-test.out +4 -4
@@ -6,9 +6,9 @@ OrderedDict([('struct', 'UserDefTwoDict'), ('data', OrderedDict([('string1', 'str'), ('dict2', 'UserDefTwoDictDict'), ('*dict3', 'UserDefTwoDictDict')]))]), OrderedDict([('struct', 'UserDefTwo'), ('data', OrderedDict([('string0', 'str'), ('dict1', 'UserDefTwoDict')]))]), OrderedDict([('struct', 'UserDefA'), ('data', OrderedDict([('boolean', 'bool')]))]), - OrderedDict([('struct', 'UserDefB'), ('data', OrderedDict([('integer', 'int')]))]), + OrderedDict([('struct', 'UserDefB'), ('data', OrderedDict([('intb', 'int')]))]), OrderedDict([('union', 'UserDefFlatUnion'), ('base', 'UserDefUnionBase'), ('discriminator', 'enum1'), ('data', OrderedDict([('value1', 'UserDefA'), ('value2', 'UserDefB'), ('value3', 'UserDefB')]))]), - OrderedDict([('struct', 'UserDefUnionBase'), ('data', OrderedDict([('string', 'str'), ('enum1', 'EnumOne')]))]), + OrderedDict([('struct', 'UserDefUnionBase'), ('base', 'UserDefZero'), ('data', OrderedDict([('string', 'str'), ('enum1', 'EnumOne')]))]), OrderedDict([('union', 'UserDefFlatUnion2'), ('base', 'UserDefUnionBase'), ('discriminator', 'enum1'), ('data', OrderedDict([('value1', 'UserDefC'), ('value2', 'UserDefB'), ('value3', 'UserDefA')]))]), OrderedDict([('alternate', 'UserDefAlternate'), ('data', OrderedDict([('uda', 'UserDefA'), ('s', 'str'), ('i', 'int')]))]), OrderedDict([('struct', 'UserDefC'), ('data', OrderedDict([('string1', 'str'), ('string2', 'str')]))]),
@@ -45,8 +45,8 @@ OrderedDict([('struct', 'UserDefTwoDict'), ('data', OrderedDict([('string1', 'str'), ('dict2', 'UserDefTwoDictDict'), ('*dict3', 'UserDefTwoDictDict')]))]), OrderedDict([('struct', 'UserDefTwo'), ('data', OrderedDict([('string0', 'str'), ('dict1', 'UserDefTwoDict')]))]), OrderedDict([('struct', 'UserDefA'), ('data', OrderedDict([('boolean', 'bool')]))]), - OrderedDict([('struct', 'UserDefB'), ('data', OrderedDict([('integer', 'int')]))]), - OrderedDict([('struct', 'UserDefUnionBase'), ('data', OrderedDict([('string', 'str'), ('enum1', 'EnumOne')]))]), + OrderedDict([('struct', 'UserDefB'), ('data', OrderedDict([('intb', 'int')]))]), + OrderedDict([('struct', 'UserDefUnionBase'), ('base', 'UserDefZero'), ('data', OrderedDict([('string', 'str'), ('enum1', 'EnumOne')]))]), OrderedDict([('struct', 'UserDefC'), ('data', OrderedDict([('string1', 'str'), ('string2', 'str')]))]), OrderedDict([('struct', 'UserDefOptions'), ('data', OrderedDict([('*i64', ['int']), ('*u64', ['uint64']), ('*u16', ['uint16']), ('*i64x', 'int'), ('*u64x', 'uint64')]))]), OrderedDict([('struct', 'EventStructOne'), ('data', OrderedDict([('struct1', 'UserDefOne'), ('string', 'str'), ('*enum2', 'EnumOne')]))]),
Signature · 1 line
2.4.3
PATCH 20/26 qapi: Fix to reject union command and event arguments
In reply to Markus ArmbrusterA command's or event's 'data' must be a struct type, given either as a dictionary, or as struct type name.
Commit dd883c6 tightened the checking there, but not enough: we still accept 'union'. Fix to reject it.
We may want to support union types there, but we'll have to extend qapi-commands.py and qapi-events.py for it.
--- scripts/qapi.py | 4 ++-- tests/qapi-schema/args-union.err | 1 + tests/qapi-schema/args-union.exit | 2 +- tests/qapi-schema/args-union.json | 2 +- tests/qapi-schema/args-union.out | 4 ---- 5 files changed, 5 insertions(+), 8 deletions(-)
scripts/qapi.py +2 -2
@@ -499,7 +499,7 @@ def check_command(expr, expr_info): check_type(expr_info, "'data' for command '%s'" % name, expr.get('data'), allow_dict=True, allow_optional=True, - allow_metas=['union', 'struct'], allow_star=allow_star) + allow_metas=['struct'], allow_star=allow_star) returns_meta = ['union', 'struct'] if name in returns_whitelist: returns_meta += ['built-in', 'alternate', 'enum']
@@ -517,7 +517,7 @@ def check_event(expr, expr_info): events.append(name) check_type(expr_info, "'data' for event '%s'" % name, expr.get('data'), allow_dict=True, allow_optional=True, - allow_metas=['union', 'struct']) + allow_metas=['struct']) def check_union(expr, expr_info): name = expr['union']
tests/qapi-schema/args-union.err +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/args-union.json:4: 'data' for command 'oops' cannot use union type 'Uni'
tests/qapi-schema/args-union.exit +1 -1
@@ -1 +1 @@ -0 +1
tests/qapi-schema/args-union.json +1 -1
@@ -1,4 +1,4 @@ -# FIXME we should reject union arguments +# we do not allow union arguments # TODO should we support this? { 'union': 'Uni', 'data': { 'case1': 'int', 'case2': 'str' } } { 'command': 'oops', 'data': 'Uni' }
tests/qapi-schema/args-union.out +0 -4
@@ -1,4 +0,0 @@ -[OrderedDict([('union', 'Uni'), ('data', OrderedDict([('case1', 'int'), ('case2', 'str')]))]), - OrderedDict([('command', 'oops'), ('data', 'Uni')])] -[{'enum_name': 'UniKind', 'enum_values': None}] -[]
Signature · 1 line
2.4.3
PATCH 25/26 qapi-commands: Drop useless initialization
In reply to Markus ArmbrusterIn generated command handlers, the assignment to retval dominates its only use. Therefore, its initialization is useless. Drop it.
--- docs/qapi-code-gen.txt | 2 +- scripts/qapi-commands.py | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-)
docs/qapi-code-gen.txt +1 -1
@@ -743,7 +743,7 @@ Example: static void qmp_marshal_input_my_command(QDict *args, QObject **ret, Error **errp) { Error *local_err = NULL; - UserDefOne *retval = NULL; + UserDefOne *retval; QmpInputVisitor *mi = qmp_input_visitor_new_strict(QOBJECT(args)); QapiDeallocVisitor *md; Visitor *v;
scripts/qapi-commands.py +2 -6
@@ -205,14 +205,10 @@ def gen_marshal_input(name, args, ret_type, middle_mode): header=hdr) if ret_type: - if is_c_ptr(ret_type): - retval = " %s retval = NULL;" % c_type(ret_type) - else: - retval = " %s retval;" % c_type(ret_type) ret += mcgen(''' -%(retval)s + %(c_type)s retval; ''', - retval=retval) + c_type=c_type(ret_type)) if len(args) > 0: ret += gen_visitor_input_containers_decl(args)
Signature · 1 line
2.4.3
PATCH 3/26 qapi: Simplify guardname()
In reply to Markus ArmbrusterThe guards around built-in declarations lose their _H. It never made much sense anyway.
--- scripts/qapi.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
scripts/qapi.py +3 -7
@@ -958,14 +958,9 @@ def mcgen(code, **kwds): code = code[1:] return cgen(code, **kwds) -def basename(filename): - return filename.split("/")[-1] def guardname(filename): - guard = basename(filename).rsplit(".", 1)[0] - for substr in [".", " ", "-"]: - guard = guard.replace(substr, "_") - return guard.upper() + '_H' + return c_name(filename, protect=False).upper() def guardstart(name): return mcgen('''
@@ -1035,6 +1030,7 @@ def parse_command_line(extra_options = "", extra_long_options = []): def open_output(output_dir, do_c, do_h, prefix, c_file, h_file, c_comment, h_comment): + guard = guardname(prefix + h_file) c_file = output_dir + prefix + c_file h_file = output_dir + prefix + h_file
@@ -1067,7 +1063,7 @@ def open_output(output_dir, do_c, do_h, prefix, c_file, h_file, #define %(guard)s ''', - comment = h_comment, guard = guardname(h_file))) + comment = h_comment, guard = guard)) return (fdef, fdecl)
Signature · 1 line
2.4.3
PATCH 9/26 qapi-visit: Fix generated code when schema has forward refs
In reply to Markus ArmbrusterThe visit_type_implicit_FOO() are generated on demand, right before their first use. Used by visit_type_STRUCT_fields() when STRUCT has base FOO, and by visit_type_UNION() when flat UNION has member a FOO.
If the schema defines FOO after its first use as struct base or flat union member, visit_type_implicit_FOO() calls visit_type_implicit_FOO() before its definition, which doesn't compile.
Rearrange qapi-schema-test.json to demonstrate the bug.
Fix by generating the necessary forward declaration.
--- scripts/qapi-visit.py | 15 ++++++++++++++- tests/qapi-schema/qapi-schema-test.json | 30 +++++++++++++++++------------- tests/qapi-schema/qapi-schema-test.out | 10 +++++----- 3 files changed, 36 insertions(+), 19 deletions(-)
scripts/qapi-visit.py +14 -1
@@ -17,13 +17,23 @@ from qapi import * import re implicit_structs = [] +struct_fields_seen = set() def generate_visit_implicit_struct(type): global implicit_structs if type in implicit_structs: return '' implicit_structs.append(type) - return mcgen(''' + ret = '' + if type not in struct_fields_seen: + # Need a forward declaration + ret += mcgen(''' + +static void visit_type_%(c_type)s_fields(Visitor *m, %(c_type)s **obj, Error **errp); +''', + c_type=type_name(type)) + + ret += mcgen(''' static void visit_type_implicit_%(c_type)s(Visitor *m, %(c_type)s **obj, Error **errp) {
@@ -38,8 +48,11 @@ static void visit_type_implicit_%(c_type)s(Visitor *m, %(c_type)s **obj, Error * } ''', c_type=type_name(type)) + return ret def generate_visit_struct_fields(name, members, base = None): + struct_fields_seen.add(name) + ret = '' if base:
tests/qapi-schema/qapi-schema-test.json +17 -13
@@ -7,13 +7,13 @@ 'data': { 'enum1': 'EnumOne', '*enum2': 'EnumOne', 'enum3': 'EnumOne', '*enum4': 'EnumOne' } } # for testing nested structs -{ 'struct': 'UserDefZero', - 'data': { 'integer': 'int' } } - { 'struct': 'UserDefOne', - 'base': 'UserDefZero', + 'base': 'UserDefZero', # intentional forward reference 'data': { 'string': 'str', '*enum1': 'EnumOne' } } +{ 'struct': 'UserDefZero', + 'data': { 'integer': 'int' } } + { 'struct': 'UserDefTwoDictDict', 'data': { 'userdef': 'UserDefOne', 'string': 'str' } }
@@ -33,29 +33,33 @@ { 'struct': 'UserDefB', 'data': { 'integer': 'int' } } -{ 'struct': 'UserDefC', - 'data': { 'string1': 'str', 'string2': 'str' } } - -{ 'struct': 'UserDefUnionBase', - 'data': { 'string': 'str', 'enum1': 'EnumOne' } } - { 'union': 'UserDefFlatUnion', - 'base': 'UserDefUnionBase', + 'base': 'UserDefUnionBase', # intentional forward reference 'discriminator': 'enum1', - 'data': { 'value1' : 'UserDefA', 'value2' : 'UserDefB', 'value3' : 'UserDefB' } } + 'data': { 'value1' : 'UserDefA', + 'value2' : 'UserDefB', + 'value3' : 'UserDefB' } } # FIXME generated struct UserDefFlatUnion has members for direct base # UserDefOne, but lacks members for indirect base UserDefZero +{ 'struct': 'UserDefUnionBase', + 'data': { 'string': 'str', 'enum1': 'EnumOne' } } + # this variant of UserDefFlatUnion defaults to a union that uses fields with # allocated types to test corner cases in the cleanup/dealloc visitor { 'union': 'UserDefFlatUnion2', 'base': 'UserDefUnionBase', 'discriminator': 'enum1', - 'data': { 'value1' : 'UserDefC', 'value2' : 'UserDefB', 'value3' : 'UserDefA' } } + 'data': { 'value1' : 'UserDefC', # intentional forward reference + 'value2' : 'UserDefB', + 'value3' : 'UserDefA' } } { 'alternate': 'UserDefAlternate', 'data': { 'uda': 'UserDefA', 's': 'str', 'i': 'int' } } +{ 'struct': 'UserDefC', + 'data': { 'string1': 'str', 'string2': 'str' } } + # for testing native lists { 'union': 'UserDefNativeListUnion', 'data': { 'integer': ['int'],
tests/qapi-schema/qapi-schema-test.out +5 -5
@@ -1,17 +1,17 @@ [OrderedDict([('enum', 'EnumOne'), ('data', ['value1', 'value2', 'value3'])]), OrderedDict([('struct', 'NestedEnumsOne'), ('data', OrderedDict([('enum1', 'EnumOne'), ('*enum2', 'EnumOne'), ('enum3', 'EnumOne'), ('*enum4', 'EnumOne')]))]), - OrderedDict([('struct', 'UserDefZero'), ('data', OrderedDict([('integer', 'int')]))]), OrderedDict([('struct', 'UserDefOne'), ('base', 'UserDefZero'), ('data', OrderedDict([('string', 'str'), ('*enum1', 'EnumOne')]))]), + OrderedDict([('struct', 'UserDefZero'), ('data', OrderedDict([('integer', 'int')]))]), OrderedDict([('struct', 'UserDefTwoDictDict'), ('data', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]), OrderedDict([('struct', 'UserDefTwoDict'), ('data', OrderedDict([('string1', 'str'), ('dict2', 'UserDefTwoDictDict'), ('*dict3', 'UserDefTwoDictDict')]))]), OrderedDict([('struct', 'UserDefTwo'), ('data', OrderedDict([('string0', 'str'), ('dict1', 'UserDefTwoDict')]))]), OrderedDict([('struct', 'UserDefA'), ('data', OrderedDict([('boolean', 'bool')]))]), OrderedDict([('struct', 'UserDefB'), ('data', OrderedDict([('integer', 'int')]))]), - OrderedDict([('struct', 'UserDefC'), ('data', OrderedDict([('string1', 'str'), ('string2', 'str')]))]), - OrderedDict([('struct', 'UserDefUnionBase'), ('data', OrderedDict([('string', 'str'), ('enum1', 'EnumOne')]))]), OrderedDict([('union', 'UserDefFlatUnion'), ('base', 'UserDefUnionBase'), ('discriminator', 'enum1'), ('data', OrderedDict([('value1', 'UserDefA'), ('value2', 'UserDefB'), ('value3', 'UserDefB')]))]), + OrderedDict([('struct', 'UserDefUnionBase'), ('data', OrderedDict([('string', 'str'), ('enum1', 'EnumOne')]))]), OrderedDict([('union', 'UserDefFlatUnion2'), ('base', 'UserDefUnionBase'), ('discriminator', 'enum1'), ('data', OrderedDict([('value1', 'UserDefC'), ('value2', 'UserDefB'), ('value3', 'UserDefA')]))]), OrderedDict([('alternate', 'UserDefAlternate'), ('data', OrderedDict([('uda', 'UserDefA'), ('s', 'str'), ('i', 'int')]))]), + OrderedDict([('struct', 'UserDefC'), ('data', OrderedDict([('string1', 'str'), ('string2', 'str')]))]), OrderedDict([('union', 'UserDefNativeListUnion'), ('data', OrderedDict([('integer', ['int']), ('s8', ['int8']), ('s16', ['int16']), ('s32', ['int32']), ('s64', ['int64']), ('u8', ['uint8']), ('u16', ['uint16']), ('u32', ['uint32']), ('u64', ['uint64']), ('number', ['number']), ('boolean', ['bool']), ('string', ['str']), ('sizes', ['size'])]))]), OrderedDict([('command', 'user_def_cmd'), ('data', OrderedDict())]), OrderedDict([('command', 'user_def_cmd1'), ('data', OrderedDict([('ud1a', 'UserDefOne')]))]),
@@ -39,15 +39,15 @@ {'enum_name': '__org.qemu_x-Union1Kind', 'enum_values': None}, {'enum_name': '__org.qemu_x-AltKind', 'enum_values': None}] [OrderedDict([('struct', 'NestedEnumsOne'), ('data', OrderedDict([('enum1', 'EnumOne'), ('*enum2', 'EnumOne'), ('enum3', 'EnumOne'), ('*enum4', 'EnumOne')]))]), - OrderedDict([('struct', 'UserDefZero'), ('data', OrderedDict([('integer', 'int')]))]), OrderedDict([('struct', 'UserDefOne'), ('base', 'UserDefZero'), ('data', OrderedDict([('string', 'str'), ('*enum1', 'EnumOne')]))]), + OrderedDict([('struct', 'UserDefZero'), ('data', OrderedDict([('integer', 'int')]))]), OrderedDict([('struct', 'UserDefTwoDictDict'), ('data', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]), OrderedDict([('struct', 'UserDefTwoDict'), ('data', OrderedDict([('string1', 'str'), ('dict2', 'UserDefTwoDictDict'), ('*dict3', 'UserDefTwoDictDict')]))]), OrderedDict([('struct', 'UserDefTwo'), ('data', OrderedDict([('string0', 'str'), ('dict1', 'UserDefTwoDict')]))]), OrderedDict([('struct', 'UserDefA'), ('data', OrderedDict([('boolean', 'bool')]))]), OrderedDict([('struct', 'UserDefB'), ('data', OrderedDict([('integer', 'int')]))]), - OrderedDict([('struct', 'UserDefC'), ('data', OrderedDict([('string1', 'str'), ('string2', 'str')]))]), OrderedDict([('struct', 'UserDefUnionBase'), ('data', OrderedDict([('string', 'str'), ('enum1', 'EnumOne')]))]), + OrderedDict([('struct', 'UserDefC'), ('data', OrderedDict([('string1', 'str'), ('string2', 'str')]))]), OrderedDict([('struct', 'UserDefOptions'), ('data', OrderedDict([('*i64', ['int']), ('*u64', ['uint64']), ('*u16', ['uint16']), ('*i64x', 'int'), ('*u64x', 'uint64')]))]), OrderedDict([('struct', 'EventStructOne'), ('data', OrderedDict([('struct1', 'UserDefOne'), ('string', 'str'), ('*enum2', 'EnumOne')]))]), OrderedDict([('struct', '__org.qemu_x-Base'), ('data', OrderedDict([('__org.qemu_x-member1', '__org.qemu_x-Enum')]))]),
Signature · 1 line
2.4.3
PATCH 13/26 tests/qapi-schema: Document events with base don't work
In reply to Markus ArmbrusterWhen event FOO's 'data' is a struct with a base, we consider only the struct's direct members, and ignore its base. The generated qapi_event_send_foo() doesn't take arguments for base members.
No such events currently exist in the QMP schema.
--- tests/qapi-schema/qapi-schema-test.json | 3 +++ 1 file changed, 3 insertions(+)
tests/qapi-schema/qapi-schema-test.json +3 -0
@@ -128,6 +128,9 @@ { 'alternate': '__org.qemu_x-Alt', 'data': { '__org.qemu_x-branch': 'str', 'b': '__org.qemu_x-Base' } } { 'event': '__ORG.QEMU_X-EVENT', 'data': '__org.qemu_x-Struct' } +# FIXME generated qapi_event_send___org_qemu_x_event() has only a +# parameter for data's member __org_qemu_x_member2, none for its base +# __org.qemu_x-Base's member __org_qemu_x_member1 { 'command': '__org.qemu_x-command', 'data': { 'a': ['__org.qemu_x-Enum'], 'b': ['__org.qemu_x-Struct'], 'c': '__org.qemu_x-Union2', 'd': '__org.qemu_x-Alt' },
Signature · 1 line
2.4.3
PATCH 19/26 qapi-tests: New tests for union, alternate command arguments
In reply to Markus ArmbrusterA command's 'data' must be a struct type, given either as a dictionary, or as struct type name.
Existing test case data-int.json covers simple type 'int'. Add test cases for type names referring to union and alternate types.
The latter is caught (good), but the former is not (bug).
Events have the same problem, but since they get checked by the same code, we don't bother to duplicate the tests.
--- tests/Makefile | 3 ++- tests/qapi-schema/args-alternate.err | 1 + tests/qapi-schema/args-alternate.exit | 1 + tests/qapi-schema/args-alternate.json | 3 +++ tests/qapi-schema/args-alternate.out | 0 tests/qapi-schema/args-union.err | 0 tests/qapi-schema/args-union.exit | 1 + tests/qapi-schema/args-union.json | 4 ++++ tests/qapi-schema/args-union.out | 4 ++++ 9 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/qapi-schema/args-alternate.err create mode 100644 tests/qapi-schema/args-alternate.exit create mode 100644 tests/qapi-schema/args-alternate.json create mode 100644 tests/qapi-schema/args-alternate.out create mode 100644 tests/qapi-schema/args-union.err create mode 100644 tests/qapi-schema/args-union.exit create mode 100644 tests/qapi-schema/args-union.json create mode 100644 tests/qapi-schema/args-union.out
tests/Makefile +2 -1
@@ -231,7 +231,8 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \ type-bypass.json type-bypass-no-gen.json type-bypass-bad-gen.json \ args-array-empty.json args-array-unknown.json args-int.json \ args-unknown.json args-member-unknown.json args-member-array.json \ - args-member-array-bad.json returns-array-bad.json returns-int.json \ + args-member-array-bad.json args-alternate.json args-union.json \ + returns-array-bad.json returns-int.json \ returns-unknown.json returns-alternate.json returns-whitelist.json \ missing-colon.json missing-comma-list.json missing-comma-object.json \ nested-struct-data.json nested-struct-returns.json non-objects.json \
tests/qapi-schema/args-alternate.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/args-alternate.json:3: 'data' for command 'oops' cannot use alternate type 'Alt'
tests/qapi-schema/args-alternate.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/args-alternate.json new file +3 -0
@@ -0,0 +1,3 @@ +# we do not allow alternate arguments +{ 'alternate': 'Alt', 'data': { 'case1': 'int', 'case2': 'str' } } +{ 'command': 'oops', 'data': 'Alt' }
tests/qapi-schema/args-alternate.out new file +0 -0
tests/qapi-schema/args-union.err new file +0 -0
tests/qapi-schema/args-union.exit new file +1 -0
@@ -0,0 +1 @@ +0
tests/qapi-schema/args-union.json new file +4 -0
@@ -0,0 +1,4 @@ +# FIXME we should reject union arguments +# TODO should we support this? +{ 'union': 'Uni', 'data': { 'case1': 'int', 'case2': 'str' } } +{ 'command': 'oops', 'data': 'Uni' }
tests/qapi-schema/args-union.out new file +4 -0
@@ -0,0 +1,4 @@ +[OrderedDict([('union', 'Uni'), ('data', OrderedDict([('case1', 'int'), ('case2', 'str')]))]), + OrderedDict([('command', 'oops'), ('data', 'Uni')])] +[{'enum_name': 'UniKind', 'enum_values': None}] +[]
Signature · 1 line
2.4.3
PATCH 6/26 qapi: Drop unused and useless parameters and variables
In reply to Markus Armbrustergen_sync_call()'s parameter indent is useless: gen_sync_call() uses it only as optional argument for push_indent() and pop_indent(), their default is four, and gen_sync_call()'s only caller passes four. Drop the parameter.
gen_visitor_input_containers_decl()'s parameter obj is always "QOBJECT(args)". Use that, and drop the parameter.
Drop unused parameters of gen_marshal_output(), gen_marshal_input_decl(), generate_visit_struct_body(), generate_visit_list(), generate_visit_enum(), generate_declaration(), generate_enum_declaration(), generate_decl_enum().
Drop unused variables in generate_event_enum_lookup(), generate_enum_lookup(), generate_visit_struct_fields(), check_event().
--- scripts/qapi-commands.py | 27 +++++++++++++-------------- scripts/qapi-event.py | 1 - scripts/qapi-types.py | 1 - scripts/qapi-visit.py | 47 ++++++++++++++++++++++------------------------- scripts/qapi.py | 1 - 5 files changed, 35 insertions(+), 42 deletions(-)
scripts/qapi-commands.py +13 -14
@@ -38,7 +38,7 @@ if (local_err) { ''') return '' -def gen_sync_call(name, args, ret_type, indent=0): +def gen_sync_call(name, args, ret_type): ret = "" arglist="" retval=""
@@ -48,7 +48,7 @@ def gen_sync_call(name, args, ret_type, indent=0): if optional: arglist += "has_%s, " % c_name(argname) arglist += "%s, " % (c_name(argname)) - push_indent(indent) + push_indent() ret = mcgen(''' %(retval)sqmp_%(name)s(%(args)s&local_err);
@@ -60,7 +60,7 @@ def gen_sync_call(name, args, ret_type, indent=0): %(marshal_output_call)s ''', marshal_output_call=gen_marshal_output_call(name, ret_type)).rstrip() - pop_indent(indent) + pop_indent() return ret.rstrip()
@@ -69,17 +69,16 @@ def gen_marshal_output_call(name, ret_type): return "" return "qmp_marshal_output_%s(retval, ret, &local_err);" % c_name(name) -def gen_visitor_input_containers_decl(args, obj): +def gen_visitor_input_containers_decl(args): ret = "" push_indent() if len(args) > 0: ret += mcgen(''' -QmpInputVisitor *mi = qmp_input_visitor_new_strict(%(obj)s); +QmpInputVisitor *mi = qmp_input_visitor_new_strict(QOBJECT(args)); QapiDeallocVisitor *md; Visitor *v; -''', - obj=obj) +''') pop_indent() return ret.rstrip()
@@ -161,7 +160,7 @@ qapi_dealloc_visitor_cleanup(md); pop_indent() return ret.rstrip() -def gen_marshal_output(name, args, ret_type, middle_mode): +def gen_marshal_output(name, ret_type): if not ret_type: return ""
@@ -194,14 +193,14 @@ out: return ret -def gen_marshal_input_decl(name, args, ret_type, middle_mode): +def gen_marshal_input_decl(name, middle_mode): ret = 'void qmp_marshal_input_%s(QDict *args, QObject **ret, Error **errp)' % c_name(name) if not middle_mode: ret = "static " + ret return ret def gen_marshal_input(name, args, ret_type, middle_mode): - hdr = gen_marshal_input_decl(name, args, ret_type, middle_mode) + hdr = gen_marshal_input_decl(name, middle_mode) ret = mcgen(''' %(header)s
@@ -228,7 +227,7 @@ def gen_marshal_input(name, args, ret_type, middle_mode): %(visitor_input_block)s ''', - visitor_input_containers_decl=gen_visitor_input_containers_decl(args, "QOBJECT(args)"), + visitor_input_containers_decl=gen_visitor_input_containers_decl(args), visitor_input_vars_decl=gen_visitor_input_vars_decl(args), visitor_input_block=gen_visitor_input_block(args)) else:
@@ -240,7 +239,7 @@ def gen_marshal_input(name, args, ret_type, middle_mode): ret += mcgen(''' %(sync_call)s ''', - sync_call=gen_sync_call(name, args, ret_type, indent=4)) + sync_call=gen_sync_call(name, args, ret_type)) if re.search('^ *goto out\\;', ret, re.MULTILINE): ret += mcgen('''
@@ -360,11 +359,11 @@ for cmd in commands: ret = generate_command_decl(cmd['command'], arglist, ret_type) + "\n" fdecl.write(ret) if ret_type: - ret = gen_marshal_output(cmd['command'], arglist, ret_type, middle_mode) + "\n" + ret = gen_marshal_output(cmd['command'], ret_type) + "\n" fdef.write(ret) if middle_mode: - fdecl.write('%s;\n' % gen_marshal_input_decl(cmd['command'], arglist, ret_type, middle_mode)) + fdecl.write('%s;\n' % gen_marshal_input_decl(cmd['command'], middle_mode)) ret = gen_marshal_input(cmd['command'], arglist, ret_type, middle_mode) + "\n" fdef.write(ret)
scripts/qapi-event.py +0 -1
@@ -199,7 +199,6 @@ const char *%(event_enum_name)s_lookup[] = { ''', event_enum_name = event_enum_name) - i = 0 for string in event_enum_strings: ret += mcgen(''' "%(string)s",
scripts/qapi-types.py +0 -1
@@ -108,7 +108,6 @@ def generate_enum_lookup(name, values): const char * const %(name)s_lookup[] = { ''', name=c_name(name)) - i = 0 for value in values: index = c_enum_const(name, value) ret += mcgen('''
scripts/qapi-visit.py +22 -25
136 lines not on this page · raw message
scripts/qapi.py +0 -1
@@ -507,7 +507,6 @@ def check_command(expr, expr_info): def check_event(expr, expr_info): global events name = expr['event'] - params = expr.get('data') if name.upper() == 'MAX': raise QAPIExprError(expr_info, "Event name 'MAX' cannot be created")
Signature · 1 line
2.4.3
PATCH 12/26 tests/qapi-schema: Document alternate's enum lacks visit function
In reply to Markus ArmbrusterWe generate a declaration, but no definition.
The QMP schema has two: Qcow2OverlapChecks and BlockdevRef. Neither visit_type_Qcow2OverlapChecksKind() nor visit_type_BlockdevRefKind() is actually used.
--- tests/qapi-schema/qapi-schema-test.json | 1 + 1 file changed, 1 insertion(+)
tests/qapi-schema/qapi-schema-test.json +1 -0
@@ -56,6 +56,7 @@ { 'alternate': 'UserDefAlternate', 'data': { 'uda': 'UserDefA', 's': 'str', 'i': 'int' } } +# FIXME only a declaration of visit_type_UserDefAlternateKind() generated { 'struct': 'UserDefC', 'data': { 'string1': 'str', 'string2': 'str' } }
Signature · 1 line
2.4.3
PATCH 11/26 qapi-visit: Fix two name arguments passed to visitors
In reply to Markus ArmbrusterThe generated code passes mangled schema names to visit_type_enum() and union's visit_start_struct(). Fix it to pass the names unadulterated, like we do everywhere else.
Only qapi-schema-test.json actually has names where this makes a
difference: enum __org.qemu_x-Enum, flat union __org.qemu_x-Union2, simple union __org.qemu_x-Union1 and its implicit enum __org.qemu_x-Union1Kind.
--- scripts/qapi-visit.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
scripts/qapi-visit.py +6 -6
@@ -185,12 +185,12 @@ out: def generate_visit_enum(name): return mcgen(''' -void visit_type_%(name)s(Visitor *m, %(name)s *obj, const char *name, Error **errp) +void visit_type_%(c_name)s(Visitor *m, %(c_name)s *obj, const char *name, Error **errp) { - visit_type_enum(m, (int *)obj, %(name)s_lookup, "%(name)s", name, errp); + visit_type_enum(m, (int *)obj, %(c_name)s_lookup, "%(name)s", name, errp); } ''', - name=c_name(name)) + c_name=c_name(name), name=name) def generate_visit_alternate(name, members): ret = mcgen('''
@@ -278,17 +278,17 @@ def generate_visit_union(expr): ret += mcgen(''' -void visit_type_%(name)s(Visitor *m, %(name)s **obj, const char *name, Error **errp) +void visit_type_%(c_name)s(Visitor *m, %(c_name)s **obj, const char *name, Error **errp) { Error *err = NULL; - visit_start_struct(m, (void **)obj, "%(name)s", name, sizeof(%(name)s), &err); + visit_start_struct(m, (void **)obj, "%(name)s", name, sizeof(%(c_name)s), &err); if (err) { goto out; } if (*obj) { ''', - name=c_name(name)) + c_name=c_name(name), name=name) if base: ret += mcgen('''
Signature · 1 line
2.4.3
PATCH 22/26 qapi-commands: Fix gen_err_check(e) for e and e != 'local_err'
In reply to Markus Armbrustergen_err_check() hard-codes 'local_err' instead of substituting the argument. Currently harmless, since all callers pass either None or 'local_err'.
--- scripts/qapi-commands.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
scripts/qapi-commands.py +7 -6
@@ -29,14 +29,15 @@ def generate_command_decl(name, args, ret_type): ret_type=c_type(ret_type), name=c_name(name), args=arglist).strip() -def gen_err_check(errvar): - if errvar: - return mcgen(''' -if (local_err) { +def gen_err_check(err): + if not err: + return '' + return mcgen(''' +if (%(err)s) { goto out; } -''') - return '' +''', + err=err) def gen_sync_call(name, args, ret_type): ret = ""
Signature · 1 line
2.4.3
PATCH 23/26 qapi-commands: Inline gen_marshal_output_call()
In reply to Markus Armbruster--- scripts/qapi-commands.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
scripts/qapi-commands.py +4 -8
@@ -57,19 +57,15 @@ def gen_sync_call(name, args, ret_type): name=c_name(name), args=arglist, retval=retval).rstrip() if ret_type: ret += "\n" + gen_err_check('local_err') - ret += "\n" + mcgen(''' -%(marshal_output_call)s + ret += mcgen(''' + +qmp_marshal_output_%(c_name)s(retval, ret, &local_err); ''', - marshal_output_call=gen_marshal_output_call(name, ret_type)).rstrip() + c_name=c_name(name)) pop_indent() return ret.rstrip() -def gen_marshal_output_call(name, ret_type): - if not ret_type: - return "" - return "qmp_marshal_output_%s(retval, ret, &local_err);" % c_name(name) - def gen_visitor_input_containers_decl(args): ret = ""
Signature · 1 line
2.4.3
PATCH 18/26 tests/qapi-schema: Rename tests from data- to args-
In reply to Markus ArmbrusterSince every schema entity has 'data', the data- prefix conveys no information. These tests actually exercise commands. Only commands have arguments, so change the prefix to to args-.
---
tests/Makefile | 6 +++---
tests/qapi-schema/{data-array-empty.err => args-array-empty.err} | 2 +-
tests/qapi-schema/{data-unknown.exit => args-array-empty.exit} | 0
tests/qapi-schema/{data-array-empty.json => args-array-empty.json} | 0
tests/qapi-schema/{data-unknown.out => args-array-empty.out} | 0
.../qapi-schema/{data-array-unknown.err => args-array-unknown.err} | 2 +-
.../{data-member-unknown.exit => args-array-unknown.exit} | 0
.../{data-array-unknown.json => args-array-unknown.json} | 0
.../qapi-schema/{data-member-unknown.out => args-array-unknown.out} | 0
tests/qapi-schema/args-int.err | 1 +
tests/qapi-schema/{data-member-array-bad.exit => args-int.exit} | 0
tests/qapi-schema/{data-int.json => args-int.json} | 0
tests/qapi-schema/{data-member-array.err => args-int.out} | 0
.../{data-member-array-bad.err => args-member-array-bad.err} | 2 +-
tests/qapi-schema/{data-int.exit => args-member-array-bad.exit} | 0
.../{data-member-array-bad.json => args-member-array-bad.json} | 0
.../{data-member-array-bad.out => args-member-array-bad.out} | 0
tests/qapi-schema/{data-int.out => args-member-array.err} | 0
.../qapi-schema/{data-member-array.exit => args-member-array.exit} | 0
.../qapi-schema/{data-member-array.json => args-member-array.json} | 0
tests/qapi-schema/{data-member-array.out => args-member-array.out} | 0
tests/qapi-schema/args-member-unknown.err | 1 +
.../{data-array-unknown.exit => args-member-unknown.exit} | 0
.../{data-member-unknown.json => args-member-unknown.json} | 0
.../qapi-schema/{data-array-unknown.out => args-member-unknown.out} | 0
tests/qapi-schema/args-unknown.err | 1 +
tests/qapi-schema/{data-array-empty.exit => args-unknown.exit} | 0
tests/qapi-schema/{data-unknown.json => args-unknown.json} | 0
tests/qapi-schema/{data-array-empty.out => args-unknown.out} | 0
tests/qapi-schema/data-int.err | 1 -
tests/qapi-schema/data-member-unknown.err | 1 -
tests/qapi-schema/data-unknown.err | 1 -
32 files changed, 9 insertions(+), 9 deletions(-)
rename tests/qapi-schema/{data-array-empty.err => args-array-empty.err} (50%)
rename tests/qapi-schema/{data-unknown.exit => args-array-empty.exit} (100%)
rename tests/qapi-schema/{data-array-empty.json => args-array-empty.json} (100%)
rename tests/qapi-schema/{data-unknown.out => args-array-empty.out} (100%)
rename tests/qapi-schema/{data-array-unknown.err => args-array-unknown.err} (50%)
rename tests/qapi-schema/{data-member-unknown.exit => args-array-unknown.exit} (100%)
rename tests/qapi-schema/{data-array-unknown.json => args-array-unknown.json} (100%)
rename tests/qapi-schema/{data-member-unknown.out => args-array-unknown.out} (100%)
create mode 100644 tests/qapi-schema/args-int.err
rename tests/qapi-schema/{data-member-array-bad.exit => args-int.exit} (100%)
rename tests/qapi-schema/{data-int.json => args-int.json} (100%)
rename tests/qapi-schema/{data-member-array.err => args-int.out} (100%)
rename tests/qapi-schema/{data-member-array-bad.err => args-member-array-bad.err} (52%)
rename tests/qapi-schema/{data-int.exit => args-member-array-bad.exit} (100%)
rename tests/qapi-schema/{data-member-array-bad.json => args-member-array-bad.json} (100%)
rename tests/qapi-schema/{data-member-array-bad.out => args-member-array-bad.out} (100%)
rename tests/qapi-schema/{data-int.out => args-member-array.err} (100%)
rename tests/qapi-schema/{data-member-array.exit => args-member-array.exit} (100%)
rename tests/qapi-schema/{data-member-array.json => args-member-array.json} (100%)
rename tests/qapi-schema/{data-member-array.out => args-member-array.out} (100%)
create mode 100644 tests/qapi-schema/args-member-unknown.err
rename tests/qapi-schema/{data-array-unknown.exit => args-member-unknown.exit} (100%)
rename tests/qapi-schema/{data-member-unknown.json => args-member-unknown.json} (100%)
rename tests/qapi-schema/{data-array-unknown.out => args-member-unknown.out} (100%)
create mode 100644 tests/qapi-schema/args-unknown.err
rename tests/qapi-schema/{data-array-empty.exit => args-unknown.exit} (100%)
rename tests/qapi-schema/{data-unknown.json => args-unknown.json} (100%)
rename tests/qapi-schema/{data-array-empty.out => args-unknown.out} (100%)
delete mode 100644 tests/qapi-schema/data-int.err
delete mode 100644 tests/qapi-schema/data-member-unknown.err
delete mode 100644 tests/qapi-schema/data-unknown.errtests/Makefile +3 -3
@@ -229,9 +229,9 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \ redefined-type.json redefined-command.json redefined-builtin.json \ redefined-event.json command-int.json bad-data.json event-max.json \ type-bypass.json type-bypass-no-gen.json type-bypass-bad-gen.json \ - data-array-empty.json data-array-unknown.json data-int.json \ - data-unknown.json data-member-unknown.json data-member-array.json \ - data-member-array-bad.json returns-array-bad.json returns-int.json \ + args-array-empty.json args-array-unknown.json args-int.json \ + args-unknown.json args-member-unknown.json args-member-array.json \ + args-member-array-bad.json returns-array-bad.json returns-int.json \ returns-unknown.json returns-alternate.json returns-whitelist.json \ missing-colon.json missing-comma-list.json missing-comma-object.json \ nested-struct-data.json nested-struct-returns.json non-objects.json \
tests/qapi-schema/args-array-empty.err renamed from tests/qapi-schema/data-array-empty.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/data-array-empty.json:2: Member 'empty' of 'data' for command 'oops': array type must contain single type name +tests/qapi-schema/args-array-empty.json:2: Member 'empty' of 'data' for command 'oops': array type must contain single type name
tests/qapi-schema/args-array-empty.exit renamed from tests/qapi-schema/data-unknown.exit +0 -0
tests/qapi-schema/args-array-empty.json renamed from tests/qapi-schema/data-array-empty.json +0 -0
tests/qapi-schema/args-array-empty.out renamed from tests/qapi-schema/data-unknown.out +0 -0
tests/qapi-schema/args-array-unknown.err renamed from tests/qapi-schema/data-array-unknown.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/data-array-unknown.json:2: Member 'array' of 'data' for command 'oops' uses unknown type 'array of NoSuchType' +tests/qapi-schema/args-array-unknown.json:2: Member 'array' of 'data' for command 'oops' uses unknown type 'array of NoSuchType'
tests/qapi-schema/args-array-unknown.exit renamed from tests/qapi-schema/data-member-unknown.exit +0 -0
tests/qapi-schema/args-array-unknown.json renamed from tests/qapi-schema/data-array-unknown.json +0 -0
tests/qapi-schema/args-array-unknown.out renamed from tests/qapi-schema/data-member-unknown.out +0 -0
tests/qapi-schema/args-int.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/args-int.json:2: 'data' for command 'oops' cannot use built-in type 'int'
tests/qapi-schema/args-int.exit renamed from tests/qapi-schema/data-member-array-bad.exit +0 -0
tests/qapi-schema/args-int.json renamed from tests/qapi-schema/data-int.json +0 -0
tests/qapi-schema/args-int.out renamed from tests/qapi-schema/data-member-array.err +0 -0
tests/qapi-schema/args-member-array-bad.err renamed from tests/qapi-schema/data-member-array-bad.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/data-member-array-bad.json:2: Member 'member' of 'data' for command 'oops': array type must contain single type name +tests/qapi-schema/args-member-array-bad.json:2: Member 'member' of 'data' for command 'oops': array type must contain single type name
tests/qapi-schema/args-member-array-bad.exit renamed from tests/qapi-schema/data-int.exit +0 -0
tests/qapi-schema/args-member-array-bad.json renamed from tests/qapi-schema/data-member-array-bad.json +0 -0
tests/qapi-schema/args-member-array-bad.out renamed from tests/qapi-schema/data-member-array-bad.out +0 -0
tests/qapi-schema/args-member-array.err renamed from tests/qapi-schema/data-int.out +0 -0
tests/qapi-schema/args-member-array.exit renamed from tests/qapi-schema/data-member-array.exit +0 -0
tests/qapi-schema/args-member-array.json renamed from tests/qapi-schema/data-member-array.json +0 -0
tests/qapi-schema/args-member-array.out renamed from tests/qapi-schema/data-member-array.out +0 -0
tests/qapi-schema/args-member-unknown.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/args-member-unknown.json:2: Member 'member' of 'data' for command 'oops' uses unknown type 'NoSuchType'
tests/qapi-schema/args-member-unknown.exit renamed from tests/qapi-schema/data-array-unknown.exit +0 -0
tests/qapi-schema/args-member-unknown.json renamed from tests/qapi-schema/data-member-unknown.json +0 -0
tests/qapi-schema/args-member-unknown.out renamed from tests/qapi-schema/data-array-unknown.out +0 -0
tests/qapi-schema/args-unknown.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/args-unknown.json:2: 'data' for command 'oops' uses unknown type 'NoSuchType'
tests/qapi-schema/args-unknown.exit renamed from tests/qapi-schema/data-array-empty.exit +0 -0
tests/qapi-schema/args-unknown.json renamed from tests/qapi-schema/data-unknown.json +0 -0
tests/qapi-schema/args-unknown.out renamed from tests/qapi-schema/data-array-empty.out +0 -0
tests/qapi-schema/data-int.err deleted +0 -1
@@ -1 +0,0 @@ -tests/qapi-schema/data-int.json:2: 'data' for command 'oops' cannot use built-in type 'int'
tests/qapi-schema/data-member-unknown.err deleted +0 -1
@@ -1 +0,0 @@ -tests/qapi-schema/data-member-unknown.json:2: Member 'member' of 'data' for command 'oops' uses unknown type 'NoSuchType'
tests/qapi-schema/data-unknown.err deleted +0 -1
@@ -1 +0,0 @@ -tests/qapi-schema/data-unknown.json:2: 'data' for command 'oops' uses unknown type 'NoSuchType'
Signature · 1 line
2.4.3
PATCH 21/26 qapi: Command returning anonymous type doesn't work, outlaw
In reply to Markus ArmbrusterReproducer: with
{ 'command': 'user_def_cmd4', 'returns': { 'a': 'int' } }added to qapi-schema-test.json, qapi-commands.py dies when it tries to generate the command handler function
Traceback (most recent call last):
File "/work/armbru/qemu/scripts/qapi-commands.py", line 359, in <module>
ret = generate_command_decl(cmd['command'], arglist, ret_type) + "\n"
File "/work/armbru/qemu/scripts/qapi-commands.py", line 29, in generate_command_decl
ret_type=c_type(ret_type), name=c_name(name),
File "/work/armbru/qemu/scripts/qapi.py", line 927, in c_type
assert isinstance(value, str) and value != ""
AssertionError
because the return type doesn't exist.
Simply outlaw this usage.
---
docs/qapi-code-gen.txt | 17 ++++++++---------
scripts/qapi.py | 2 +-
tests/Makefile | 4 ++--
tests/qapi-schema/nested-struct-returns.err | 1 -
tests/qapi-schema/nested-struct-returns.json | 3 ---
tests/qapi-schema/returns-dict.err | 1 +
.../{nested-struct-returns.exit => returns-dict.exit} | 0
tests/qapi-schema/returns-dict.json | 2 ++
.../{nested-struct-returns.out => returns-dict.out} | 0
9 files changed, 14 insertions(+), 16 deletions(-)
delete mode 100644 tests/qapi-schema/nested-struct-returns.err
delete mode 100644 tests/qapi-schema/nested-struct-returns.json
create mode 100644 tests/qapi-schema/returns-dict.err
rename tests/qapi-schema/{nested-struct-returns.exit => returns-dict.exit} (100%)
create mode 100644 tests/qapi-schema/returns-dict.json
rename tests/qapi-schema/{nested-struct-returns.out => returns-dict.out} (100%)docs/qapi-code-gen.txt +8 -9
@@ -394,7 +394,7 @@ following example objects: === Commands === Usage: { 'command': STRING, '*data': COMPLEX-TYPE-NAME-OR-DICT, - '*returns': TYPE-NAME-OR-DICT, + '*returns': TYPE-NAME, '*gen': false, '*success-response': false } Commands are defined by using a dictionary containing several members,
@@ -416,14 +416,13 @@ The member is optional from the command declaration; if absent, the "return" field will be an empty dictionary. If 'returns' is present, it must be the string name of a complex or built-in type, a one-element array containing the name of a complex or built-in type, -or a dictionary that declares an anonymous type with the same -semantics as a 'struct' expression, with one exception noted below -when 'gen' is used. Although it is permitted to have the 'returns' -member name a built-in type or an array of built-in types, any command -that does this cannot be extended to return additional information in -the future; thus, new commands should strongly consider returning a -dictionary-based type or an array of dictionaries, even if the -dictionary only contains one field at the present. +with one exception noted below when 'gen' is used. Although it is +permitted to have the 'returns' member name a built-in type or an +array of built-in types, any command that does this cannot be extended +to return additional information in the future; thus, new commands +should strongly consider returning a dictionary-based type or an array +of dictionaries, even if the dictionary only contains one field at the +present. All commands in Client JSON Protocol use a dictionary to report failure, with no way to specify that in QAPI. Where the error return
scripts/qapi.py +1 -1
@@ -504,7 +504,7 @@ def check_command(expr, expr_info): if name in returns_whitelist: returns_meta += ['built-in', 'alternate', 'enum'] check_type(expr_info, "'returns' for command '%s'" % name, - expr.get('returns'), allow_array=True, allow_dict=True, + expr.get('returns'), allow_array=True, allow_optional=True, allow_metas=returns_meta, allow_star=allow_star)
tests/Makefile +2 -2
@@ -232,10 +232,10 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \ args-array-empty.json args-array-unknown.json args-int.json \ args-unknown.json args-member-unknown.json args-member-array.json \ args-member-array-bad.json args-alternate.json args-union.json \ - returns-array-bad.json returns-int.json \ + returns-array-bad.json returns-int.json returns-dict.json \ returns-unknown.json returns-alternate.json returns-whitelist.json \ missing-colon.json missing-comma-list.json missing-comma-object.json \ - nested-struct-data.json nested-struct-returns.json non-objects.json \ + nested-struct-data.json non-objects.json \ qapi-schema-test.json quoted-structural-chars.json \ trailing-comma-list.json trailing-comma-object.json \ unclosed-list.json unclosed-object.json unclosed-string.json \
tests/qapi-schema/nested-struct-returns.err deleted +0 -1
@@ -1 +0,0 @@ -tests/qapi-schema/nested-struct-returns.json:2: Member 'a' of 'returns' for command 'foo' should be a type name
tests/qapi-schema/nested-struct-returns.json deleted +0 -3
@@ -1,3 +0,0 @@ -# inline subtypes collide with our desired future use of defaults -{ 'command': 'foo', - 'returns': { 'a' : { 'string' : 'str', 'integer': 'int' }, 'b' : 'str' } }
tests/qapi-schema/returns-dict.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/returns-dict.json:2: 'returns' for command 'oops' should be a type name
tests/qapi-schema/returns-dict.exit renamed from tests/qapi-schema/nested-struct-returns.exit +0 -0
tests/qapi-schema/returns-dict.json new file +2 -0
@@ -0,0 +1,2 @@ +# we reject inline struct return type +{ 'command': 'oops', 'returns': { 'a': 'str' } }
tests/qapi-schema/returns-dict.out renamed from tests/qapi-schema/nested-struct-returns.out +0 -0
Signature · 1 line
2.4.3
PATCH 24/26 qapi-commands: Don't feed output of mcgen() to mcgen() again
In reply to Markus ArmbrusterMultiple passes through mcgen() is prone to produce unwanted blank lines, which we then combat by sprinkling .rstrip() on top. Just don't do it.
--- scripts/qapi-commands.py | 52 +++++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 31 deletions(-)
scripts/qapi-commands.py +21 -31
@@ -27,7 +27,7 @@ def generate_command_decl(name, args, ret_type): %(ret_type)s qmp_%(name)s(%(args)sError **errp); ''', ret_type=c_type(ret_type), name=c_name(name), - args=arglist).strip() + args=arglist) def gen_err_check(err): if not err:
@@ -52,19 +52,17 @@ def gen_sync_call(name, args, ret_type): push_indent() ret = mcgen(''' %(retval)sqmp_%(name)s(%(args)s&local_err); - ''', - name=c_name(name), args=arglist, retval=retval).rstrip() + name=c_name(name), args=arglist, retval=retval) if ret_type: - ret += "\n" + gen_err_check('local_err') + ret += gen_err_check('local_err') ret += mcgen(''' qmp_marshal_output_%(c_name)s(retval, ret, &local_err); ''', c_name=c_name(name)) pop_indent() - return ret.rstrip() - + return ret def gen_visitor_input_containers_decl(args): ret = ""
@@ -78,7 +76,7 @@ Visitor *v; ''') pop_indent() - return ret.rstrip() + return ret def gen_visitor_input_vars_decl(args): ret = ""
@@ -101,7 +99,7 @@ bool has_%(argname)s = false; argname=c_name(argname), argtype=c_type(argtype)) pop_indent() - return ret.rstrip() + return ret def gen_visitor_input_block(args, dealloc=False): ret = ""
@@ -155,7 +153,7 @@ visit_type_%(visitor)s(v, &%(c_name)s, "%(name)s", %(errp)s); qapi_dealloc_visitor_cleanup(md); ''') pop_indent() - return ret.rstrip() + return ret def gen_marshal_output(name, ret_type): if not ret_type:
@@ -217,26 +215,17 @@ def gen_marshal_input(name, args, ret_type, middle_mode): retval=retval) if len(args) > 0: - ret += mcgen(''' -%(visitor_input_containers_decl)s -%(visitor_input_vars_decl)s - -%(visitor_input_block)s - -''', - visitor_input_containers_decl=gen_visitor_input_containers_decl(args), - visitor_input_vars_decl=gen_visitor_input_vars_decl(args), - visitor_input_block=gen_visitor_input_block(args)) + ret += gen_visitor_input_containers_decl(args) + ret += gen_visitor_input_vars_decl(args) + '\n' + ret += gen_visitor_input_block(args) + '\n' else: ret += mcgen(''' (void)args; ''') - ret += mcgen(''' -%(sync_call)s -''', - sync_call=gen_sync_call(name, args, ret_type)) + ret += gen_sync_call(name, args, ret_type) + if re.search('^ *goto out\\;', ret, re.MULTILINE): ret += mcgen('''
@@ -244,11 +233,11 @@ out: ''') ret += mcgen(''' error_propagate(errp, local_err); -%(visitor_input_block_cleanup)s +''') + ret += gen_visitor_input_block(args, dealloc=True) + ret += mcgen(''' } -''', - visitor_input_block_cleanup=gen_visitor_input_block(args, - dealloc=True)) +''') return ret def gen_registry(commands):
@@ -268,12 +257,13 @@ qmp_register_command("%(name)s", qmp_marshal_input_%(c_name)s, %(opts)s); ret = mcgen(''' static void qmp_init_marshal(void) { -%(registry)s +''') + ret += registry + ret += mcgen(''' } qapi_init(qmp_init_marshal); -''', - registry=registry.rstrip()) +''') return ret middle_mode = False
@@ -353,7 +343,7 @@ for cmd in commands: arglist = cmd['data'] if cmd.has_key('returns'): ret_type = cmd['returns'] - ret = generate_command_decl(cmd['command'], arglist, ret_type) + "\n" + ret = generate_command_decl(cmd['command'], arglist, ret_type) fdecl.write(ret) if ret_type: ret = gen_marshal_output(cmd['command'], ret_type) + "\n"
Signature · 1 line
2.4.3
PATCH 26/26 qapi: Generated code cleanup
In reply to Markus ArmbrusterClean up white-space, brace placement, and superfluous #ifdef QAPI_TYPES_BUILTIN_CLEANUP_DEF.
--- docs/qapi-code-gen.txt | 12 ++++----- scripts/qapi-commands.py | 1 + scripts/qapi-event.py | 3 +-- scripts/qapi-types.py | 66 +++++++++++++++++++++++------------------------- scripts/qapi-visit.py | 1 + 5 files changed, 39 insertions(+), 44 deletions(-)
docs/qapi-code-gen.txt +5 -7
@@ -569,7 +569,6 @@ Example: visit_type_UserDefOne(v, &obj, NULL, NULL); qapi_dealloc_visitor_cleanup(md); } - $ cat qapi-generated/example-qapi-types.h [Uninteresting stuff omitted...]
@@ -580,8 +579,7 @@ Example: typedef struct UserDefOne UserDefOne; - typedef struct UserDefOneList - { + typedef struct UserDefOneList { union { UserDefOne *value; uint64_t padding;
@@ -589,10 +587,10 @@ Example: struct UserDefOneList *next; } UserDefOneList; + [Functions on built-in types omitted...] - struct UserDefOne - { + struct UserDefOne { int64_t integer; char *string; };
@@ -630,6 +628,7 @@ Example: static void visit_type_UserDefOne_fields(Visitor *m, UserDefOne **obj, Error **errp) { Error *err = NULL; + visit_type_int(m, &(*obj)->integer, "integer", &err); if (err) { goto out;
@@ -843,8 +842,7 @@ Example: void qapi_event_send_my_event(Error **errp); extern const char *example_QAPIEvent_lookup[]; - typedef enum example_QAPIEvent - { + typedef enum example_QAPIEvent { EXAMPLE_QAPI_EVENT_MY_EVENT = 0, EXAMPLE_QAPI_EVENT_MAX = 1, } example_QAPIEvent;
scripts/qapi-commands.py +1 -0
@@ -218,6 +218,7 @@ def gen_marshal_input(name, args, ret_type, middle_mode): ret += mcgen(''' (void)args; + ''') ret += gen_sync_call(name, args, ret_type)
scripts/qapi-event.py +1 -2
@@ -167,8 +167,7 @@ extern const char *%(event_enum_name)s_lookup[]; event_enum_name = event_enum_name) enum_decl = mcgen(''' -typedef enum %(event_enum_name)s -{ +typedef enum %(event_enum_name)s { ''', event_enum_name = event_enum_name)
scripts/qapi-types.py +31 -35
181 lines not on this page · raw message
scripts/qapi-visit.py +1 -0
@@ -62,6 +62,7 @@ def generate_visit_struct_fields(name, members, base = None): static void visit_type_%(name)s_fields(Visitor *m, %(name)s **obj, Error **errp) { Error *err = NULL; + ''', name=c_name(name)) push_indent()
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH 02/26] qapi: Clean up cgen() and mcgen()
In reply to Markus ArmbrusterQuoted 55 lines · Markus Armbruster
Commit 05dfb26 added eatspace stripping to
mcgen(). Move it tocgen(), just in case somebody gets tempted to usecgen()directly instead of viamcgen().
cgen()indents blank lines. No such lines get generated right now, but fix it anyway.We use triple-quoted strings for program text, like this:
''' Program text any number of lines '''Keeps the program text relatively readable, but puts an extra newline at either end.
mcgen()"fixes" that by dropping the first and last line outright. Drop only the newlines.This unmasks a bug in
qapi-commands.py: four quotes instead of three. Fix it up.Output doesn't change
Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Eric Blake <[email protected]>--- scripts/qapi-commands.py | 2 +- scripts/qapi.py | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-)scripts/qapi-commands.py +1
-1@@ -56,7 +56,7 @@ def gen_sync_call(name, args, ret_type, indent=0): name=c_name(name), args=arglist, retval=retval).rstrip() if ret_type: ret += "\n" + gen_err_check('local_err') - ret += "\n" + mcgen('''' + ret += "\n" + mcgen(''' %(marshal_output_call)s ''', marshal_output_call=gen_marshal_output_call(name, ret_type)).rstrip()scripts/qapi.py +2
-1@@ -943,16 +943,21 @@ def pop_indent(indent_amount=4): global indent_level indent_level -= indent_amount +# Generate @code with @kwds interpolated. +# Obey indent_level, and strip eatspace. def cgen(code, **kwds): - indent = genindent(indent_level)
scripts/qapi.py def pop_indent(indent_amount=4): · line 952
Quoted 10 lines
scripts/qapi.py +4
-6- lines = code.split('\n') - lines = map(lambda x: indent + x, lines) - return '\n'.join(lines) % kwds + '\n' - -def mcgen(code, **kwds): - raw = cgen('\n'.join(code.split('\n')[1:-1]), **kwds) + raw = code % kwds + if indent_level: + indent = genindent(indent_level) + raw = re.subn("^.", indent + '\g<0>', raw, 0, re.MULTILINE)
pylint wants us to use r'\g<0>'. If nothing else comes up, I'll fix this up for my pull.
Quoted 10 lines
scripts/qapi.py +6
-0+ raw = raw[0] return re.sub(re.escape(eatspace) + ' *', '', raw) +def mcgen(code, **kwds): + if code[0] == '\n': + code = code[1:] + return cgen(code, **kwds) + def basename(filename): return filename.split("/")[-1]
Re: [Qemu-devel] [PATCH 07/26] qapi: Fix generated code when flat union has member 'kind'
In reply to Markus ArmbrusterQuoted 2 lines · Markus Armbruster
A flat union's tag member gets renamed to 'kind' in the generated code. Breaks when another member is named 'kind' exists.
Too many verbs. Drop either 'is' or 'exists'.
Quoted 22 lines
Example, adapted from qapi-schema-test.json:
{ 'struct': 'UserDefUnionBase',
'data': { 'kind': 'str', 'enum1': 'EnumOne' } }We generate:
struct UserDefFlatUnion { EnumOne kind; union { void *data; UserDefA *value1; UserDefB *value2; UserDefB *value3; }; char *kind; };Kill the silly rename.
Quoted 8 lines
Reported-by Eric Blake <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi-types.py | 3 ++- scripts/qapi-visit.py | 7 +++++-- tests/test-qmp-input-visitor.c | 2 +- tests/test-qmp-output-visitor.c | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 02/26] qapi: Clean up cgen() and mcgen()
In reply to Markus ArmbrusterQuoted 23 lines · Markus Armbruster
Quoted 14 lines · Markus Armbruster
Commit 05dfb26 added eatspace stripping to
mcgen(). Move it tocgen(), just in case somebody gets tempted to usecgen()directly instead of viamcgen().Output doesn't change
Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Eric Blake <[email protected]>--- scripts/qapi-commands.py | 2 +- scripts/qapi.py | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-)scripts/qapi.py def pop_indent(indent_amount=4): · line 952
Quoted 6 lines
scripts/qapi.py +4
-2-def mcgen(code, **kwds): - raw = cgen('\n'.join(code.split('\n')[1:-1]), **kwds) + raw = code % kwds + if indent_level: + indent = genindent(indent_level) + raw = re.subn("^.", indent + '\g<0>', raw, 0, re.MULTILINE)
Quoted 3 lines
pylint wants us to use r'\g<0>'. If nothing else comes up, I'll fix this up for my pull.
Goes to show that I've never (yet) used pylint. I probably ought to :)
Fine by me to make that tweak and keep my R-b.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 08/26] qapi: Generate a nicer struct for flat unions
In reply to Markus ArmbrusterQuoted 8 lines · Markus Armbruster
The struct generated for a flat union is weird: the members of its base are at the end, except for the union tag, which is at the beginning.
Change to put all base members at the beginning, unadulterated. Not only is this easier to understand, it also permits casting the flat union to its base, if that should become useful.
And I already have a followup patch to your RFCv3 where it IS useful :)
Quoted 17 lines
We now generate:
struct UserDefFlatUnion { /* Members inherited from UserDefUnionBase: */ char *string; EnumOne enum1; /* Own members: */ union { /* union tag is @enum1 */ void *data; UserDefA *value1; UserDefB *value2; UserDefB *value3; }; };
Quoted 5 lines
Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi-types.py | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 16/26] qapi: Document flaws in checking of names
In reply to Markus ArmbrusterQuoted 10 lines · Markus Armbruster
We don't actually enforce our "other than downstream extensions [...], all names should begin with a letter" rule. Add a FIXME.
We should reject names that differ only in '_' vs. '.' vs. '-', because they're liable to clash in generated C. Add a FIXME.
Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi.py | 4 ++++ 1 file changed, 4 insertions(+)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 18/26] tests/qapi-schema: Rename tests from data- to args-
In reply to Markus ArmbrusterQuoted 10 lines · Markus Armbruster
Since every schema entity has 'data', the data- prefix conveys no information. These tests actually exercise commands. Only commands have arguments, so change the prefix to to args-.
Signed-off-by Markus Armbruster <[email protected]>--- tests/Makefile | 6 +++--- tests/qapi-schema/{data-array-empty.err => args-array-empty.err} | 2 +- tests/qapi-schema/{data-unknown.exit => args-array-empty.exit} | 0 tests/qapi-schema/{data-array-empty.json => args-array-empty.json} | 0
git rename detection doesn't work too well when renaming identical contents :) Thankfully, it all works out in the end, and the Makefile changes are the easiest way to review this. And thank goodness that git compresses renames in patches; this email would have been a lot longer by traditional diff.
Quoted 5 lines
tests/Makefile +0
-0
tests/Makefile check-qapi-schema-y := $(addprefix tests/qapi-schema/, \ · line 235
Quoted 10 lines
tests/Makefile +3
-3@@ -229,9 +229,9 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \ redefined-type.json redefined-command.json redefined-builtin.json \ redefined-event.json command-int.json bad-data.json event-max.json \ type-bypass.json type-bypass-no-gen.json type-bypass-bad-gen.json \ - data-array-empty.json data-array-unknown.json data-int.json \ - data-unknown.json data-member-unknown.json data-member-array.json \ - data-member-array-bad.json returns-array-bad.json returns-int.json \ + args-array-empty.json args-array-unknown.json args-int.json \ + args-unknown.json args-member-unknown.json args-member-array.json \ + args-member-array-bad.json returns-array-bad.json returns-int.json \ returns-unknown.json returns-alternate.json returns-whitelist.json \
7 sets of files renamed, including fallout to the changed error messages.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 20/26] qapi: Fix to reject union command and event arguments
In reply to Markus ArmbrusterQuoted 9 lines · Markus Armbruster
A command's or event's 'data' must be a struct type, given either as a dictionary, or as struct type name.
Commit dd883c6 tightened the checking there, but not enough: we still accept 'union'. Fix to reject it.
We may want to support union types there, but we'll have to extend
qapi-commands.pyandqapi-events.pyfor it.
Quoted 9 lines
Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi.py | 4 ++-- tests/qapi-schema/args-union.err | 1 + tests/qapi-schema/args-union.exit | 2 +- tests/qapi-schema/args-union.json | 2 +- tests/qapi-schema/args-union.out | 4 ---- 5 files changed, 5 insertions(+), 8 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 21/26] qapi: Command returning anonymous type doesn't work, outlaw
In reply to Markus ArmbrusterQuoted 16 lines · Markus Armbruster
Reproducer: with
{ 'command': 'user_def_cmd4', 'returns': { 'a': 'int' } }added to qapi-schema-test.json,
qapi-commands.pydies when it tries to generate the command handler functionTraceback (most recent call last):
File "/work/armbru/qemu/scripts/qapi-commands.py", line 359, in <module>
ret =generate_command_decl(cmd['command'], arglist, ret_type)+ "\n"
File "/work/armbru/qemu/scripts/qapi-commands.py", line 29, ingenerate_command_decl
ret_type=c_type(ret_type), name=c_name(name),
File "/work/armbru/qemu/scripts/qapi.py", line 927, inc_type
assertisinstance(value, str)and value != ""
AssertionError
Quoted 3 lines
because the return type doesn't exist.
Simply outlaw this usage.
Might be worth allowing someday, but that would imply that we can come up with a sane naming scheme for anonymous structs in the qapi schema that won't risk collisions with explicit types. Shame on me for not thinking to test this in my earlier testsuite additions, but I definitely agree with your solution of outlawing it for now.
Quoted 13 lines
Signed-off-by Markus Armbruster <[email protected]>--- docs/qapi-code-gen.txt | 17 ++++++++--------- scripts/qapi.py | 2 +- tests/Makefile | 4 ++-- tests/qapi-schema/nested-struct-returns.err | 1 - tests/qapi-schema/nested-struct-returns.json | 3 --- tests/qapi-schema/returns-dict.err | 1 + .../{nested-struct-returns.exit => returns-dict.exit} | 0 tests/qapi-schema/returns-dict.json | 2 ++ .../{nested-struct-returns.out => returns-dict.out} | 0 9 files changed, 14 insertions(+), 16 deletions(-)
Once again, git rename detection didn't accurately capture what you did :)
Quoted 7 lines
delete mode 100644 tests/qapi-schema/nested-struct-returns.err
delete mode 100644 tests/qapi-schema/nested-struct-returns.json
create mode 100644 tests/qapi-schema/returns-dict.err
rename tests/qapi-schema/{nested-struct-returns.exit => returns-dict.exit} (100%)
create mode 100644 tests/qapi-schema/returns-dict.json
rename tests/qapi-schema/{nested-struct-returns.out => returns-dict.out} (100%)git grep "'returns'.*{"
found a couple more culprits (tests that fail elsewhere prior to warning about this, but where an anonymous return does not add to the negative test). Please squash this in:
(quoted diff) +0 -0
w/tests/qapi-schema/command-int.json
index c90d408..40a6ae3 100644
tests/qapi-schema/command-int.json +2 -1
@@ -1,3 +1,4 @@ # we reject collisions between commands and types { 'command': 'int', 'data': { 'character': 'str' }, - 'returns': { 'value': 'int' } } + 'returns': 'Foo' } +{ 'struct': 'Foo', 'data': { 'value': 'int' } }
(quoted diff) +0 -0
w/tests/qapi-schema/nested-struct-data.json
index 3d52d2b..efbe773 100644
tests/qapi-schema/nested-struct-data.json +1 -2
@@ -1,4 +1,3 @@ # inline subtypes collide with our desired future use of defaults { 'command': 'foo', - 'data': { 'a' : { 'string' : 'str', 'integer': 'int' }, 'b' : 'str' }, - 'returns': {} } + 'data': { 'a' : { 'string' : 'str', 'integer': 'int' }, 'b' : 'str' } }
at which point you may add:
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 25/26] qapi-commands: Drop useless initialization
In reply to Markus ArmbrusterQuoted 9 lines · Markus Armbruster
In generated command handlers, the assignment to retval dominates its only use. Therefore, its initialization is useless. Drop it.
Suggested-by Eric Blake <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- docs/qapi-code-gen.txt | 2 +- scripts/qapi-commands.py | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 26/26] qapi: Generated code cleanup
In reply to Markus ArmbrusterQuoted 12 lines · Markus Armbruster
Clean up white-space, brace placement, and superfluous #ifdef
QAPI_TYPES_BUILTIN_CLEANUP_DEF.Signed-off-by Markus Armbruster <[email protected]>--- docs/qapi-code-gen.txt | 12 ++++----- scripts/qapi-commands.py | 1 + scripts/qapi-event.py | 3 +-- scripts/qapi-types.py | 66 +++++++++++++++++++++++------------------------- scripts/qapi-visit.py | 1 + 5 files changed, 39 insertions(+), 44 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 07/26] qapi: Fix generated code when flat union has member 'kind'
In reply to Eric BlakeQuoted 5 lines · Eric Blake
Quoted 2 lines · Markus Armbruster
A flat union's tag member gets renamed to 'kind' in the generated code. Breaks when another member is named 'kind' exists.
Too many verbs. Drop either 'is' or 'exists'.
Will fix.
Quoted 31 lines
Quoted 22 lines
Example, adapted from qapi-schema-test.json:
{ 'struct': 'UserDefUnionBase',
'data': { 'kind': 'str', 'enum1': 'EnumOne' } }We generate:
struct UserDefFlatUnion { EnumOne kind; union { void *data; UserDefA *value1; UserDefB *value2; UserDefB *value3; }; char *kind; };Kill the silly rename.
Quoted 8 lines
Reported-by Eric Blake <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi-types.py | 3 ++- scripts/qapi-visit.py | 7 +++++-- tests/test-qmp-input-visitor.c | 2 +- tests/test-qmp-output-visitor.c | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-)
Quoted 1 line
Reviewed-by Eric Blake <[email protected]>
Thanks!
Re: [Qemu-devel] [PATCH 21/26] qapi: Command returning anonymous type doesn't work, outlaw
In reply to Eric BlakeQuoted 65 lines · Eric Blake
Quoted 16 lines · Markus Armbruster
Reproducer: with
{ 'command': 'user_def_cmd4', 'returns': { 'a': 'int' } }added to qapi-schema-test.json,
qapi-commands.pydies when it tries to generate the command handler functionTraceback (most recent call last):
File "/work/armbru/qemu/scripts/qapi-commands.py", line 359, in <module>
ret =generate_command_decl(cmd['command'], arglist, ret_type)+ "\n"
File "/work/armbru/qemu/scripts/qapi-commands.py", line 29, ingenerate_command_decl
ret_type=c_type(ret_type), name=c_name(name),
File "/work/armbru/qemu/scripts/qapi.py", line 927, inc_type
assertisinstance(value, str)and value != ""
AssertionErrorQuoted 3 lines
because the return type doesn't exist.
Simply outlaw this usage.
Might be worth allowing someday, but that would imply that we can come up with a sane naming scheme for anonymous structs in the qapi schema that won't risk collisions with explicit types. Shame on me for not thinking to test this in my earlier testsuite additions, but I definitely agree with your solution of outlawing it for now.
Quoted 13 lines
Signed-off-by Markus Armbruster <[email protected]>--- docs/qapi-code-gen.txt | 17 ++++++++--------- scripts/qapi.py | 2 +- tests/Makefile | 4 ++-- tests/qapi-schema/nested-struct-returns.err | 1 - tests/qapi-schema/nested-struct-returns.json | 3 --- tests/qapi-schema/returns-dict.err | 1 + .../{nested-struct-returns.exit => returns-dict.exit} | 0 tests/qapi-schema/returns-dict.json | 2 ++ .../{nested-struct-returns.out => returns-dict.out} | 0 9 files changed, 14 insertions(+), 16 deletions(-)Once again, git rename detection didn't accurately capture what you did :)
Quoted 9 lines
delete mode 100644 tests/qapi-schema/nested-struct-returns.err delete mode 100644 tests/qapi-schema/nested-struct-returns.json create mode 100644 tests/qapi-schema/returns-dict.err rename tests/qapi-schema/{nested-struct-returns.exit => returns-dict.exit} (100%) create mode 100644 tests/qapi-schema/returns-dict.json rename tests/qapi-schema/{nested-struct-returns.out =>returns-dict.out} (100%)
git grep "'returns'.*{"
found a couple more culprits (tests that fail elsewhere prior to warning about this, but where an anonymous return does not add to the negative test). Please squash this in:
(quoted diff) +0
-0
w/tests/qapi-schema/command-int.json
index c90d408..40a6ae3 100644
tests/qapi-schema/command-int.json line 4
Quoted 5 lines
tests/qapi-schema/command-int.json +2
-1@@ -1,3 +1,4 @@ # we reject collisions between commands and types { 'command': 'int', 'data': { 'character': 'str' }, - 'returns': { 'value': 'int' } } + 'returns': 'Foo' } +{ 'struct': 'Foo', 'data': { 'value': 'int' } }
Okay to simply drop the 'returns' instead?
Quoted 13 lines
(quoted diff) +0
-0
w/tests/qapi-schema/nested-struct-data.json
index 3d52d2b..efbe773 100644tests/qapi-schema/nested-struct-data.json +1
-2@@ -1,4 +1,3 @@ # inline subtypes collide with our desired future use of defaults { 'command': 'foo', - 'data': { 'a' : { 'string' : 'str', 'integer': 'int' }, 'b' : 'str' }, - 'returns': {} } + 'data': { 'a' : { 'string' : 'str', 'integer': 'int' }, 'b' : 'str' } }
Quoted 3 lines
at which point you may add:
Reviewed-by Eric Blake <[email protected]>
Thanks!
Re: [Qemu-devel] [PATCH 21/26] qapi: Command returning anonymous type doesn't work, outlaw
Quoted 11 lines · Markus Armbruster
Quoted 8 lines · Eric Blake
Quoted 7 lines · Markus Armbruster
Reproducer: with
{ 'command': 'user_def_cmd4', 'returns': { 'a': 'int' } }added to qapi-schema-test.json,
qapi-commands.pydies when it tries to generate the command handler function
Quoted 10 lines
tests/qapi-schema/command-int.json line 4
Quoted 7 lines
+++
w/tests/qapi-schema/command-int.jsontests/qapi-schema/command-int.json +2
-1@@ -1,3 +1,4 @@ # we reject collisions between commands and types { 'command': 'int', 'data': { 'character': 'str' }, - 'returns': { 'value': 'int' } } + 'returns': 'Foo' } +{ 'struct': 'Foo', 'data': { 'value': 'int' } }Okay to simply drop the 'returns' instead?
Sure, that works too.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 21/26] qapi: Command returning anonymous type doesn't work, outlaw
Quoted 23 lines · Eric Blake
Quoted 11 lines · Markus Armbruster
Quoted 8 lines · Eric Blake
Quoted 7 lines · Markus Armbruster
Reproducer: with
{ 'command': 'user_def_cmd4', 'returns': { 'a': 'int' } }added to qapi-schema-test.json,
qapi-commands.pydies when it tries to generate the command handler functionQuoted 10 lines
tests/qapi-schema/command-int.json line 4
Quoted 7 lines
+++
w/tests/qapi-schema/command-int.jsontests/qapi-schema/command-int.json +2
-1@@ -1,3 +1,4 @@ # we reject collisions between commands and types { 'command': 'int', 'data': { 'character': 'str' }, - 'returns': { 'value': 'int' } } + 'returns': 'Foo' } +{ 'struct': 'Foo', 'data': { 'value': 'int' } }Okay to simply drop the 'returns' instead?
Quoted 1 line
Sure, that works too.
Done, with commit message amended:
Simply outlaw this usage, and drop or dumb down test cases accordingly.
Re: [Qemu-devel] [PATCH 20/26] qapi: Fix to reject union command and event arguments
In reply to Markus ArmbrusterQuoted 9 lines · Markus Armbruster
A command's or event's 'data' must be a struct type, given either as a dictionary, or as struct type name.
Commit dd883c6 tightened the checking there, but not enough: we still accept 'union'. Fix to reject it.
We may want to support union types there, but we'll have to extend
qapi-commands.pyandqapi-events.pyfor it.
Quoted 8 lines
Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi.py | 4 ++-- tests/qapi-schema/args-union.err | 1 + tests/qapi-schema/args-union.exit | 2 +- tests/qapi-schema/args-union.json | 2 +- tests/qapi-schema/args-union.out | 4 ---- 5 files changed, 5 insertions(+), 8 deletions(-)
Our documentation is also wrong; you may want to squash this in:
docs/qapi-code-gen.txt +3 -4
@@ -408,10 +408,9 @@ Client JSON Protocol command exchange. The 'data' argument maps to the "arguments" dictionary passed in as part of a Client JSON Protocol command. The 'data' member is optional and defaults to {} (an empty dictionary). If present, it must be the -string name of a complex type, a one-element array containing the name -of a complex type, or a dictionary that declares an anonymous type -with the same semantics as a 'struct' expression, with one exception -noted below when 'gen' is used. +string name of a complex type, or a dictionary that declares an +anonymous type with the same semantics as a 'struct' expression, with +one exception noted below when 'gen' is used. The 'returns' member describes what will appear in the "return" field of a Client JSON Protocol reply on successful completion of a command.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 20/26] qapi: Fix to reject union command and event arguments
Quoted 29 lines · Eric Blake
Quoted 9 lines · Markus Armbruster
A command's or event's 'data' must be a struct type, given either as a dictionary, or as struct type name.
Commit dd883c6 tightened the checking there, but not enough: we still accept 'union'. Fix to reject it.
We may want to support union types there, but we'll have to extend
qapi-commands.pyandqapi-events.pyfor it.Quoted 8 lines
Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi.py | 4 ++-- tests/qapi-schema/args-union.err | 1 + tests/qapi-schema/args-union.exit | 2 +- tests/qapi-schema/args-union.json | 2 +- tests/qapi-schema/args-union.out | 4 ---- 5 files changed, 5 insertions(+), 8 deletions(-)Our documentation is also wrong; you may want to squash this in:
docs/qapi-code-gen.txt +0
-0@@ -408,10 +408,9 @@ Client JSON Protocol command exchange. The 'data' argument maps to the "arguments" dictionary passed in as part of a Client JSON Protocol command. The 'data' member is optional and defaults to {} (an empty dictionary). If present, it must be the
docs/qapi-code-gen.txt Client JSON Protocol command exchange. · line 416
Quoted 10 lines
docs/qapi-code-gen.txt +3
-4-string name of a complex type, a one-element array containing the name -of a complex type, or a dictionary that declares an anonymous type -with the same semantics as a 'struct' expression, with one exception -noted below when 'gen' is used. +string name of a complex type, or a dictionary that declares an +anonymous type with the same semantics as a 'struct' expression, with +one exception noted below when 'gen' is used. The 'returns' member describes what will appear in the "return" field of a Client JSON Protocol reply on successful completion of a command.
Will do, thanks!