drop qapi nested structs
cover drop qapi nested structs
According to this email:
https://lists.gnu.org/archive/html/qemu-devel/2014-05/msg00708.html
we want to repurpose 'data': { 'name': {dict...} } in qapi files for future use of designating default values of optional parameters. But to do that, we must first nuke existing use of that syntax for declaring nested structs. Enhancing the testsuite while at it never hurts.
Eric Blake (7):
qapi: add some enum tests
qapi: better error message for bad enum
qapi: merge UserDefTwo and UserDefNested in tests
qapi: drop tests for inline subtypes
qapi: drop inline subtype in query-version
qapi: drop inline subtype in query-pci
qapi: drop support for inline subtypes
hmp.c | 28 ++++----- hw/pci/pci.c | 42 +++++++------ qapi-schema.json | 90 +++++++++++++++++++--------- qapi/common.json | 26 +++++--- qmp.c | 9 +-- scripts/qapi-commands.py | 8 +-- scripts/qapi-event.py | 4 +- scripts/qapi-types.py | 9 +-- scripts/qapi-visit.py | 37 ++---------- scripts/qapi.py | 52 ++++++++++------ tests/Makefile | 6 +- tests/qapi-schema/enum-empty.err | 0 tests/qapi-schema/enum-empty.exit | 1 + tests/qapi-schema/enum-empty.json | 1 + tests/qapi-schema/enum-empty.out | 3 + tests/qapi-schema/enum-missing-data.err | 1 + tests/qapi-schema/enum-missing-data.exit | 1 + tests/qapi-schema/enum-missing-data.json | 1 + tests/qapi-schema/enum-missing-data.out | 0 tests/qapi-schema/enum-wrong-data.err | 1 + tests/qapi-schema/enum-wrong-data.exit | 1 + tests/qapi-schema/enum-wrong-data.json | 1 + tests/qapi-schema/enum-wrong-data.out | 0 tests/qapi-schema/event-nest-struct.err | 2 +- tests/qapi-schema/nested-struct-data.err | 1 + tests/qapi-schema/nested-struct-data.exit | 1 + tests/qapi-schema/nested-struct-data.json | 3 + tests/qapi-schema/nested-struct-data.out | 0 tests/qapi-schema/nested-struct-returns.err | 1 + tests/qapi-schema/nested-struct-returns.exit | 1 + tests/qapi-schema/nested-struct-returns.json | 2 + tests/qapi-schema/nested-struct-returns.out | 0 tests/qapi-schema/qapi-schema-test.json | 18 +++--- tests/qapi-schema/qapi-schema-test.out | 10 ++-- tests/test-qmp-commands.c | 35 ++++++----- tests/test-qmp-input-strict.c | 19 +++--- tests/test-qmp-input-visitor.c | 25 ++++---- tests/test-qmp-output-visitor.c | 64 +++++++++++--------- tests/test-visitor-serialization.c | 84 ++++++++++++++------------ 39 files changed, 334 insertions(+), 254 deletions(-) create mode 100644 tests/qapi-schema/enum-empty.err create mode 100644 tests/qapi-schema/enum-empty.exit create mode 100644 tests/qapi-schema/enum-empty.json create mode 100644 tests/qapi-schema/enum-empty.out create mode 100644 tests/qapi-schema/enum-missing-data.err create mode 100644 tests/qapi-schema/enum-missing-data.exit create mode 100644 tests/qapi-schema/enum-missing-data.json create mode 100644 tests/qapi-schema/enum-missing-data.out create mode 100644 tests/qapi-schema/enum-wrong-data.err create mode 100644 tests/qapi-schema/enum-wrong-data.exit create mode 100644 tests/qapi-schema/enum-wrong-data.json create mode 100644 tests/qapi-schema/enum-wrong-data.out create mode 100644 tests/qapi-schema/nested-struct-data.err create mode 100644 tests/qapi-schema/nested-struct-data.exit create mode 100644 tests/qapi-schema/nested-struct-data.json create mode 100644 tests/qapi-schema/nested-struct-data.out create mode 100644 tests/qapi-schema/nested-struct-returns.err create mode 100644 tests/qapi-schema/nested-struct-returns.exit create mode 100644 tests/qapi-schema/nested-struct-returns.json create mode 100644 tests/qapi-schema/nested-struct-returns.out
Signature · 1 line
1.9.3
PATCH 1/7 qapi: add some enum tests
Demonstrate that the qapi generator doesn't deal well with enums that aren't up to par. Later patches can improve the expected results as the generator is made stricter.
* tests/qapi-schema/enum-empty.*: New files.
* tests/qapi-schema/enum-missing-data.*: Likewise.
* tests/qapi-schema/enum-wrong-data.*: Likewise.
* tests/Makefile (check-qapi-schema-y): Run them.
--- tests/Makefile | 3 ++- tests/qapi-schema/enum-empty.err | 0 tests/qapi-schema/enum-empty.exit | 1 + tests/qapi-schema/enum-empty.json | 1 + tests/qapi-schema/enum-empty.out | 3 +++ tests/qapi-schema/enum-missing-data.err | 6 ++++++ tests/qapi-schema/enum-missing-data.exit | 1 + tests/qapi-schema/enum-missing-data.json | 1 + tests/qapi-schema/enum-missing-data.out | 0 tests/qapi-schema/enum-wrong-data.err | 0 tests/qapi-schema/enum-wrong-data.exit | 1 + tests/qapi-schema/enum-wrong-data.json | 1 + tests/qapi-schema/enum-wrong-data.out | 3 +++ 13 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/qapi-schema/enum-empty.err create mode 100644 tests/qapi-schema/enum-empty.exit create mode 100644 tests/qapi-schema/enum-empty.json create mode 100644 tests/qapi-schema/enum-empty.out create mode 100644 tests/qapi-schema/enum-missing-data.err create mode 100644 tests/qapi-schema/enum-missing-data.exit create mode 100644 tests/qapi-schema/enum-missing-data.json create mode 100644 tests/qapi-schema/enum-missing-data.out create mode 100644 tests/qapi-schema/enum-wrong-data.err create mode 100644 tests/qapi-schema/enum-wrong-data.exit create mode 100644 tests/qapi-schema/enum-wrong-data.json create mode 100644 tests/qapi-schema/enum-wrong-data.out
tests/Makefile +2 -1
@@ -190,7 +190,8 @@ $(foreach target,$(SYSEMU_TARGET_LIST), \ $(eval check-qtest-$(target)-y += tests/qom-test$(EXESUF))) check-qapi-schema-y := $(addprefix tests/qapi-schema/, \ - comments.json empty.json funny-char.json indented-expr.json \ + comments.json empty.json enum-empty.json enum-missing-data.json \ + enum-wrong-data.json funny-char.json indented-expr.json \ missing-colon.json missing-comma-list.json \ missing-comma-object.json non-objects.json \ qapi-schema-test.json quoted-structural-chars.json \
tests/qapi-schema/enum-empty.err new file +0 -0
tests/qapi-schema/enum-empty.exit new file +1 -0
@@ -0,0 +1 @@ +0
tests/qapi-schema/enum-empty.json new file +1 -0
@@ -0,0 +1 @@ +{ 'enum': 'MyEnum', 'data': [ ] }
tests/qapi-schema/enum-empty.out new file +3 -0
@@ -0,0 +1,3 @@ +[OrderedDict([('enum', 'MyEnum'), ('data', [])])] +[{'enum_name': 'MyEnum', 'enum_values': []}] +[]
tests/qapi-schema/enum-missing-data.err new file +6 -0
@@ -0,0 +1,6 @@ +Traceback (most recent call last): + File "tests/qapi-schema/test-qapi.py", line 19, in <module> + exprs = parse_schema(sys.argv[1]) + File "scripts/qapi.py", line 339, in parse_schema + add_enum(expr['enum'], expr['data']) +KeyError: 'data'
tests/qapi-schema/enum-missing-data.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/enum-missing-data.json new file +1 -0
@@ -0,0 +1 @@ +{ 'enum': 'MyEnum' }
tests/qapi-schema/enum-missing-data.out new file +0 -0
tests/qapi-schema/enum-wrong-data.err new file +0 -0
tests/qapi-schema/enum-wrong-data.exit new file +1 -0
@@ -0,0 +1 @@ +0
tests/qapi-schema/enum-wrong-data.json new file +1 -0
@@ -0,0 +1 @@ +{ 'enum': 'MyEnum', 'data': { 'value': 'str' } }
tests/qapi-schema/enum-wrong-data.out new file +3 -0
@@ -0,0 +1,3 @@ +[OrderedDict([('enum', 'MyEnum'), ('data', OrderedDict([('value', 'str')]))])] +[{'enum_name': 'MyEnum', 'enum_values': OrderedDict([('value', 'str')])}] +[]
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH 1/7] qapi: add some enum tests
tests/Makefile $(foreach target,$(SYSEMU_TARGET_LIST), \ · line 194
Quoted 11 lines · Eric Blake
tests/Makefile +2
-1@@ -190,7 +190,8 @@ $(foreach target,$(SYSEMU_TARGET_LIST), \ $(eval check-qtest-$(target)-y += tests/qom-test$(EXESUF))) check-qapi-schema-y := $(addprefix tests/qapi-schema/, \ - comments.json empty.json funny-char.json indented-expr.json \ + comments.json empty.json enum-empty.json enum-missing-data.json \ + enum-wrong-data.json funny-char.json indented-expr.json \
Misaligned. Please use soft tab.
PATCH 2/7 qapi: better error message for bad enum
In reply to Eric BlakeThe previous test demonstrated that the generator choked if an enum forgot 'data', and silently ignored an enum where 'data' was the wrong type. Fix both cases to give a sane error message.
* scripts/qapi.py (parse_schema): Avoid bad deref. (check_exprs): Check for array on enums.
* tests/qapi-schema/enum-missing-data.err: Update expected results.
* tests/qapi-schema/enum-wrong-data.*: Likewise.
--- scripts/qapi.py | 16 ++++++++++++---- tests/qapi-schema/enum-missing-data.err | 7 +------ tests/qapi-schema/enum-wrong-data.err | 1 + tests/qapi-schema/enum-wrong-data.exit | 2 +- tests/qapi-schema/enum-wrong-data.out | 3 --- 5 files changed, 15 insertions(+), 14 deletions(-)
scripts/qapi.py +12 -4
@@ -2,7 +2,7 @@ # QAPI helper library # # Copyright IBM, Corp. 2011 -# Copyright (c) 2013 Red Hat Inc. +# Copyright (c) 2013-2014 Red Hat Inc. # # Authors: # Anthony Liguori <[email protected]>
@@ -319,10 +319,18 @@ def check_union(expr, expr_info): def check_exprs(schema): for expr_elem in schema.exprs: expr = expr_elem['expr'] + info = expr_elem['info'] + members = expr.get('data') + if expr.has_key('union'): - check_union(expr, expr_elem['info']) + check_union(expr, info) if expr.has_key('event'): - check_event(expr, expr_elem['info']) + check_event(expr, info) + if expr.has_key('enum'): + if not isinstance(members, list): + raise QAPIExprError(info, + "enum '%s' requires an array for 'data'" + % expr.get('enum')) def parse_schema(input_file): try:
@@ -335,7 +343,7 @@ def parse_schema(input_file): for expr_elem in schema.exprs: expr = expr_elem['expr'] - if expr.has_key('enum'): + if expr.has_key('enum') and expr.has_key('data'): add_enum(expr['enum'], expr['data']) elif expr.has_key('union'): add_union(expr)
tests/qapi-schema/enum-missing-data.err +1 -6
@@ -1,6 +1 @@ -Traceback (most recent call last): - File "tests/qapi-schema/test-qapi.py", line 19, in <module> - exprs = parse_schema(sys.argv[1]) - File "scripts/qapi.py", line 339, in parse_schema - add_enum(expr['enum'], expr['data']) -KeyError: 'data' +tests/qapi-schema/enum-missing-data.json:1: enum 'MyEnum' requires an array for 'data'
tests/qapi-schema/enum-wrong-data.err +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/enum-wrong-data.json:1: enum 'MyEnum' requires an array for 'data'
tests/qapi-schema/enum-wrong-data.exit +1 -1
@@ -1 +1 @@ -0 +1
tests/qapi-schema/enum-wrong-data.out +0 -3
@@ -1,3 +0,0 @@ -[OrderedDict([('enum', 'MyEnum'), ('data', OrderedDict([('value', 'str')]))])] -[{'enum_name': 'MyEnum', 'enum_values': OrderedDict([('value', 'str')])}] -[]
Signature · 1 line
1.9.3
PATCH 3/7 qapi: merge UserDefTwo and UserDefNested in tests
In reply to Eric BlakeIn the testsuite, UserDefTwo and UserDefNested were identical types other than the member names. Reduce code duplication by having just one type, and choose names that also favor reuse. This will also make it easier for a later patch to get rid of nested inline subtypes in QAPI.
Ensure that 'make check-qapi-schema check-unit' still passes. Wrap some long lines to keep checkpatch happy.
* tests/qapi-schema/qapi-schema-test.json (UserDefNested): Drop. (UserDefTwo): Rename element members for clarity.
* tests/qapi-schema/qapi-schema-test.out: Update expected output.
* tests/test-qmp-output-visitor.c (test_visitor_out_struct_nested, test_visitor_out_list_qapi_free):
Update clients.
* tests/test-qmp-input-visitor.c (test_visitor_in_struct_nested):
Likewise.
* tests/test-qmp-input-strict.c (test_validate_struct_nested) (test_validate_fail_struct_nested): Likewise.
* tests/test-qmp-commands.c (qmp_user_def_cmd2) (test_dealloc_partial, test_dispatch_cmd_io): Likewise.
* tests/test-visitor-serialization.c (nested_struct_create) (nested_struct_compare, nested_struct_cleanup) (visit_nested_struct, visit_nested_struct_list) (test_nested_struct, test_nested_struct_list): Likewise.
--- tests/qapi-schema/qapi-schema-test.json | 10 +---- tests/qapi-schema/qapi-schema-test.out | 6 +-- tests/test-qmp-commands.c | 32 +++++++-------- tests/test-qmp-input-strict.c | 19 +++++---- tests/test-qmp-input-visitor.c | 19 +++++---- tests/test-qmp-output-visitor.c | 50 +++++++++++------------ tests/test-visitor-serialization.c | 71 +++++++++++++++++---------------- 7 files changed, 103 insertions(+), 104 deletions(-)
tests/qapi-schema/qapi-schema-test.json +2 -8
@@ -15,16 +15,10 @@ 'data': { 'string': 'str', '*enum1': 'EnumOne' } } { 'type': 'UserDefTwo', - 'data': { 'string': 'str', - 'dict': { 'string': 'str', - 'dict': { 'userdef': 'UserDefOne', 'string': 'str' }, - '*dict2': { 'userdef': 'UserDefOne', 'string': 'str' } } } } - -{ 'type': 'UserDefNested', 'data': { 'string0': 'str', 'dict1': { 'string1': 'str', - 'dict2': { 'userdef1': 'UserDefOne', 'string2': 'str' }, - '*dict3': { 'userdef2': 'UserDefOne', 'string3': 'str' } } } } + 'dict2': { 'userdef': 'UserDefOne', 'string': 'str' }, + '*dict3': { 'userdef': 'UserDefOne', 'string': 'str' } } } } # for testing unions { 'type': 'UserDefA',
tests/qapi-schema/qapi-schema-test.out +2 -4
@@ -2,8 +2,7 @@ OrderedDict([('type', 'NestedEnumsOne'), ('data', OrderedDict([('enum1', 'EnumOne'), ('*enum2', 'EnumOne'), ('enum3', 'EnumOne'), ('*enum4', 'EnumOne')]))]), OrderedDict([('type', 'UserDefZero'), ('data', OrderedDict([('integer', 'int')]))]), OrderedDict([('type', 'UserDefOne'), ('base', 'UserDefZero'), ('data', OrderedDict([('string', 'str'), ('*enum1', 'EnumOne')]))]), - OrderedDict([('type', 'UserDefTwo'), ('data', OrderedDict([('string', 'str'), ('dict', OrderedDict([('string', 'str'), ('dict', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')])), ('*dict2', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]))]))]), - OrderedDict([('type', 'UserDefNested'), ('data', OrderedDict([('string0', 'str'), ('dict1', OrderedDict([('string1', 'str'), ('dict2', OrderedDict([('userdef1', 'UserDefOne'), ('string2', 'str')])), ('*dict3', OrderedDict([('userdef2', 'UserDefOne'), ('string3', 'str')]))]))]))]), + OrderedDict([('type', 'UserDefTwo'), ('data', OrderedDict([('string0', 'str'), ('dict1', OrderedDict([('string1', 'str'), ('dict2', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')])), ('*dict3', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]))]))]), OrderedDict([('type', 'UserDefA'), ('data', OrderedDict([('boolean', 'bool')]))]), OrderedDict([('type', 'UserDefB'), ('data', OrderedDict([('integer', 'int')]))]), OrderedDict([('union', 'UserDefUnion'), ('base', 'UserDefZero'), ('data', OrderedDict([('a', 'UserDefA'), ('b', 'UserDefB')]))]),
@@ -28,8 +27,7 @@ [OrderedDict([('type', 'NestedEnumsOne'), ('data', OrderedDict([('enum1', 'EnumOne'), ('*enum2', 'EnumOne'), ('enum3', 'EnumOne'), ('*enum4', 'EnumOne')]))]), OrderedDict([('type', 'UserDefZero'), ('data', OrderedDict([('integer', 'int')]))]), OrderedDict([('type', 'UserDefOne'), ('base', 'UserDefZero'), ('data', OrderedDict([('string', 'str'), ('*enum1', 'EnumOne')]))]), - OrderedDict([('type', 'UserDefTwo'), ('data', OrderedDict([('string', 'str'), ('dict', OrderedDict([('string', 'str'), ('dict', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')])), ('*dict2', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]))]))]), - OrderedDict([('type', 'UserDefNested'), ('data', OrderedDict([('string0', 'str'), ('dict1', OrderedDict([('string1', 'str'), ('dict2', OrderedDict([('userdef1', 'UserDefOne'), ('string2', 'str')])), ('*dict3', OrderedDict([('userdef2', 'UserDefOne'), ('string3', 'str')]))]))]))]), + OrderedDict([('type', 'UserDefTwo'), ('data', OrderedDict([('string0', 'str'), ('dict1', OrderedDict([('string1', 'str'), ('dict2', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')])), ('*dict3', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]))]))]), OrderedDict([('type', 'UserDefA'), ('data', OrderedDict([('boolean', 'bool')]))]), OrderedDict([('type', 'UserDefB'), ('data', OrderedDict([('integer', 'int')]))]), OrderedDict([('type', 'UserDefUnionBase'), ('data', OrderedDict([('string', 'str'), ('enum1', 'EnumOne')]))]),
tests/test-qmp-commands.c +16 -16
@@ -32,13 +32,13 @@ UserDefTwo *qmp_user_def_cmd2(UserDefOne *ud1a, ud1d->base->integer = has_udb1 ? ud1b->base->integer :0 ; ret =g_malloc0 (sizeof (UserDefTwo)); - ret->string =strdup ("blah1" ); - ret->dict.string =strdup ("blah2" ); - ret->dict.dict.userdef = ud1c; - ret->dict.dict.string =strdup ("blah3" ); - ret->dict.has_dict2 = true; - ret->dict.dict2.userdef = ud1d; - ret->dict.dict2.string =strdup ("blah4" ); + ret->string0 =strdup ("blah1" ); + ret->dict1.string1 =strdup ("blah2" ); + ret->dict1.dict2.userdef = ud1c; + ret->dict1.dict2.string =strdup ("blah3" ); + ret->dict1.has_dict3 = true; + ret->dict1.dict3.userdef = ud1d; + ret->dict1.dict3.string =strdup ("blah4" );return ret; }
@@ -120,15 +120,15 @@ static void test_dispatch_cmd_io(void) ret =qobject_to_qdict (test_qmp_dispatch (req)); -assert (!strcmp (qdict_get_str (ret,"string" ),"blah1" )); - ret_dict =qdict_get_qdict (ret,"dict" ); -assert (!strcmp (qdict_get_str (ret_dict,"string" ),"blah2" )); - ret_dict_dict =qdict_get_qdict (ret_dict,"dict" ); +assert (!strcmp (qdict_get_str (ret,"string0" ),"blah1" )); + ret_dict =qdict_get_qdict (ret,"dict1" ); +assert (!strcmp (qdict_get_str (ret_dict,"string1" ),"blah2" )); + ret_dict_dict =qdict_get_qdict (ret_dict,"dict2" ); ret_dict_dict_userdef =qdict_get_qdict (ret_dict_dict,"userdef" );assert (qdict_get_int (ret_dict_dict_userdef,"integer" ) ==42 );assert (!strcmp (qdict_get_str (ret_dict_dict_userdef,"string" ),"hello" ));assert (!strcmp (qdict_get_str (ret_dict_dict,"string" ),"blah3" )); - ret_dict_dict2 =qdict_get_qdict (ret_dict,"dict2" ); + ret_dict_dict2 =qdict_get_qdict (ret_dict,"dict3" ); ret_dict_dict2_userdef =qdict_get_qdict (ret_dict_dict2,"userdef" );assert (qdict_get_int (ret_dict_dict2_userdef,"integer" ) ==422 );assert (!strcmp (qdict_get_str (ret_dict_dict2_userdef,"string" ),"hello2" ));
@@ -192,7 +192,7 @@ static void test_dealloc_partial(void)QmpInputVisitor *qiv; ud2_dict =qdict_new (); -qdict_put_obj (ud2_dict,"string" ,QOBJECT (qstring_from_str (text))); +qdict_put_obj (ud2_dict,"string0" ,QOBJECT (qstring_from_str (text))); qiv =qmp_input_visitor_new (QOBJECT (ud2_dict));visit_type_UserDefTwo (qmp_input_get_visitor (qiv), &ud2,NULL , &err);
@@ -202,9 +202,9 @@ static void test_dealloc_partial(void)/* verify partial success */ assert (ud2 !=NULL ); -assert (ud2->string !=NULL ); -assert (strcmp (ud2->string, text) ==0 ); -assert (ud2->dict.dict.userdef ==NULL ); +assert (ud2->string0 !=NULL ); +assert (strcmp (ud2->string0, text) ==0 ); +assert (ud2->dict1.dict2.userdef ==NULL );/* confirm & release construction error */ assert (err !=NULL );
tests/test-qmp-input-strict.c +11 -8
@@ -1,7 +1,7 @@/* * QMP Input Visitor unit-tests (strict mode). * -* Copyright (C) 2011-2012 Red Hat Inc. +* Copyright (C) 2011-2012, 2014 Red Hat Inc. * * Authors: * Luiz Capitulino <[email protected]>
@@ -116,15 +116,18 @@ static void test_validate_struct(TestInputVisitorData *data,static void test_validate_struct_nested (TestInputVisitorData *data,const void *unused) { -UserDefNested *udp =NULL ; +UserDefTwo *udp =NULL ;Error *err =NULL ;Visitor *v; - v =validate_test_init (data,"{ 'string0': 'string0', 'dict1': { 'string1': 'string1', 'dict2': { 'userdef1': { 'integer': 42, 'string': 'string' }, 'string2': 'string2'}}}" ); + v =validate_test_init (data,"{ 'string0': 'string0', " +"'dict1': { 'string1': 'string1', " +"'dict2': { 'userdef': { 'integer': 42, " +"'string': 'string' }, 'string': 'string2'}}}" ); -visit_type_UserDefNested (v, &udp,NULL , &err); +visit_type_UserDefTwo (v, &udp,NULL , &err);g_assert (!err); -qapi_free_UserDefNested (udp); +qapi_free_UserDefTwo (udp); } static void test_validate_list(TestInputVisitorData *data,
@@ -207,15 +210,15 @@ static void test_validate_fail_struct(TestInputVisitorData *data,static void test_validate_fail_struct_nested (TestInputVisitorData *data,const void *unused) { -UserDefNested *udp =NULL ; +UserDefTwo *udp =NULL ;Error *err =NULL ;Visitor *v; v =validate_test_init (data,"{ 'string0': 'string0', 'dict1': { 'string1': 'string1', 'dict2': { 'userdef1': { 'integer': 42, 'string': 'string', 'extra': [42, 23, {'foo':'bar'}] }, 'string2': 'string2'}}}" ); -visit_type_UserDefNested (v, &udp,NULL , &err); +visit_type_UserDefTwo (v, &udp,NULL , &err);g_assert (err); -qapi_free_UserDefNested (udp); +qapi_free_UserDefTwo (udp); } static void test_validate_fail_list(TestInputVisitorData *data,
tests/test-qmp-input-visitor.c +11 -8
@@ -1,7 +1,7 @@/* * QMP Input Visitor unit-tests. * -* Copyright (C) 2011 Red Hat Inc. +* Copyright (C) 2011, 2014 Red Hat Inc. * * Authors: * Luiz Capitulino <[email protected]>
@@ -248,23 +248,26 @@ static void check_and_free_str(char *str, const char *cmp)static void test_visitor_in_struct_nested (TestInputVisitorData *data,const void *unused) { -UserDefNested *udp =NULL ; +UserDefTwo *udp =NULL ;Error *err =NULL ;Visitor *v; - v =visitor_input_test_init (data,"{ 'string0': 'string0', 'dict1': { 'string1': 'string1', 'dict2': { 'userdef1': { 'integer': 42, 'string': 'string' }, 'string2': 'string2'}}}" ); + v =visitor_input_test_init (data,"{ 'string0': 'string0', " +"'dict1': { 'string1': 'string1', " +"'dict2': { 'userdef': { 'integer': 42, " +"'string': 'string' }, 'string': 'string2'}}}" ); -visit_type_UserDefNested (v, &udp,NULL , &err); +visit_type_UserDefTwo (v, &udp,NULL , &err);g_assert (!err);check_and_free_str (udp->string0,"string0" );check_and_free_str (udp->dict1.string1,"string1" ); - g_assert_cmpint(udp->dict1.dict2.userdef1->base->integer, ==, 42); -check_and_free_str (udp->dict1.dict2.userdef1->string,"string" ); -check_and_free_str (udp->dict1.dict2.string2,"string2" ); + g_assert_cmpint(udp->dict1.dict2.userdef->base->integer, ==, 42); +check_and_free_str (udp->dict1.dict2.userdef->string,"string" ); +check_and_free_str (udp->dict1.dict2.string,"string2" );g_assert (udp->dict1.has_dict3 == false); -g_free (udp->dict1.dict2.userdef1); +g_free (udp->dict1.dict2.userdef);g_free (udp); }
tests/test-qmp-output-visitor.c +25 -25
106 lines not on this page · raw message
tests/test-visitor-serialization.c +36 -35
127 lines not on this page · raw message
Signature · 1 line
1.9.3
PATCH 4/7 qapi: drop tests for inline subtypes
In reply to Eric BlakeA future patch will be using a 'name':{dictionary} entry in the QAPI schema to specify a default value for an optional argument; but existing use of inline substructs conflicts with that goal. This patch fixes the testsuite to avoid nested subtypes, by breaking the nesting into explicit types.
* tests/qapi-schema/qapi-schema-test.json: Flatten UserDefTwo.
* tests/qapi-schema/qapi-schema-test.out: Update expected output.
* tests/test-qmp-output-visitor.c (test_visitor_out_struct_nested) (test_visitor_out_list_qapi_free): Update clients.
* tests/test-qmp-input-visitor.c (test_visitor_in_struct_nested):
Likewise.
* tests/test-qmp-commands.c (qmp_user_def_cmd2) (test_dealloc_partial): Likewise.
* tests/test-visitor-serialization.c (nested_struct_create) (nested_struct_compare): Likewise.
--- tests/qapi-schema/qapi-schema-test.json | 12 ++++++-- tests/qapi-schema/qapi-schema-test.out | 8 +++-- tests/test-qmp-commands.c | 17 ++++++----- tests/test-qmp-input-visitor.c | 14 +++++---- tests/test-qmp-output-visitor.c | 44 +++++++++++++++------------ tests/test-visitor-serialization.c | 53 ++++++++++++++++++--------------- 6 files changed, 87 insertions(+), 61 deletions(-)
tests/qapi-schema/qapi-schema-test.json +9 -3
@@ -14,11 +14,17 @@ 'base': 'UserDefZero', 'data': { 'string': 'str', '*enum1': 'EnumOne' } } +{ 'type': 'UserDefTwoDictDict', + 'data': { 'userdef': 'UserDefOne', 'string': 'str' } } + +{ 'type': 'UserDefTwoDict', + 'data': { 'string1': 'str', + 'dict2': 'UserDefTwoDictDict', + '*dict3': 'UserDefTwoDictDict' } } + { 'type': 'UserDefTwo', 'data': { 'string0': 'str', - 'dict1': { 'string1': 'str', - 'dict2': { 'userdef': 'UserDefOne', 'string': 'str' }, - '*dict3': { 'userdef': 'UserDefOne', 'string': 'str' } } } } + 'dict1': 'UserDefTwoDict' } } # for testing unions { 'type': 'UserDefA',
tests/qapi-schema/qapi-schema-test.out +6 -2
@@ -2,7 +2,9 @@ OrderedDict([('type', 'NestedEnumsOne'), ('data', OrderedDict([('enum1', 'EnumOne'), ('*enum2', 'EnumOne'), ('enum3', 'EnumOne'), ('*enum4', 'EnumOne')]))]), OrderedDict([('type', 'UserDefZero'), ('data', OrderedDict([('integer', 'int')]))]), OrderedDict([('type', 'UserDefOne'), ('base', 'UserDefZero'), ('data', OrderedDict([('string', 'str'), ('*enum1', 'EnumOne')]))]), - OrderedDict([('type', 'UserDefTwo'), ('data', OrderedDict([('string0', 'str'), ('dict1', OrderedDict([('string1', 'str'), ('dict2', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')])), ('*dict3', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]))]))]), + OrderedDict([('type', 'UserDefTwoDictDict'), ('data', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]), + OrderedDict([('type', 'UserDefTwoDict'), ('data', OrderedDict([('string1', 'str'), ('dict2', 'UserDefTwoDictDict'), ('*dict3', 'UserDefTwoDictDict')]))]), + OrderedDict([('type', 'UserDefTwo'), ('data', OrderedDict([('string0', 'str'), ('dict1', 'UserDefTwoDict')]))]), OrderedDict([('type', 'UserDefA'), ('data', OrderedDict([('boolean', 'bool')]))]), OrderedDict([('type', 'UserDefB'), ('data', OrderedDict([('integer', 'int')]))]), OrderedDict([('union', 'UserDefUnion'), ('base', 'UserDefZero'), ('data', OrderedDict([('a', 'UserDefA'), ('b', 'UserDefB')]))]),
@@ -27,7 +29,9 @@ [OrderedDict([('type', 'NestedEnumsOne'), ('data', OrderedDict([('enum1', 'EnumOne'), ('*enum2', 'EnumOne'), ('enum3', 'EnumOne'), ('*enum4', 'EnumOne')]))]), OrderedDict([('type', 'UserDefZero'), ('data', OrderedDict([('integer', 'int')]))]), OrderedDict([('type', 'UserDefOne'), ('base', 'UserDefZero'), ('data', OrderedDict([('string', 'str'), ('*enum1', 'EnumOne')]))]), - OrderedDict([('type', 'UserDefTwo'), ('data', OrderedDict([('string0', 'str'), ('dict1', OrderedDict([('string1', 'str'), ('dict2', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')])), ('*dict3', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]))]))]), + OrderedDict([('type', 'UserDefTwoDictDict'), ('data', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]), + OrderedDict([('type', 'UserDefTwoDict'), ('data', OrderedDict([('string1', 'str'), ('dict2', 'UserDefTwoDictDict'), ('*dict3', 'UserDefTwoDictDict')]))]), + OrderedDict([('type', 'UserDefTwo'), ('data', OrderedDict([('string0', 'str'), ('dict1', 'UserDefTwoDict')]))]), OrderedDict([('type', 'UserDefA'), ('data', OrderedDict([('boolean', 'bool')]))]), OrderedDict([('type', 'UserDefB'), ('data', OrderedDict([('integer', 'int')]))]), OrderedDict([('type', 'UserDefUnionBase'), ('data', OrderedDict([('string', 'str'), ('enum1', 'EnumOne')]))]),
tests/test-qmp-commands.c +10 -7
@@ -33,12 +33,15 @@ UserDefTwo *qmp_user_def_cmd2(UserDefOne *ud1a, ret =g_malloc0 (sizeof (UserDefTwo)); ret->string0 =strdup ("blah1" ); - ret->dict1.string1 =strdup ("blah2" ); - ret->dict1.dict2.userdef = ud1c; - ret->dict1.dict2.string =strdup ("blah3" ); - ret->dict1.has_dict3 = true; - ret->dict1.dict3.userdef = ud1d; - ret->dict1.dict3.string =strdup ("blah4" ); + ret->dict1 =g_malloc0 (sizeof (UserDefTwoDict)); + ret->dict1->string1 =strdup ("blah2" ); + ret->dict1->dict2 =g_malloc0 (sizeof (UserDefTwoDictDict)); + ret->dict1->dict2->userdef = ud1c; + ret->dict1->dict2->string =strdup ("blah3" ); + ret->dict1->dict3 =g_malloc0 (sizeof (UserDefTwoDictDict)); + ret->dict1->has_dict3 = true; + ret->dict1->dict3->userdef = ud1d; + ret->dict1->dict3->string =strdup ("blah4" );return ret; }
@@ -204,7 +207,7 @@ static void test_dealloc_partial(void)assert (ud2 !=NULL );assert (ud2->string0 !=NULL );assert (strcmp (ud2->string0, text) ==0 ); -assert (ud2->dict1.dict2.userdef ==NULL ); +assert (ud2->dict1 ==NULL );/* confirm & release construction error */ assert (err !=NULL );
tests/test-qmp-input-visitor.c +8 -6
@@ -261,13 +261,15 @@ static void test_visitor_in_struct_nested(TestInputVisitorData *data,g_assert (!err);check_and_free_str (udp->string0,"string0" ); -check_and_free_str (udp->dict1.string1,"string1" ); - g_assert_cmpint(udp->dict1.dict2.userdef->base->integer, ==, 42); -check_and_free_str (udp->dict1.dict2.userdef->string,"string" ); -check_and_free_str (udp->dict1.dict2.string,"string2" ); -g_assert (udp->dict1.has_dict3 == false); +check_and_free_str (udp->dict1->string1,"string1" ); + g_assert_cmpint(udp->dict1->dict2->userdef->base->integer, ==, 42); +check_and_free_str (udp->dict1->dict2->userdef->string,"string" ); +check_and_free_str (udp->dict1->dict2->string,"string2" ); +g_assert (udp->dict1->has_dict3 == false); -g_free (udp->dict1.dict2.userdef); +g_free (udp->dict1->dict2->userdef); +g_free (udp->dict1->dict2); +g_free (udp->dict1);g_free (udp); }
tests/test-qmp-output-visitor.c +25 -19
57 lines not on this page · raw message
tests/test-visitor-serialization.c +29 -24
65 lines not on this page · raw message
Signature · 1 line
1.9.3
PATCH 5/7 qapi: drop inline subtype in query-version
In reply to Eric BlakeA future patch will be using a 'name':{dictionary} entry in the QAPI schema to specify a default value for an optional argument; but existing use of inline substructs conflicts with that goal. This patch fixes one of only two commands relying on nested subtypes, by breaking the nesting into an explicit type.
Prefer the safer g_new0() while making the conversion.
* qapi/common.json (VersionInfo): Split inline data... (VersionTriple): ...into new type.
* qmp.c (qmp_query_version): Update caller.
* hmp.c (hmp_info_version): Likewise.
--- hmp.c | 2 +- qapi/common.json | 26 +++++++++++++++++++------- qmp.c | 9 +++++---- 3 files changed, 25 insertions(+), 12 deletions(-)
hmp.c +1 -1
@@ -55,7 +55,7 @@ void hmp_info_version(Monitor *mon, const QDict *qdict) info =qmp_query_version (NULL );monitor_printf (mon,"%" PRId64".%" PRId64".%" PRId64"%s\n" , - info->qemu.major, info->qemu.minor, info->qemu.micro, + info->qemu->major, info->qemu->minor, info->qemu->micro, info->package);qapi_free_VersionInfo (info);
qapi/common.json +19 -7
@@ -29,15 +29,28 @@ 'DeviceNotActive', 'DeviceNotFound', 'KVMMissingCap' ] } ## +# @VersionTriple +# +# A three-part version number. +# +# @qemu.major: The major version number. +# +# @qemu.minor: The minor version number. +# +# @qemu.micro: The micro version number. +# +# Since: 2.2 +## +{ 'type': 'VersionTriple', + 'data': {'major': 'int', 'minor': 'int', 'micro': 'int'} } + + +## # @VersionInfo: # # A description of QEMU's version. # -# @qemu.major: The major version of QEMU -# -# @qemu.minor: The minor version of QEMU -# -# @qemu.micro: The micro version of QEMU. By current convention, a micro +# @qemu: The version of QEMU. By current convention, a micro # version of 50 signifies a development branch. A micro version # greater than or equal to 90 signifies a release candidate for # the next minor version. A micro version of less than 50
@@ -51,8 +64,7 @@ # Since: 0.14.0 ## { 'type': 'VersionInfo', - 'data': {'qemu': {'major': 'int', 'minor': 'int', 'micro': 'int'}, - 'package': 'str'} } + 'data': {'qemu': 'VersionTriple', 'package': 'str'} } ## # @query-version:
qmp.c +5 -4
@@ -45,15 +45,16 @@ NameInfo *qmp_query_name(Error **errp)VersionInfo *qmp_query_version (Error **errp) { -VersionInfo *info =g_malloc0 (sizeof (*info)); +VersionInfo *info =g_new0 (VersionInfo,1 );const char *version =QEMU_VERSION ;char *tmp; - info->qemu.major =strtol (version, &tmp,10 ); + info->qemu =g_new0 (VersionTriple,1 ); + info->qemu->major =strtol (version, &tmp,10 ); tmp++; - info->qemu.minor =strtol (tmp, &tmp,10 ); + info->qemu->minor =strtol (tmp, &tmp,10 ); tmp++; - info->qemu.micro =strtol (tmp, &tmp,10 ); + info->qemu->micro =strtol (tmp, &tmp,10 ); info->package =g_strdup (QEMU_PKGVERSION );return info;
Signature · 1 line
1.9.3
PATCH 6/7 qapi: drop inline subtype in query-pci
In reply to Eric BlakeA future patch will be using a 'name':{dictionary} entry in the QAPI schema to specify a default value for an optional argument; but existing use of inline substructs conflicts with that goal. This patch fixes one of only two commands relying on nested subtypes, by breaking the nesting into an explicit type.
Prefer the safer g_new0() while making the conversion, and reduce some long lines.
* qapi-schema.json (PciBridgeInfo, PciDeviceInfo): Split inline data...
(PciBusInfo, PciDeviceClass, PciDeviceId): ...into new types.
* hmp.c (hmp_info_pci_device): Update caller.
* hw/pci/pci.c (qmp_query_pci_bridge, qmp_query_pci_device):
Likewise.
--- hmp.c | 26 ++++++++-------- hw/pci/pci.c | 42 ++++++++++++++------------ qapi-schema.json | 90 ++++++++++++++++++++++++++++++++++++++------------------ 3 files changed, 98 insertions(+), 60 deletions(-)
hmp.c +13 -13
@@ -553,14 +553,14 @@ static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) dev->slot, dev->function);monitor_printf (mon," " ); -if (dev->class_info.has_desc) { -monitor_printf (mon,"%s" , dev->class_info.desc); +if (dev->class_info->has_desc) { +monitor_printf (mon,"%s" , dev->class_info->desc); }else { -monitor_printf (mon,"Class %04" PRId64, dev->class_info.q_class); +monitor_printf (mon,"Class %04" PRId64, dev->class_info->q_class); }monitor_printf (mon,": PCI device %04" PRIx64":%04" PRIx64"\n" , - dev->id.vendor, dev->id.device); + dev->id->vendor, dev->id->device);if (dev->has_irq) {monitor_printf (mon," IRQ %" PRId64".\n" , dev->irq);
@@ -568,25 +568,25 @@ static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)if (dev->has_pci_bridge) {monitor_printf (mon," BUS %" PRId64".\n" , - dev->pci_bridge->bus.number); + dev->pci_bridge->bus->number);monitor_printf (mon," secondary bus %" PRId64".\n" , - dev->pci_bridge->bus.secondary); + dev->pci_bridge->bus->secondary);monitor_printf (mon," subordinate bus %" PRId64".\n" , - dev->pci_bridge->bus.subordinate); + dev->pci_bridge->bus->subordinate);monitor_printf (mon," IO range [0x%04" PRIx64", 0x%04" PRIx64"]\n" , - dev->pci_bridge->bus.io_range->base, - dev->pci_bridge->bus.io_range->limit); + dev->pci_bridge->bus->io_range->base, + dev->pci_bridge->bus->io_range->limit);monitor_printf (mon," memory range [0x%08" PRIx64", 0x%08" PRIx64"]\n" , - dev->pci_bridge->bus.memory_range->base, - dev->pci_bridge->bus.memory_range->limit); + dev->pci_bridge->bus->memory_range->base, + dev->pci_bridge->bus->memory_range->limit);monitor_printf (mon," prefetchable memory range " "[0x%08" PRIx64", 0x%08" PRIx64"]\n" , - dev->pci_bridge->bus.prefetchable_range->base, - dev->pci_bridge->bus.prefetchable_range->limit); + dev->pci_bridge->bus->prefetchable_range->base, + dev->pci_bridge->bus->prefetchable_range->limit); }for (region = dev->regions; region; region = region->next) {
hw/pci/pci.c +23 -19
68 lines not on this page · raw message
qapi-schema.json +62 -28
119 lines not on this page · raw message
Signature · 1 line
1.9.3
PATCH 7/7 qapi: drop support for inline subtypes
In reply to Eric BlakeA future patch will be using a 'name':{dictionary} entry in the QAPI schema to specify a default value for an optional argument; but existing use of inline substructs conflicts with that goal. Now that all commands have been fixed to avoid inline substructs, nuke support for them.
* scripts/qapi.py (check_exprs): Enforce no nested dicts up front. (parse_args): Drop structured support.
(check_event): Drop; no longer needed.
* scripts/qapi-types.py (generate_struct_fields): Adjust caller.
* scripts/qapi-visit.py (generate_visit_struct_fields): Likewise.
* scripts/qapi-event.py (_generate_event_api_name) (generate_event_implement): Likewise.
* scripts/qapi-commands.py (generate_command_decl) (gen_sync_call, gen_visitor_input_vars_decl) (gen_visitor_input_block): Likewise.
* tests/qapi-schema/event-nest-struct.err: Update expected result.
* tests/qapi-schema/nested-struct.*: New files.
* tests/qapi-schema/nested-struct-returns.*: Likewise.
* tests/Makefile (check-qapi-schema-y): Run them.
--- scripts/qapi-commands.py | 8 +++--- scripts/qapi-event.py | 4 +-- scripts/qapi-types.py | 9 ++----- scripts/qapi-visit.py | 37 ++++----------------------- scripts/qapi.py | 38 ++++++++++++++++------------ tests/Makefile | 3 ++- tests/qapi-schema/event-nest-struct.err | 2 +- tests/qapi-schema/nested-struct-data.err | 1 + tests/qapi-schema/nested-struct-data.exit | 1 + tests/qapi-schema/nested-struct-data.json | 3 +++ tests/qapi-schema/nested-struct-data.out | 0 tests/qapi-schema/nested-struct-returns.err | 1 + tests/qapi-schema/nested-struct-returns.exit | 1 + tests/qapi-schema/nested-struct-returns.json | 2 ++ tests/qapi-schema/nested-struct-returns.out | 0 15 files changed, 47 insertions(+), 63 deletions(-) create mode 100644 tests/qapi-schema/nested-struct-data.err create mode 100644 tests/qapi-schema/nested-struct-data.exit create mode 100644 tests/qapi-schema/nested-struct-data.json create mode 100644 tests/qapi-schema/nested-struct-data.out create mode 100644 tests/qapi-schema/nested-struct-returns.err create mode 100644 tests/qapi-schema/nested-struct-returns.exit create mode 100644 tests/qapi-schema/nested-struct-returns.json create mode 100644 tests/qapi-schema/nested-struct-returns.out
scripts/qapi-commands.py +4 -4
@@ -28,7 +28,7 @@ def type_visitor(name): def generate_command_decl(name, args, ret_type): arglist="" - for argname, argtype, optional, structured in parse_args(args): + for argname, argtype, optional in parse_args(args): argtype = c_type(argtype, is_param=True) if optional: arglist += "bool has_%s, " % c_var(argname)
@@ -53,7 +53,7 @@ def gen_sync_call(name, args, ret_type, indent=0): retval="" if ret_type: retval = "retval = " - for argname, argtype, optional, structured in parse_args(args): + for argname, argtype, optional in parse_args(args): if optional: arglist += "has_%s, " % c_var(argname) arglist += "%s, " % (c_var(argname))
@@ -96,7 +96,7 @@ Visitor *v; def gen_visitor_input_vars_decl(args): ret = "" push_indent() - for argname, argtype, optional, structured in parse_args(args): + for argname, argtype, optional in parse_args(args): if optional: ret += mcgen(''' bool has_%(argname)s = false;
@@ -139,7 +139,7 @@ v = qapi_dealloc_get_visitor(md); v = qmp_input_get_visitor(mi); ''') - for argname, argtype, optional, structured in parse_args(args): + for argname, argtype, optional in parse_args(args): if optional: ret += mcgen(''' visit_optional(v, &has_%(c_name)s, "%(name)s", %(errp)s);
scripts/qapi-event.py +2 -2
@@ -21,7 +21,7 @@ def _generate_event_api_name(event_name, params): l = len(api_name) if params: - for argname, argentry, optional, structured in parse_args(params): + for argname, argentry, optional in parse_args(params): if optional: api_name += "bool has_%s,\n" % c_var(argname) api_name += "".ljust(l)
@@ -93,7 +93,7 @@ def generate_event_implement(api_name, event_name, params): """, event_name = event_name) - for argname, argentry, optional, structured in parse_args(params): + for argname, argentry, optional in parse_args(params): if optional: ret += mcgen(""" if (has_%(var)s) {
scripts/qapi-types.py +2 -7
@@ -63,18 +63,13 @@ typedef struct %(name)sList def generate_struct_fields(members): ret = '' - for argname, argentry, optional, structured in parse_args(members): + for argname, argentry, optional in parse_args(members): if optional: ret += mcgen(''' bool has_%(c_name)s; ''', c_name=c_var(argname)) - if structured: - push_indent() - ret += generate_struct({ "field": argname, "data": argentry}) - pop_indent() - else: - ret += mcgen(''' + ret += mcgen(''' %(c_type)s %(c_name)s; ''', c_type=c_type(argentry), c_name=c_var(argname))
scripts/qapi-visit.py +5 -32
@@ -51,27 +51,6 @@ def generate_visit_struct_fields(name, field_prefix, fn_prefix, members, base = else: full_name = "%s_%s" % (name, fn_prefix) - for argname, argentry, optional, structured in parse_args(members): - if structured: - if not fn_prefix: - nested_fn_prefix = argname - else: - nested_fn_prefix = "%s_%s" % (fn_prefix, argname) - - nested_field_prefix = "%s%s." % (field_prefix, argname) - ret += generate_visit_struct_fields(name, nested_field_prefix, - nested_fn_prefix, argentry) - ret += mcgen(''' - -static void visit_type_%(full_name)s_field_%(c_name)s(Visitor *m, %(name)s **obj, Error **errp) -{ -''', - name=name, full_name=full_name, c_name=c_var(argname)) - ret += generate_visit_struct_body(full_name, argname, argentry) - ret += mcgen(''' -} -''') - if base: ret += generate_visit_implicit_struct(base)
@@ -94,7 +73,7 @@ if (err) { c_prefix=c_var(field_prefix), type=type_name(base), c_name=c_var('base')) - for argname, argentry, optional, structured in parse_args(members): + for argname, argentry, optional in parse_args(members): if optional: ret += mcgen(''' visit_optional(m, &(*obj)->%(c_prefix)shas_%(c_name)s, "%(name)s", &err);
@@ -104,18 +83,12 @@ if (!err && (*obj)->%(prefix)shas_%(c_name)s) { c_name=c_var(argname), name=argname) push_indent() - if structured: - ret += mcgen(''' -visit_type_%(full_name)s_field_%(c_name)s(m, obj, &err); -''', - full_name=full_name, c_name=c_var(argname)) - else: - ret += mcgen(''' + ret += mcgen(''' visit_type_%(type)s(m, &(*obj)->%(c_prefix)s%(c_name)s, "%(name)s", &err); ''', - c_prefix=c_var(field_prefix), prefix=field_prefix, - type=type_name(argentry), c_name=c_var(argname), - name=argname) + c_prefix=c_var(field_prefix), prefix=field_prefix, + type=type_name(argentry), c_name=c_var(argname), + name=argname) if optional: pop_indent()
scripts/qapi.py +22 -16
@@ -248,16 +248,6 @@ def discriminator_find_enum_define(expr): return find_enum(discriminator_type) -def check_event(expr, expr_info): - params = expr.get('data') - if params: - for argname, argentry, optional, structured in parse_args(params): - if structured: - raise QAPIExprError(expr_info, - "Nested structure define in event is not " - "supported, event '%s', argname '%s'" - % (expr['event'], argname)) - def check_union(expr, expr_info): name = expr['union'] base = expr.get('base')
@@ -324,13 +314,30 @@ def check_exprs(schema): if expr.has_key('union'): check_union(expr, info) - if expr.has_key('event'): - check_event(expr, info) + # 'enum' must have 'data':[]; all other expressions have optional + # 'data'; if present it is either a typename or a dict if expr.has_key('enum'): if not isinstance(members, list): raise QAPIExprError(info, "enum '%s' requires an array for 'data'" % expr.get('enum')) + elif isinstance(members, OrderedDict): + for (key, value) in members.items(): + # Todo: allow dictionaries to represent default values of + # an optional argument. + if isinstance(value, OrderedDict): + raise QAPIExprError(info, + "Nested structure not supported for " + "member '%s'" % key) + # Nested structs also forbidden in command return type. + if expr.has_key('command'): + returns = expr.get('returns') + if isinstance(returns, OrderedDict): + for (key, value) in returns.items(): + if isinstance(value, OrderedDict): + raise QAPIExprError(info, + "Nested structure not supported for " + "member '%s'" % key) def parse_schema(input_file): try:
@@ -376,13 +383,12 @@ def parse_args(typeinfo): argname = member argentry = typeinfo[member] optional = False - structured = False if member.startswith('*'): argname = member[1:] optional = True - if isinstance(argentry, OrderedDict): - structured = True - yield (argname, argentry, optional, structured) + # Todo: allow argentry to be OrderedDict, for providing the + # value of an optional argument. + yield (argname, argentry, optional) def de_camel_case(name): new_name = ''
tests/Makefile +2 -1
@@ -193,7 +193,8 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \ comments.json empty.json enum-empty.json enum-missing-data.json \ enum-wrong-data.json funny-char.json indented-expr.json \ missing-colon.json missing-comma-list.json \ - missing-comma-object.json non-objects.json \ + missing-comma-object.json nested-struct-data.json \ + nested-struct-returns.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/event-nest-struct.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/event-nest-struct.json:1: Nested structure define in event is not supported, event 'EVENT_A', argname 'a' +tests/qapi-schema/event-nest-struct.json:1: Nested structure not supported for member 'a'
tests/qapi-schema/nested-struct-data.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/nested-struct-data.json:1: Nested structure not supported for member 'a'
tests/qapi-schema/nested-struct-data.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/nested-struct-data.json new file +3 -0
@@ -0,0 +1,3 @@ +{ 'command': 'foo', + 'data': { 'a' : { 'string' : 'str', 'integer': 'int' }, 'b' : 'str' }, + 'returns': {} }
tests/qapi-schema/nested-struct-data.out new file +0 -0
tests/qapi-schema/nested-struct-returns.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/nested-struct-returns.json:1: Nested structure not supported for member 'a'
tests/qapi-schema/nested-struct-returns.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/nested-struct-returns.json new file +2 -0
@@ -0,0 +1,2 @@ +{ 'command': 'foo', + 'returns': { 'a' : { 'string' : 'str', 'integer': 'int' }, 'b' : 'str' } }
tests/qapi-schema/nested-struct-returns.out new file +0 -0
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH 7/7] qapi: drop support for inline subtypes
tests/Makefile check-qapi-schema-y := $(addprefix tests/qapi-schema/, \ · line 197
Quoted 11 lines · Eric Blake
tests/Makefile +2
-1@@ -193,7 +193,8 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \ comments.json empty.json enum-empty.json enum-missing-data.json \ enum-wrong-data.json funny-char.json indented-expr.json \ missing-colon.json missing-comma-list.json \ - missing-comma-object.json non-objects.json \ + missing-comma-object.json nested-struct-data.json \ + nested-struct-returns.json non-objects.json \
Soft tab, please, to match the block's tab style. Fixing soft/hard tab for the whole file could happen in a separate patch, though.
Fam