drop qapi nested structs
PATCH v6 30/36 qapi: Use 'struct' instead of 'type' in schema
In reply to Eric BlakeReferring to "type" as both a meta-type (built-in, enum, union, alternte, or struct) and a specific type (the name that the schema uses for declaring structs) is confusing. Finish up the conversion to using "struct" in qapi schema by coverting all users, then remove the hack in the generator that allowed 'type'. Tweak a couple of tests whose output changes slightly due to longer lines. The json files were changed with:
for f in `find -name '*.json'; do sed -i "s/'type'/'struct'/"; done
followed by manually filtering out the places where we have a 'type' embedded in 'data'. I also verified that the generated files for QMP and QGA (such as qmp-commands.h) are the same before and after, as assurance that I didn't leave in any accidental member name changes.
---
v6: new patch
--- qapi-schema.json | 166 ++++++++++----------- qapi/block-core.json | 62 ++++---- qapi/block.json | 2 +- qapi/common.json | 4 +- qapi/trace.json | 2 +- qga/qapi-schema.json | 28 ++-- scripts/qapi.py | 14 -- tests/qapi-schema/alternate-array.json | 2 +- tests/qapi-schema/alternate-base.json | 2 +- tests/qapi-schema/alternate-conflict-dict.json | 4 +- tests/qapi-schema/alternate-good.json | 2 +- tests/qapi-schema/bad-base.json | 2 +- tests/qapi-schema/bad-ident.json | 2 +- tests/qapi-schema/bad-type-bool.json | 2 +- tests/qapi-schema/bad-type-int.err | 2 +- tests/qapi-schema/bad-type-int.json | 2 +- tests/qapi-schema/data-member-array.json | 2 +- tests/qapi-schema/double-data.err | 2 +- tests/qapi-schema/double-data.json | 2 +- tests/qapi-schema/double-type.json | 2 +- tests/qapi-schema/flat-union-bad-base.json | 4 +- .../qapi-schema/flat-union-bad-discriminator.json | 6 +- tests/qapi-schema/flat-union-base-star.json | 4 +- tests/qapi-schema/flat-union-base-union.json | 4 +- tests/qapi-schema/flat-union-branch-clash.json | 6 +- tests/qapi-schema/flat-union-inline.json | 2 +- tests/qapi-schema/flat-union-int-branch.json | 4 +- .../qapi-schema/flat-union-invalid-branch-key.json | 6 +- .../flat-union-invalid-discriminator.json | 6 +- tests/qapi-schema/flat-union-no-base.json | 4 +- .../flat-union-optional-discriminator.json | 4 +- tests/qapi-schema/flat-union-reverse-define.json | 6 +- .../flat-union-string-discriminator.json | 6 +- tests/qapi-schema/qapi-schema-test.json | 22 +-- tests/qapi-schema/redefined-builtin.json | 2 +- tests/qapi-schema/redefined-type.json | 2 +- tests/qapi-schema/union-bad-branch.json | 4 +- tests/qapi-schema/union-base-no-discriminator.json | 6 +- tests/qapi-schema/union-invalid-base.json | 4 +- tests/qapi-schema/unknown-expr-key.json | 2 +- 40 files changed, 198 insertions(+), 212 deletions(-)
qapi-schema.json +83 -83
@@ -71,7 +71,7 @@ # # Since 0.14.0 ## -{ 'type': 'NameInfo', 'data': {'*name': 'str'} } +{ 'struct': 'NameInfo', 'data': {'*name': 'str'} } ## # @query-name:
@@ -95,7 +95,7 @@ # # Since: 0.14.0 ## -{ 'type': 'KvmInfo', 'data': {'enabled': 'bool', 'present': 'bool'} } +{ 'struct': 'KvmInfo', 'data': {'enabled': 'bool', 'present': 'bool'} } ## # @query-kvm:
@@ -170,7 +170,7 @@ # # Notes: @singlestep is enabled through the GDB stub ## -{ 'type': 'StatusInfo', +{ 'struct': 'StatusInfo', 'data': {'running': 'bool', 'singlestep': 'bool', 'status': 'RunState'} } ##
@@ -195,7 +195,7 @@ # # Notes: If no UUID was specified for the guest, a null UUID is returned. ## -{ 'type': 'UuidInfo', 'data': {'UUID': 'str'} } +{ 'struct': 'UuidInfo', 'data': {'UUID': 'str'} } ## # @query-uuid:
@@ -226,7 +226,7 @@ # # Since: 0.14.0 ## -{ 'type': 'ChardevInfo', 'data': {'label': 'str', +{ 'struct': 'ChardevInfo', 'data': {'label': 'str', 'filename': 'str', 'frontend-open': 'bool'} }
@@ -250,7 +250,7 @@ # # Since: 2.0 ## -{ 'type': 'ChardevBackendInfo', 'data': {'name': 'str'} } +{ 'struct': 'ChardevBackendInfo', 'data': {'name': 'str'} } ## # @query-chardev-backends:
@@ -339,7 +339,7 @@ # # Since: 1.2.0 ## -{ 'type': 'EventInfo', 'data': {'name': 'str'} } +{ 'struct': 'EventInfo', 'data': {'name': 'str'} } ## # @query-events:
@@ -380,7 +380,7 @@ # # Since: 0.14.0 ## -{ 'type': 'MigrationStats', +{ 'struct': 'MigrationStats', 'data': {'transferred': 'int', 'remaining': 'int', 'total': 'int' , 'duplicate': 'int', 'skipped': 'int', 'normal': 'int', 'normal-bytes': 'int', 'dirty-pages-rate' : 'int',
@@ -405,7 +405,7 @@ # # Since: 1.2 ## -{ 'type': 'XBZRLECacheStats', +{ 'struct': 'XBZRLECacheStats', 'data': {'cache-size': 'int', 'bytes': 'int', 'pages': 'int', 'cache-miss': 'int', 'cache-miss-rate': 'number', 'overflow': 'int' } }
@@ -476,7 +476,7 @@ # # Since: 0.14.0 ## -{ 'type': 'MigrationInfo', +{ 'struct': 'MigrationInfo', 'data': {'*status': 'MigrationStatus', '*ram': 'MigrationStats', '*disk': 'MigrationStats', '*xbzrle-cache': 'XBZRLECacheStats',
@@ -534,7 +534,7 @@ # # Since: 1.2 ## -{ 'type': 'MigrationCapabilityStatus', +{ 'struct': 'MigrationCapabilityStatus', 'data': { 'capability' : 'MigrationCapability', 'state' : 'bool' } } ##
@@ -575,7 +575,7 @@ # # Since: 0.14.0 ## -{ 'type': 'MouseInfo', +{ 'struct': 'MouseInfo', 'data': {'name': 'str', 'index': 'int', 'current': 'bool', 'absolute': 'bool'} }
@@ -621,7 +621,7 @@ # Notes: @halted is a transient state that changes frequently. By the time the # data is sent to the client, the guest may no longer be halted. ## -{ 'type': 'CpuInfo', +{ 'struct': 'CpuInfo', 'data': {'CPU': 'int', 'current': 'bool', 'halted': 'bool', '*pc': 'int', '*nip': 'int', '*npc': 'int', '*PC': 'int', 'thread_id': 'int'} }
@@ -647,7 +647,7 @@ # # Since: 2.0 ## -{ 'type': 'IOThreadInfo', +{ 'struct': 'IOThreadInfo', 'data': {'id': 'str', 'thread-id': 'int'} } ##
@@ -700,7 +700,7 @@ # # Since: 2.1 ## -{ 'type': 'VncBasicInfo', +{ 'struct': 'VncBasicInfo', 'data': { 'host': 'str', 'service': 'str', 'family': 'NetworkAddressFamily',
@@ -715,7 +715,7 @@ # # Since: 2.1 ## -{ 'type': 'VncServerInfo', +{ 'struct': 'VncServerInfo', 'base': 'VncBasicInfo', 'data': { '*auth': 'str' } }
@@ -732,7 +732,7 @@ # # Since: 0.14.0 ## -{ 'type': 'VncClientInfo', +{ 'struct': 'VncClientInfo', 'base': 'VncBasicInfo', 'data': { '*x509_dname': 'str', '*sasl_username': 'str' } }
@@ -772,7 +772,7 @@ # # Since: 0.14.0 ## -{ 'type': 'VncInfo', +{ 'struct': 'VncInfo', 'data': {'enabled': 'bool', '*host': 'str', '*family': 'NetworkAddressFamily', '*service': 'str', '*auth': 'str', '*clients': ['VncClientInfo']} }
@@ -826,7 +826,7 @@ # # Since: 2.3 ## -{ 'type': 'VncInfo2', +{ 'struct': 'VncInfo2', 'data': { 'id' : 'str', 'server' : ['VncBasicInfo'], 'clients' : ['VncClientInfo'],
@@ -869,7 +869,7 @@ # # Since: 2.1 ## -{ 'type': 'SpiceBasicInfo', +{ 'struct': 'SpiceBasicInfo', 'data': { 'host': 'str', 'port': 'str', 'family': 'NetworkAddressFamily' } }
@@ -883,7 +883,7 @@ # # Since: 2.1 ## -{ 'type': 'SpiceServerInfo', +{ 'struct': 'SpiceServerInfo', 'base': 'SpiceBasicInfo', 'data': { '*auth': 'str' } }
@@ -907,7 +907,7 @@ # # Since: 0.14.0 ## -{ 'type': 'SpiceChannel', +{ 'struct': 'SpiceChannel', 'base': 'SpiceBasicInfo', 'data': {'connection-id': 'int', 'channel-type': 'int', 'channel-id': 'int', 'tls': 'bool'} }
@@ -965,7 +965,7 @@ # # Since: 0.14.0 ## -{ 'type': 'SpiceInfo', +{ 'struct': 'SpiceInfo', 'data': {'enabled': 'bool', 'migrated': 'bool', '*host': 'str', '*port': 'int', '*tls-port': 'int', '*auth': 'str', '*compiled-version': 'str', 'mouse-mode': 'SpiceQueryMouseMode', '*channels': ['SpiceChannel']} }
@@ -991,7 +991,7 @@ # Since: 0.14.0 # ## -{ 'type': 'BalloonInfo', 'data': {'actual': 'int' } } +{ 'struct': 'BalloonInfo', 'data': {'actual': 'int' } } ## # @query-balloon:
@@ -1018,7 +1018,7 @@ # # Since: 0.14.0 ## -{ 'type': 'PciMemoryRange', 'data': {'base': 'int', 'limit': 'int'} } +{ 'struct': 'PciMemoryRange', 'data': {'base': 'int', 'limit': 'int'} } ## # @PciMemoryRegion
@@ -1036,7 +1036,7 @@ # # Since: 0.14.0 ## -{ 'type': 'PciMemoryRegion', +{ 'struct': 'PciMemoryRegion', 'data': {'bar': 'int', 'type': 'str', 'address': 'int', 'size': 'int', '*prefetch': 'bool', '*mem_type_64': 'bool' } }
@@ -1065,7 +1065,7 @@ # # Since: 0.14.0 ## -{ 'type': 'PciBridgeInfo', +{ 'struct': 'PciBridgeInfo', 'data': {'bus': { 'number': 'int', 'secondary': 'int', 'subordinate': 'int', 'io_range': 'PciMemoryRange', 'memory_range': 'PciMemoryRange',
@@ -1104,7 +1104,7 @@ # # Since: 0.14.0 ## -{ 'type': 'PciDeviceInfo', +{ 'struct': 'PciDeviceInfo', 'data': {'bus': 'int', 'slot': 'int', 'function': 'int', 'class_info': {'*desc': 'str', 'class': 'int'}, 'id': {'device': 'int', 'vendor': 'int'},
@@ -1122,7 +1122,7 @@ # # Since: 0.14.0 ## -{ 'type': 'PciInfo', 'data': {'bus': 'int', 'devices': ['PciDeviceInfo']} } +{ 'struct': 'PciInfo', 'data': {'bus': 'int', 'devices': ['PciDeviceInfo']} } ## # @query-pci:
@@ -1341,7 +1341,7 @@ # # Since: 1.6 ### -{ 'type': 'Abort', +{ 'struct': 'Abort', 'data': { } } ##
@@ -1506,7 +1506,7 @@ # # Since: 1.2 ## -{ 'type': 'ObjectPropertyInfo', +{ 'struct': 'ObjectPropertyInfo', 'data': { 'name': 'str', 'type': 'str' } } ##
@@ -1691,7 +1691,7 @@ # # Notes: This command is experimental and may change syntax in future releases. ## -{ 'type': 'ObjectTypeInfo', +{ 'struct': 'ObjectTypeInfo', 'data': { 'name': 'str' } } ##
@@ -1723,7 +1723,7 @@ # # Since: 1.2 ## -{ 'type': 'DevicePropertyInfo', +{ 'struct': 'DevicePropertyInfo', 'data': { 'name': 'str', 'type': 'str', '*description': 'str' } } ##
@@ -1903,7 +1903,7 @@ # # Since: 2.0 ## -{ 'type': 'DumpGuestMemoryCapability', +{ 'struct': 'DumpGuestMemoryCapability', 'data': { 'formats': ['DumpGuestMemoryFormat'] } }
@@ -2000,7 +2000,7 @@ # # Since 1.2 ## -{ 'type': 'NetdevNoneOptions', +{ 'struct': 'NetdevNoneOptions', 'data': { } } ##
@@ -2020,7 +2020,7 @@ # # Since 1.2 ## -{ 'type': 'NetLegacyNicOptions', +{ 'struct': 'NetLegacyNicOptions', 'data': { '*netdev': 'str', '*macaddr': 'str',
@@ -2035,7 +2035,7 @@ # # Since 1.2 ## -{ 'type': 'String', +{ 'struct': 'String', 'data': { 'str': 'str' } }
@@ -2078,7 +2078,7 @@ # # Since 1.2 ## -{ 'type': 'NetdevUserOptions', +{ 'struct': 'NetdevUserOptions', 'data': { '*hostname': 'str', '*restrict': 'bool',
@@ -2130,7 +2130,7 @@ # # Since 1.2 ## -{ 'type': 'NetdevTapOptions', +{ 'struct': 'NetdevTapOptions', 'data': { '*ifname': 'str', '*fd': 'str',
@@ -2166,7 +2166,7 @@ # # Since 1.2 ## -{ 'type': 'NetdevSocketOptions', +{ 'struct': 'NetdevSocketOptions', 'data': { '*fd': 'str', '*listen': 'str',
@@ -2214,7 +2214,7 @@ # # Since 2.1 ## -{ 'type': 'NetdevL2TPv3Options', +{ 'struct': 'NetdevL2TPv3Options', 'data': { 'src': 'str', 'dst': 'str',
@@ -2246,7 +2246,7 @@ # # Since 1.2 ## -{ 'type': 'NetdevVdeOptions', +{ 'struct': 'NetdevVdeOptions', 'data': { '*sock': 'str', '*port': 'uint16',
@@ -2265,7 +2265,7 @@ # # Since 1.2 ## -{ 'type': 'NetdevDumpOptions', +{ 'struct': 'NetdevDumpOptions', 'data': { '*len': 'size', '*file': 'str' } }
@@ -2281,7 +2281,7 @@ # # Since 1.2 ## -{ 'type': 'NetdevBridgeOptions', +{ 'struct': 'NetdevBridgeOptions', 'data': { '*br': 'str', '*helper': 'str' } }
@@ -2295,7 +2295,7 @@ # # Since 1.2 ## -{ 'type': 'NetdevHubPortOptions', +{ 'struct': 'NetdevHubPortOptions', 'data': { 'hubid': 'int32' } }
@@ -2315,7 +2315,7 @@ # # Since 2.0 ## -{ 'type': 'NetdevNetmapOptions', +{ 'struct': 'NetdevNetmapOptions', 'data': { 'ifname': 'str', '*devname': 'str' } }
@@ -2331,7 +2331,7 @@ # # Since 2.1 ## -{ 'type': 'NetdevVhostUserOptions', +{ 'struct': 'NetdevVhostUserOptions', 'data': { 'chardev': 'str', '*vhostforce': 'bool' } }
@@ -2376,7 +2376,7 @@ # # Since 1.2 ## -{ 'type': 'NetLegacy', +{ 'struct': 'NetLegacy', 'data': { '*vlan': 'int32', '*id': 'str',
@@ -2394,7 +2394,7 @@ # # Since 1.2 ## -{ 'type': 'Netdev', +{ 'struct': 'Netdev', 'data': { 'id': 'str', 'opts': 'NetClientOptions' } }
@@ -2418,7 +2418,7 @@ # # Since 1.3 ## -{ 'type': 'InetSocketAddress', +{ 'struct': 'InetSocketAddress', 'data': { 'host': 'str', 'port': 'str',
@@ -2435,7 +2435,7 @@ # # Since 1.3 ## -{ 'type': 'UnixSocketAddress', +{ 'struct': 'UnixSocketAddress', 'data': { 'path': 'str' } }
@@ -2500,7 +2500,7 @@ # # Since: 1.2.0 ## -{ 'type': 'MachineInfo', +{ 'struct': 'MachineInfo', 'data': { 'name': 'str', '*alias': 'str', '*is-default': 'bool', 'cpu-max': 'int' } }
@@ -2524,7 +2524,7 @@ # # Since: 1.2.0 ## -{ 'type': 'CpuDefinitionInfo', +{ 'struct': 'CpuDefinitionInfo', 'data': { 'name': 'str' } } ##
@@ -2549,7 +2549,7 @@ # # Since: 1.2.0 ## -{ 'type': 'AddfdInfo', 'data': {'fdset-id': 'int', 'fd': 'int'} } +{ 'struct': 'AddfdInfo', 'data': {'fdset-id': 'int', 'fd': 'int'} } ## # @add-fd:
@@ -2605,7 +2605,7 @@ # # Since: 1.2.0 ## -{ 'type': 'FdsetFdInfo', +{ 'struct': 'FdsetFdInfo', 'data': {'fd': 'int', '*opaque': 'str'} } ##
@@ -2619,7 +2619,7 @@ # # Since: 1.2.0 ## -{ 'type': 'FdsetInfo', +{ 'struct': 'FdsetInfo', 'data': {'fdset-id': 'int', 'fds': ['FdsetFdInfo']} } ##
@@ -2645,7 +2645,7 @@ # # Since: 1.2.0 ## -{ 'type': 'TargetInfo', +{ 'struct': 'TargetInfo', 'data': { 'arch': 'str' } } ##
@@ -2745,7 +2745,7 @@ # # Since: 1.4 ## -{ 'type': 'ChardevFile', 'data': { '*in' : 'str', +{ 'struct': 'ChardevFile', 'data': { '*in' : 'str', 'out' : 'str' } } ##
@@ -2759,7 +2759,7 @@ # # Since: 1.4 ## -{ 'type': 'ChardevHostdev', 'data': { 'device' : 'str' } } +{ 'struct': 'ChardevHostdev', 'data': { 'device' : 'str' } } ## # @ChardevSocket:
@@ -2781,7 +2781,7 @@ # # Since: 1.4 ## -{ 'type': 'ChardevSocket', 'data': { 'addr' : 'SocketAddress', +{ 'struct': 'ChardevSocket', 'data': { 'addr' : 'SocketAddress', '*server' : 'bool', '*wait' : 'bool', '*nodelay' : 'bool',
@@ -2798,7 +2798,7 @@ # # Since: 1.5 ## -{ 'type': 'ChardevUdp', 'data': { 'remote' : 'SocketAddress', +{ 'struct': 'ChardevUdp', 'data': { 'remote' : 'SocketAddress', '*local' : 'SocketAddress' } } ##
@@ -2810,7 +2810,7 @@ # # Since: 1.5 ## -{ 'type': 'ChardevMux', 'data': { 'chardev' : 'str' } } +{ 'struct': 'ChardevMux', 'data': { 'chardev' : 'str' } } ## # @ChardevStdio:
@@ -2823,7 +2823,7 @@ # # Since: 1.5 ## -{ 'type': 'ChardevStdio', 'data': { '*signal' : 'bool' } } +{ 'struct': 'ChardevStdio', 'data': { '*signal' : 'bool' } } ## # @ChardevSpiceChannel:
@@ -2834,7 +2834,7 @@ # # Since: 1.5 ## -{ 'type': 'ChardevSpiceChannel', 'data': { 'type' : 'str' } } +{ 'struct': 'ChardevSpiceChannel', 'data': { 'type' : 'str' } } ## # @ChardevSpicePort:
@@ -2845,7 +2845,7 @@ # # Since: 1.5 ## -{ 'type': 'ChardevSpicePort', 'data': { 'fqdn' : 'str' } } +{ 'struct': 'ChardevSpicePort', 'data': { 'fqdn' : 'str' } } ## # @ChardevVC:
@@ -2859,7 +2859,7 @@ # # Since: 1.5 ## -{ 'type': 'ChardevVC', 'data': { '*width' : 'int', +{ 'struct': 'ChardevVC', 'data': { '*width' : 'int', '*height' : 'int', '*cols' : 'int', '*rows' : 'int' } }
@@ -2873,7 +2873,7 @@ # # Since: 1.5 ## -{ 'type': 'ChardevRingbuf', 'data': { '*size' : 'int' } } +{ 'struct': 'ChardevRingbuf', 'data': { '*size' : 'int' } } ## # @ChardevBackend:
@@ -2882,7 +2882,7 @@ # # Since: 1.4 (testdev since 2.2) ## -{ 'type': 'ChardevDummy', 'data': { } } +{ 'struct': 'ChardevDummy', 'data': { } } { 'union': 'ChardevBackend', 'data': { 'file' : 'ChardevFile', 'serial' : 'ChardevHostdev',
@@ -2915,7 +2915,7 @@ # # Since: 1.4 ## -{ 'type' : 'ChardevReturn', 'data': { '*pty' : 'str' } } +{ 'struct' : 'ChardevReturn', 'data': { '*pty' : 'str' } } ## # @chardev-add:
@@ -3002,7 +3002,7 @@ # # Since: 1.5 ## -{ 'type': 'TPMPassthroughOptions', 'data': { '*path' : 'str', +{ 'struct': 'TPMPassthroughOptions', 'data': { '*path' : 'str', '*cancel-path' : 'str'} } ##
@@ -3030,7 +3030,7 @@ # # Since: 1.5 ## -{ 'type': 'TPMInfo', +{ 'struct': 'TPMInfo', 'data': {'id': 'str', 'model': 'TpmModel', 'options': 'TpmTypeOptions' } }
@@ -3092,7 +3092,7 @@ # # Since 1.5 ## -{ 'type': 'AcpiTableOptions', +{ 'struct': 'AcpiTableOptions', 'data': { '*sig': 'str', '*rev': 'uint8',
@@ -3138,7 +3138,7 @@ # # Since 1.5 ## -{ 'type': 'CommandLineParameterInfo', +{ 'struct': 'CommandLineParameterInfo', 'data': { 'name': 'str', 'type': 'CommandLineParameterType', '*help': 'str',
@@ -3155,7 +3155,7 @@ # # Since 1.5 ## -{ 'type': 'CommandLineOptionInfo', +{ 'struct': 'CommandLineOptionInfo', 'data': { 'option': 'str', 'parameters': ['CommandLineParameterInfo'] } } ##
@@ -3199,7 +3199,7 @@ # # Since: 1.5 ## -{ 'type': 'X86CPUFeatureWordInfo', +{ 'struct': 'X86CPUFeatureWordInfo', 'data': { 'cpuid-input-eax': 'int', '*cpuid-input-ecx': 'int', 'cpuid-register': 'X86CPURegister32',
@@ -3252,7 +3252,7 @@ # Since 1.6 ## -{ 'type': 'RxFilterInfo', +{ 'struct': 'RxFilterInfo', 'data': { 'name': 'str', 'promiscuous': 'bool',
@@ -3314,7 +3314,7 @@ # # Since: 2.0 ## -{ 'type' : 'InputKeyEvent', +{ 'struct' : 'InputKeyEvent', 'data' : { 'key' : 'KeyValue', 'down' : 'bool' } }
@@ -3328,7 +3328,7 @@ # # Since: 2.0 ## -{ 'type' : 'InputBtnEvent', +{ 'struct' : 'InputBtnEvent', 'data' : { 'button' : 'InputButton', 'down' : 'bool' } }
@@ -3343,7 +3343,7 @@ # # Since: 2.0 ## -{ 'type' : 'InputMoveEvent', +{ 'struct' : 'InputMoveEvent', 'data' : { 'axis' : 'InputAxis', 'value' : 'int' } }
@@ -3426,7 +3426,7 @@ # # Since: 2.1 ## -{ 'type': 'NumaNodeOptions', +{ 'struct': 'NumaNodeOptions', 'data': { '*nodeid': 'uint16', '*cpus': ['uint16'],
@@ -3473,7 +3473,7 @@ # Since: 2.1 ## -{ 'type': 'Memdev', +{ 'struct': 'Memdev', 'data': { 'size': 'size', 'merge': 'bool',
@@ -3516,7 +3516,7 @@ # # Since: 2.1 ## -{ 'type': 'PCDIMMDeviceInfo', +{ 'struct': 'PCDIMMDeviceInfo', 'data': { '*id': 'str', 'addr': 'int', 'size': 'int',
@@ -3570,7 +3570,7 @@ # # Since: 2.1 ## -{ 'type': 'ACPIOSTInfo', +{ 'struct': 'ACPIOSTInfo', 'data' : { '*device': 'str', 'slot': 'str', 'slot-type': 'ACPISlotType',
qapi/block-core.json +31 -31
248 lines not on this page · raw message
qapi/block.json +1 -1
@@ -52,7 +52,7 @@ # # Since: 1.7 ## -{ 'type': 'BlockdevSnapshotInternal', +{ 'struct': 'BlockdevSnapshotInternal', 'data': { 'device': 'str', 'name': 'str' } } ##
qapi/common.json +2 -2
@@ -50,7 +50,7 @@ # # Since: 0.14.0 ## -{ 'type': 'VersionInfo', +{ 'struct': 'VersionInfo', 'data': {'qemu': {'major': 'int', 'minor': 'int', 'micro': 'int'}, 'package': 'str'} }
@@ -74,7 +74,7 @@ # # Since: 0.14.0 ## -{ 'type': 'CommandInfo', 'data': {'name': 'str'} } +{ 'struct': 'CommandInfo', 'data': {'name': 'str'} } ## # @query-commands:
qapi/trace.json +1 -1
@@ -32,7 +32,7 @@ # # Since 2.2 ## -{ 'type': 'TraceEventInfo', +{ 'struct': 'TraceEventInfo', 'data': {'name': 'str', 'state': 'TraceEventState'} } ##
qga/qapi-schema.json +14 -14
@@ -150,7 +150,7 @@ # # Since 1.1.0 ## -{ 'type': 'GuestAgentCommandInfo', +{ 'struct': 'GuestAgentCommandInfo', 'data': { 'name': 'str', 'enabled': 'bool', 'success-response': 'bool' } } ##
@@ -164,7 +164,7 @@ # # Since 0.15.0 ## -{ 'type': 'GuestAgentInfo', +{ 'struct': 'GuestAgentInfo', 'data': { 'version': 'str', 'supported_commands': ['GuestAgentCommandInfo'] } } ##
@@ -242,7 +242,7 @@ # # Since: 0.15.0 ## -{ 'type': 'GuestFileRead', +{ 'struct': 'GuestFileRead', 'data': { 'count': 'int', 'buf-b64': 'str', 'eof': 'bool' } } ##
@@ -274,7 +274,7 @@ # # Since: 0.15.0 ## -{ 'type': 'GuestFileWrite', +{ 'struct': 'GuestFileWrite', 'data': { 'count': 'int', 'eof': 'bool' } } ##
@@ -309,7 +309,7 @@ # # Since: 0.15.0 ## -{ 'type': 'GuestFileSeek', +{ 'struct': 'GuestFileSeek', 'data': { 'position': 'int', 'eof': 'bool' } } ##
@@ -556,7 +556,7 @@ # # Since: 1.1 ## -{ 'type': 'GuestIpAddress', +{ 'struct': 'GuestIpAddress', 'data': {'ip-address': 'str', 'ip-address-type': 'GuestIpAddressType', 'prefix': 'int'} }
@@ -572,7 +572,7 @@ # # Since: 1.1 ## -{ 'type': 'GuestNetworkInterface', +{ 'struct': 'GuestNetworkInterface', 'data': {'name': 'str', '*hardware-address': 'str', '*ip-addresses': ['GuestIpAddress'] } }
@@ -604,7 +604,7 @@ # # Since: 1.5 ## -{ 'type': 'GuestLogicalProcessor', +{ 'struct': 'GuestLogicalProcessor', 'data': {'logical-id': 'int', 'online': 'bool', '*can-offline': 'bool'} }
@@ -694,7 +694,7 @@ # # Since: 2.2 ## -{ 'type': 'GuestPCIAddress', +{ 'struct': 'GuestPCIAddress', 'data': {'domain': 'int', 'bus': 'int', 'slot': 'int', 'function': 'int'} }
@@ -709,7 +709,7 @@ # # Since: 2.2 ## -{ 'type': 'GuestDiskAddress', +{ 'struct': 'GuestDiskAddress', 'data': {'pci-controller': 'GuestPCIAddress', 'bus-type': 'GuestDiskBusType', 'bus': 'int', 'target': 'int', 'unit': 'int'} }
@@ -725,7 +725,7 @@ # # Since: 2.2 ## -{ 'type': 'GuestFilesystemInfo', +{ 'struct': 'GuestFilesystemInfo', 'data': {'name': 'str', 'mountpoint': 'str', 'type': 'str', 'disk': ['GuestDiskAddress']} }
@@ -782,7 +782,7 @@ # # Since: 2.3 ## -{ 'type': 'GuestMemoryBlock', +{ 'struct': 'GuestMemoryBlock', 'data': {'phys-index': 'uint64', 'online': 'bool', '*can-offline': 'bool'} }
@@ -835,7 +835,7 @@ # # Since: 2.3 ## -{ 'type': 'GuestMemoryBlockResponse', +{ 'struct': 'GuestMemoryBlockResponse', 'data': { 'phys-index': 'uint64', 'response': 'GuestMemoryBlockResponseType', '*error-code': 'int' }}
@@ -876,7 +876,7 @@ # # Since: 2.3 ## -{ 'type': 'GuestMemoryBlockInfo', +{ 'struct': 'GuestMemoryBlockInfo', 'data': {'size': 'uint64'} } ##
scripts/qapi.py +0 -14
@@ -617,20 +617,6 @@ def parse_schema(input_file): for expr_elem in schema.exprs: expr = expr_elem['expr'] info = expr_elem['info'] - - # back-compat hack until all schemas have been converted; - # preserve the ordering of the original expression - if expr.has_key('type'): - seen_type = False - for (key, value) in expr.items(): - if key == 'type': - seen_type = True - del expr['type'] - expr['struct'] = value - elif seen_type: - del expr[key] - expr[key] = value - if expr.has_key('enum'): check_keys(expr_elem, 'enum', ['data']) add_enum(expr['enum'], info, expr['data'])
tests/qapi-schema/alternate-array.json +1 -1
@@ -1,6 +1,6 @@ # we do not support array branches of alternates yet # TODO: should we support this? -{ 'type': 'One', +{ 'struct': 'One', 'data': { 'name': 'str' } } { 'alternate': 'Alt', 'data': { 'one': 'One',
tests/qapi-schema/alternate-base.json +1 -1
@@ -1,5 +1,5 @@ # we reject alternate with base type -{ 'type': 'Base', +{ 'struct': 'Base', 'data': { 'string': 'str' } } { 'alternate': 'Alt', 'base': 'Base',
tests/qapi-schema/alternate-conflict-dict.json +2 -2
@@ -1,7 +1,7 @@ # we reject alternates with multiple object branches -{ 'type': 'One', +{ 'struct': 'One', 'data': { 'name': 'str' } } -{ 'type': 'Two', +{ 'struct': 'Two', 'data': { 'value': 'int' } } { 'alternate': 'Alt', 'data': { 'one': 'One',
tests/qapi-schema/alternate-good.json +1 -1
@@ -1,5 +1,5 @@ # Working example of alternate -{ 'type': 'Data', +{ 'struct': 'Data', 'data': { '*number': 'int', '*name': 'str' } } { 'enum': 'Enum', 'data': [ 'hello', 'world' ] }
tests/qapi-schema/bad-base.json +1 -1
@@ -1,3 +1,3 @@ # we reject a base that is not a struct { 'union': 'Union', 'data': { 'a': 'int', 'b': 'str' } } -{ 'type': 'MyType', 'base': 'Union', 'data': { 'c': 'int' } } +{ 'struct': 'MyType', 'base': 'Union', 'data': { 'c': 'int' } }
tests/qapi-schema/bad-ident.json +1 -1
@@ -1,2 +1,2 @@ # we reject creating a type name with bad name -{ 'type': '*oops', 'data': { 'i': 'int' } } +{ 'struct': '*oops', 'data': { 'i': 'int' } }
tests/qapi-schema/bad-type-bool.json +1 -1
@@ -1,2 +1,2 @@ # we reject an expression with a metatype that is not a string -{ 'type': true, 'data': { } } +{ 'struct': true, 'data': { } }
tests/qapi-schema/bad-type-int.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/bad-type-int.json:3:11: Stray "1" +tests/qapi-schema/bad-type-int.json:3:13: Stray "1"
tests/qapi-schema/bad-type-int.json +1 -1
@@ -1,3 +1,3 @@ # we reject an expression with a metatype that is not a string # FIXME: once the parser understands integer inputs, improve the error message -{ 'type': 1, 'data': { } } +{ 'struct': 1, 'data': { } }
tests/qapi-schema/data-member-array.json +1 -1
@@ -1,4 +1,4 @@ # valid array members { 'enum': 'abc', 'data': [ 'a', 'b', 'c' ] } -{ 'type': 'def', 'data': { 'array': [ 'abc' ] } } +{ 'struct': 'def', 'data': { 'array': [ 'abc' ] } } { 'command': 'okay', 'data': { 'member1': [ 'int' ], 'member2': [ 'def' ] } }
tests/qapi-schema/double-data.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/double-data.json:2:39: Duplicate key "data" +tests/qapi-schema/double-data.json:2:41: Duplicate key "data"
tests/qapi-schema/double-data.json +1 -1
@@ -1,2 +1,2 @@ # we reject an expression with duplicate top-level keys -{ 'type': 'bar', 'data': { }, 'data': { 'string': 'str'} } +{ 'struct': 'bar', 'data': { }, 'data': { 'string': 'str'} }
tests/qapi-schema/double-type.json +1 -1
@@ -1,2 +1,2 @@ # we reject an expression with ambiguous metatype -{ 'command': 'foo', 'type': 'bar', 'data': { } } +{ 'command': 'foo', 'struct': 'bar', 'data': { } }
tests/qapi-schema/flat-union-bad-base.json +2 -2
@@ -2,9 +2,9 @@ # TODO: should we allow an anonymous inline base type? { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } -{ 'type': 'TestTypeA', +{ 'struct': 'TestTypeA', 'data': { 'string': 'str' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } { 'union': 'TestUnion', 'base': { 'enum1': 'TestEnum', 'kind': 'str' },
tests/qapi-schema/flat-union-bad-discriminator.json +3 -3
@@ -2,11 +2,11 @@ # this tests the old syntax for anonymous unions before we added alternates { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } -{ 'type': 'TestBase', +{ 'struct': 'TestBase', 'data': { 'enum1': 'TestEnum', 'kind': 'str' } } -{ 'type': 'TestTypeA', +{ 'struct': 'TestTypeA', 'data': { 'string': 'str' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } { 'union': 'TestUnion', 'base': 'TestBase',
tests/qapi-schema/flat-union-base-star.json +2 -2
@@ -1,9 +1,9 @@ # we require the base to be an existing complex type { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } -{ 'type': 'TestTypeA', +{ 'struct': 'TestTypeA', 'data': { 'string': 'str' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } { 'union': 'TestUnion', 'base': '**',
tests/qapi-schema/flat-union-base-union.json +2 -2
@@ -1,9 +1,9 @@ # we require the base to be a struct { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } -{ 'type': 'TestTypeA', +{ 'struct': 'TestTypeA', 'data': { 'string': 'str' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } { 'union': 'UnionBase', 'data': { 'kind1': 'TestTypeA',
tests/qapi-schema/flat-union-branch-clash.json +3 -3
@@ -1,11 +1,11 @@ # FIXME: we should check for no duplicate keys between branches and base { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } -{ 'type': 'Base', +{ 'struct': 'Base', 'data': { 'enum1': 'TestEnum', 'name': 'str' } } -{ 'type': 'Branch1', +{ 'struct': 'Branch1', 'data': { 'name': 'str' } } -{ 'type': 'Branch2', +{ 'struct': 'Branch2', 'data': { 'value': 'int' } } { 'union': 'TestUnion', 'base': 'Base',
tests/qapi-schema/flat-union-inline.json +1 -1
@@ -2,7 +2,7 @@ # TODO: should we allow anonymous inline types? { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } -{ 'type': 'Base', +{ 'struct': 'Base', 'data': { 'enum1': 'TestEnum', 'kind': 'str' } } { 'union': 'TestUnion', 'base': { 'enum1': 'TestEnum', 'kind': 'str' },
tests/qapi-schema/flat-union-int-branch.json +2 -2
@@ -1,9 +1,9 @@ # we require flat union branches to be a complex type { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } -{ 'type': 'Base', +{ 'struct': 'Base', 'data': { 'enum1': 'TestEnum' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } { 'union': 'TestUnion', 'base': 'Base',
tests/qapi-schema/flat-union-invalid-branch-key.json +3 -3
@@ -1,13 +1,13 @@ { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } -{ 'type': 'TestBase', +{ 'struct': 'TestBase', 'data': { 'enum1': 'TestEnum' } } -{ 'type': 'TestTypeA', +{ 'struct': 'TestTypeA', 'data': { 'string': 'str' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } { 'union': 'TestUnion',
tests/qapi-schema/flat-union-invalid-discriminator.json +3 -3
@@ -1,13 +1,13 @@ { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } -{ 'type': 'TestBase', +{ 'struct': 'TestBase', 'data': { 'enum1': 'TestEnum' } } -{ 'type': 'TestTypeA', +{ 'struct': 'TestTypeA', 'data': { 'string': 'str' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } { 'union': 'TestUnion',
tests/qapi-schema/flat-union-no-base.json +2 -2
@@ -1,8 +1,8 @@ # flat unions require a base # TODO: simple unions should be able to use an enum discriminator -{ 'type': 'TestTypeA', +{ 'struct': 'TestTypeA', 'data': { 'string': 'str' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } { 'enum': 'Enum', 'data': [ 'value1', 'value2' ] }
tests/qapi-schema/flat-union-optional-discriminator.json +2 -2
@@ -1,8 +1,8 @@ # we require the discriminator to be non-optional { 'enum': 'Enum', 'data': [ 'one', 'two' ] } -{ 'type': 'Base', +{ 'struct': 'Base', 'data': { '*switch': 'Enum' } } -{ 'type': 'Branch', 'data': { 'name': 'str' } } +{ 'struct': 'Branch', 'data': { 'name': 'str' } } { 'union': 'MyUnion', 'base': 'Base', 'discriminator': '*switch',
tests/qapi-schema/flat-union-reverse-define.json +3 -3
@@ -4,14 +4,14 @@ 'data': { 'value1': 'TestTypeA', 'value2': 'TestTypeB' } } -{ 'type': 'TestBase', +{ 'struct': 'TestBase', 'data': { 'enum1': 'TestEnum' } } { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } -{ 'type': 'TestTypeA', +{ 'struct': 'TestTypeA', 'data': { 'string': 'str' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } }
tests/qapi-schema/flat-union-string-discriminator.json +3 -3
@@ -1,13 +1,13 @@ { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } -{ 'type': 'TestBase', +{ 'struct': 'TestBase', 'data': { 'enum1': 'TestEnum', 'kind': 'str' } } -{ 'type': 'TestTypeA', +{ 'struct': 'TestTypeA', 'data': { 'string': 'str' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } { 'union': 'TestUnion',
tests/qapi-schema/qapi-schema-test.json +11 -11
@@ -3,40 +3,40 @@ # for testing enums { 'enum': 'EnumOne', 'data': [ 'value1', 'value2', 'value3' ] } -{ 'type': 'NestedEnumsOne', +{ 'struct': 'NestedEnumsOne', 'data': { 'enum1': 'EnumOne', '*enum2': 'EnumOne', 'enum3': 'EnumOne', '*enum4': 'EnumOne' } } # for testing nested structs -{ 'type': 'UserDefZero', +{ 'struct': 'UserDefZero', 'data': { 'integer': 'int' } } -{ 'type': 'UserDefOne', +{ 'struct': 'UserDefOne', 'base': 'UserDefZero', 'data': { 'string': 'str', '*enum1': 'EnumOne' } } -{ 'type': 'UserDefTwo', +{ 'struct': 'UserDefTwo', 'data': { 'string': 'str', 'dict': { 'string': 'str', 'dict': { 'userdef': 'UserDefOne', 'string': 'str' }, '*dict2': { 'userdef': 'UserDefOne', 'string': 'str' } } } } -{ 'type': 'UserDefNested', +{ 'struct': 'UserDefNested', 'data': { 'string0': 'str', 'dict1': { 'string1': 'str', 'dict2': { 'userdef1': 'UserDefOne', 'string2': 'str' }, '*dict3': { 'userdef2': 'UserDefOne', 'string3': 'str' } } } } # for testing unions -{ 'type': 'UserDefA', +{ 'struct': 'UserDefA', 'data': { 'boolean': 'bool' } } -{ 'type': 'UserDefB', +{ 'struct': 'UserDefB', 'data': { 'integer': 'int' } } -{ 'type': 'UserDefC', +{ 'struct': 'UserDefC', 'data': { 'string1': 'str', 'string2': 'str' } } -{ 'type': 'UserDefUnionBase', +{ 'struct': 'UserDefUnionBase', 'data': { 'string': 'str', 'enum1': 'EnumOne' } } { 'union': 'UserDefFlatUnion',
@@ -88,7 +88,7 @@ # # For simplicity, this example doesn't use [type=]discriminator nor optargs # specific to discriminator values. -{ 'type': 'UserDefOptions', +{ 'struct': 'UserDefOptions', 'data': { '*i64' : [ 'int' ], '*u64' : [ 'uint64' ],
@@ -97,7 +97,7 @@ '*u64x': 'uint64' } } # testing event -{ 'type': 'EventStructOne', +{ 'struct': 'EventStructOne', 'data': { 'struct1': 'UserDefOne', 'string': 'str', '*enum2': 'EnumOne' } } { 'event': 'EVENT_A' }
tests/qapi-schema/redefined-builtin.json +1 -1
@@ -1,2 +1,2 @@ # we reject types that duplicate builtin names -{ 'type': 'size', 'data': { 'myint': 'size' } } +{ 'struct': 'size', 'data': { 'myint': 'size' } }
tests/qapi-schema/redefined-type.json +1 -1
@@ -1,3 +1,3 @@ # we reject types defined more than once -{ 'type': 'foo', 'data': { 'one': 'str' } } +{ 'struct': 'foo', 'data': { 'one': 'str' } } { 'enum': 'foo', 'data': [ 'two' ] }
tests/qapi-schema/union-bad-branch.json +2 -2
@@ -1,7 +1,7 @@ # we reject normal unions where branches would collide in C -{ 'type': 'One', +{ 'struct': 'One', 'data': { 'string': 'str' } } -{ 'type': 'Two', +{ 'struct': 'Two', 'data': { 'number': 'int' } } { 'union': 'MyUnion', 'data': { 'one': 'One',
tests/qapi-schema/union-base-no-discriminator.json +3 -3
@@ -1,11 +1,11 @@ # we reject simple unions with a base (or flat unions without discriminator) -{ 'type': 'TestTypeA', +{ 'struct': 'TestTypeA', 'data': { 'string': 'str' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } -{ 'type': 'Base', +{ 'struct': 'Base', 'data': { 'string': 'str' } } { 'union': 'TestUnion',
tests/qapi-schema/union-invalid-base.json +2 -2
@@ -1,8 +1,8 @@ # a union base type must be a struct -{ 'type': 'TestTypeA', +{ 'struct': 'TestTypeA', 'data': { 'string': 'str' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } { 'union': 'TestUnion',
tests/qapi-schema/unknown-expr-key.json +1 -1
@@ -1,2 +1,2 @@ # we reject an expression with unknown top-level keys -{ 'type': 'bar', 'data': { 'string': 'str'}, 'bogus': { } } +{ 'struct': 'bar', 'data': { 'string': 'str'}, 'bogus': { } }
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v6 30/36] qapi: Use 'struct' instead of 'type' in schema
Quoted 8 lines · Eric Blake
Referring to "type" as both a meta-type (built-in, enum, union, alternte, or struct) and a specific type (the name that the schema uses for declaring structs) is confusing. Finish up the conversion to using "struct" in qapi schema by coverting all users, then remove the hack in the generator that allowed 'type'. Tweak a couple of tests whose output changes slightly due to longer lines. The json files were changed with:
Quoted 7 lines
for f in `find -name '*.json'; do sed -i "s/'type'/'struct'/"; done
followed by manually filtering out the places where we have a 'type' embedded in 'data'. I also verified that the generated files for QMP and QGA (such as
qmp-commands.h) are the same before and after, as assurance that I didn't leave in any accidental member name changes.
Sounds safe enough. Could miss comments, though. See possible misses inline.
Quoted 1 line
Signed-off-by Eric Blake <[email protected]>
[...]
tests/qapi-schema/flat-union-bad-base.json
Quoted 5 lines
tests/qapi-schema/flat-union-bad-base.json +0
-0@@ -2,9 +2,9 @@
# we require the base to be an existing complex type
Should this be 'an existing struct type'?
Quoted 35 lines
tests/qapi-schema/flat-union-bad-base.json +2
-2# TODO: should we allow an anonymous inline base type? { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } -{ 'type': 'TestTypeA', +{ 'struct': 'TestTypeA', 'data': { 'string': 'str' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } { 'union': 'TestUnion', 'base': { 'enum1': 'TestEnum', 'kind': 'str' },tests/qapi-schema/flat-union-bad-discriminator.json +3
-3@@ -2,11 +2,11 @@ # this tests the old syntax for anonymous unions before we added alternates { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } -{ 'type': 'TestBase', +{ 'struct': 'TestBase', 'data': { 'enum1': 'TestEnum', 'kind': 'str' } } -{ 'type': 'TestTypeA', +{ 'struct': 'TestTypeA', 'data': { 'string': 'str' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } { 'union': 'TestUnion', 'base': 'TestBase',tests/qapi-schema/flat-union-base-star.json +0
-0
tests/qapi-schema/flat-union-base-star.json line 1
Quoted 1 line
tests/qapi-schema/flat-union-base-star.json +0
-0@@ -1,9 +1,9 @@ # we require the base to be an existing complex type
Likewise.
tests/qapi-schema/flat-union-inline.json
Quoted 50 lines
tests/qapi-schema/flat-union-base-star.json +2
-2{ 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } -{ 'type': 'TestTypeA', +{ 'struct': 'TestTypeA', 'data': { 'string': 'str' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } { 'union': 'TestUnion', 'base': '**',tests/qapi-schema/flat-union-base-union.json +2
-2@@ -1,9 +1,9 @@ # we require the base to be a struct { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } -{ 'type': 'TestTypeA', +{ 'struct': 'TestTypeA', 'data': { 'string': 'str' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } { 'union': 'UnionBase', 'data': { 'kind1': 'TestTypeA',tests/qapi-schema/flat-union-branch-clash.json +3
-3@@ -1,11 +1,11 @@ # FIXME: we should check for no duplicate keys between branches and base { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } -{ 'type': 'Base', +{ 'struct': 'Base', 'data': { 'enum1': 'TestEnum', 'name': 'str' } } -{ 'type': 'Branch1', +{ 'struct': 'Branch1', 'data': { 'name': 'str' } } -{ 'type': 'Branch2', +{ 'struct': 'Branch2', 'data': { 'value': 'int' } } { 'union': 'TestUnion', 'base': 'Base',tests/qapi-schema/flat-union-inline.json +0
-0@@ -2,7 +2,7 @@
# we require branches to be a complex type name
Should this be 'a struct type name'?
Quoted 13 lines
tests/qapi-schema/flat-union-inline.json +1
-1# TODO: should we allow anonymous inline types? { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } -{ 'type': 'Base', +{ 'struct': 'Base', 'data': { 'enum1': 'TestEnum', 'kind': 'str' } } { 'union': 'TestUnion', 'base': { 'enum1': 'TestEnum', 'kind': 'str' },tests/qapi-schema/flat-union-int-branch.json +0
-0
tests/qapi-schema/flat-union-int-branch.json line 1
Quoted 1 line
tests/qapi-schema/flat-union-int-branch.json +0
-0@@ -1,9 +1,9 @@ # we require flat union branches to be a complex type
Likewise.
Quoted 267 lines
tests/qapi-schema/flat-union-int-branch.json +2
-2{ 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } -{ 'type': 'Base', +{ 'struct': 'Base', 'data': { 'enum1': 'TestEnum' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } { 'union': 'TestUnion', 'base': 'Base',tests/qapi-schema/flat-union-invalid-branch-key.json +3
-3@@ -1,13 +1,13 @@ { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } -{ 'type': 'TestBase', +{ 'struct': 'TestBase', 'data': { 'enum1': 'TestEnum' } } -{ 'type': 'TestTypeA', +{ 'struct': 'TestTypeA', 'data': { 'string': 'str' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } { 'union': 'TestUnion',tests/qapi-schema/flat-union-invalid-discriminator.json +3
-3@@ -1,13 +1,13 @@ { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } -{ 'type': 'TestBase', +{ 'struct': 'TestBase', 'data': { 'enum1': 'TestEnum' } } -{ 'type': 'TestTypeA', +{ 'struct': 'TestTypeA', 'data': { 'string': 'str' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } { 'union': 'TestUnion',tests/qapi-schema/flat-union-no-base.json +2
-2@@ -1,8 +1,8 @@ # flat unions require a base # TODO: simple unions should be able to use an enum discriminator -{ 'type': 'TestTypeA', +{ 'struct': 'TestTypeA', 'data': { 'string': 'str' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } { 'enum': 'Enum', 'data': [ 'value1', 'value2' ] }tests/qapi-schema/flat-union-optional-discriminator.json +2
-2@@ -1,8 +1,8 @@ # we require the discriminator to be non-optional { 'enum': 'Enum', 'data': [ 'one', 'two' ] } -{ 'type': 'Base', +{ 'struct': 'Base', 'data': { '*switch': 'Enum' } } -{ 'type': 'Branch', 'data': { 'name': 'str' } } +{ 'struct': 'Branch', 'data': { 'name': 'str' } } { 'union': 'MyUnion', 'base': 'Base', 'discriminator': '*switch',tests/qapi-schema/flat-union-reverse-define.json +3
-3@@ -4,14 +4,14 @@ 'data': { 'value1': 'TestTypeA', 'value2': 'TestTypeB' } } -{ 'type': 'TestBase', +{ 'struct': 'TestBase', 'data': { 'enum1': 'TestEnum' } } { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } -{ 'type': 'TestTypeA', +{ 'struct': 'TestTypeA', 'data': { 'string': 'str' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } }tests/qapi-schema/flat-union-string-discriminator.json +3
-3@@ -1,13 +1,13 @@ { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } -{ 'type': 'TestBase', +{ 'struct': 'TestBase', 'data': { 'enum1': 'TestEnum', 'kind': 'str' } } -{ 'type': 'TestTypeA', +{ 'struct': 'TestTypeA', 'data': { 'string': 'str' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } { 'union': 'TestUnion',tests/qapi-schema/qapi-schema-test.json +11
-11@@ -3,40 +3,40 @@ # for testing enums { 'enum': 'EnumOne', 'data': [ 'value1', 'value2', 'value3' ] } -{ 'type': 'NestedEnumsOne', +{ 'struct': 'NestedEnumsOne', 'data': { 'enum1': 'EnumOne', '*enum2': 'EnumOne', 'enum3': 'EnumOne', '*enum4': 'EnumOne' } } # for testing nested structs -{ 'type': 'UserDefZero', +{ 'struct': 'UserDefZero', 'data': { 'integer': 'int' } } -{ 'type': 'UserDefOne', +{ 'struct': 'UserDefOne', 'base': 'UserDefZero', 'data': { 'string': 'str', '*enum1': 'EnumOne' } } -{ 'type': 'UserDefTwo', +{ 'struct': 'UserDefTwo', 'data': { 'string': 'str', 'dict': { 'string': 'str', 'dict': { 'userdef': 'UserDefOne', 'string': 'str' }, '*dict2': { 'userdef': 'UserDefOne', 'string': 'str' } } } } -{ 'type': 'UserDefNested', +{ 'struct': 'UserDefNested', 'data': { 'string0': 'str', 'dict1': { 'string1': 'str', 'dict2': { 'userdef1': 'UserDefOne', 'string2': 'str' }, '*dict3': { 'userdef2': 'UserDefOne', 'string3': 'str' } } } } # for testing unions -{ 'type': 'UserDefA', +{ 'struct': 'UserDefA', 'data': { 'boolean': 'bool' } } -{ 'type': 'UserDefB', +{ 'struct': 'UserDefB', 'data': { 'integer': 'int' } } -{ 'type': 'UserDefC', +{ 'struct': 'UserDefC', 'data': { 'string1': 'str', 'string2': 'str' } } -{ 'type': 'UserDefUnionBase', +{ 'struct': 'UserDefUnionBase', 'data': { 'string': 'str', 'enum1': 'EnumOne' } } { 'union': 'UserDefFlatUnion',@@ -88,7 +88,7 @@ # # For simplicity, this example doesn't use [type=]discriminator nor optargs # specific to discriminator values. -{ 'type': 'UserDefOptions', +{ 'struct': 'UserDefOptions', 'data': { '*i64' : [ 'int' ], '*u64' : [ 'uint64' ],@@ -97,7 +97,7 @@ '*u64x': 'uint64' } } # testing event -{ 'type': 'EventStructOne', +{ 'struct': 'EventStructOne', 'data': { 'struct1': 'UserDefOne', 'string': 'str', '*enum2': 'EnumOne' } } { 'event': 'EVENT_A' }tests/qapi-schema/redefined-builtin.json +1
-1@@ -1,2 +1,2 @@ # we reject types that duplicate builtin names -{ 'type': 'size', 'data': { 'myint': 'size' } } +{ 'struct': 'size', 'data': { 'myint': 'size' } }tests/qapi-schema/redefined-type.json +1
-1@@ -1,3 +1,3 @@ # we reject types defined more than once -{ 'type': 'foo', 'data': { 'one': 'str' } } +{ 'struct': 'foo', 'data': { 'one': 'str' } } { 'enum': 'foo', 'data': [ 'two' ] }tests/qapi-schema/union-bad-branch.json +2
-2@@ -1,7 +1,7 @@ # we reject normal unions where branches would collide in C -{ 'type': 'One', +{ 'struct': 'One', 'data': { 'string': 'str' } } -{ 'type': 'Two', +{ 'struct': 'Two', 'data': { 'number': 'int' } } { 'union': 'MyUnion', 'data': { 'one': 'One',tests/qapi-schema/union-base-no-discriminator.json +3
-3@@ -1,11 +1,11 @@ # we reject simple unions with a base (or flat unions without discriminator) -{ 'type': 'TestTypeA', +{ 'struct': 'TestTypeA', 'data': { 'string': 'str' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } -{ 'type': 'Base', +{ 'struct': 'Base', 'data': { 'string': 'str' } } { 'union': 'TestUnion',tests/qapi-schema/union-invalid-base.json +2
-2@@ -1,8 +1,8 @@ # a union base type must be a struct -{ 'type': 'TestTypeA', +{ 'struct': 'TestTypeA', 'data': { 'string': 'str' } } -{ 'type': 'TestTypeB', +{ 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } { 'union': 'TestUnion',tests/qapi-schema/unknown-expr-key.json +0
-0
tests/qapi-schema/unknown-expr-key.json line 2
Quoted 3 lines
tests/qapi-schema/unknown-expr-key.json +1
-1@@ -1,2 +1,2 @@ # we reject an expression with unknown top-level keys -{ 'type': 'bar', 'data': { 'string': 'str'}, 'bogus': { } } +{ 'struct': 'bar', 'data': { 'string': 'str'}, 'bogus': { } }
PATCH v6 31/36 qapi: Merge UserDefTwo and UserDefNested in tests
In reply to Eric BlakeIn the testsuite, UserDefTwo and UserDefNested were identical structs 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 inline nested types in QAPI. When touching code related to allocations, convert g_malloc0(sizeof(Type)) to the more typesafe g_new0(Type, 1).
Ensure that 'make check-qapi-schema check-unit' still passes.
---
v6: rebase onto earlier changes; update commit message
--- tests/qapi-schema/qapi-schema-test.json | 10 +---- tests/qapi-schema/qapi-schema-test.out | 6 +-- tests/test-qmp-commands.c | 34 +++++++-------- tests/test-qmp-input-strict.c | 17 ++++---- tests/test-qmp-input-visitor.c | 17 ++++---- tests/test-qmp-output-visitor.c | 48 +++++++++++----------- tests/test-visitor-serialization.c | 73 +++++++++++++++++---------------- 7 files changed, 102 insertions(+), 103 deletions(-)
tests/qapi-schema/qapi-schema-test.json +2 -8
@@ -15,16 +15,10 @@ 'data': { 'string': 'str', '*enum1': 'EnumOne' } } { 'struct': 'UserDefTwo', - 'data': { 'string': 'str', - 'dict': { 'string': 'str', - 'dict': { 'userdef': 'UserDefOne', 'string': 'str' }, - '*dict2': { 'userdef': 'UserDefOne', 'string': 'str' } } } } - -{ 'struct': '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 { 'struct': 'UserDefA',
tests/qapi-schema/qapi-schema-test.out +2 -4
@@ -2,8 +2,7 @@ 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', 'UserDefTwo'), ('data', OrderedDict([('string', 'str'), ('dict', OrderedDict([('string', 'str'), ('dict', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')])), ('*dict2', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]))]))]), - OrderedDict([('struct', 'UserDefNested'), ('data', OrderedDict([('string0', 'str'), ('dict1', OrderedDict([('string1', 'str'), ('dict2', OrderedDict([('userdef1', 'UserDefOne'), ('string2', 'str')])), ('*dict3', OrderedDict([('userdef2', 'UserDefOne'), ('string3', 'str')]))]))]))]), + OrderedDict([('struct', 'UserDefTwo'), ('data', OrderedDict([('string0', 'str'), ('dict1', OrderedDict([('string1', 'str'), ('dict2', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')])), ('*dict3', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]))]))]), OrderedDict([('struct', 'UserDefA'), ('data', OrderedDict([('boolean', 'bool')]))]), OrderedDict([('struct', 'UserDefB'), ('data', OrderedDict([('integer', 'int')]))]), OrderedDict([('struct', 'UserDefC'), ('data', OrderedDict([('string1', 'str'), ('string2', 'str')]))]),
@@ -28,8 +27,7 @@ [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', 'UserDefTwo'), ('data', OrderedDict([('string', 'str'), ('dict', OrderedDict([('string', 'str'), ('dict', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')])), ('*dict2', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]))]))]), - OrderedDict([('struct', 'UserDefNested'), ('data', OrderedDict([('string0', 'str'), ('dict1', OrderedDict([('string1', 'str'), ('dict2', OrderedDict([('userdef1', 'UserDefOne'), ('string2', 'str')])), ('*dict3', OrderedDict([('userdef2', 'UserDefOne'), ('string3', 'str')]))]))]))]), + OrderedDict([('struct', 'UserDefTwo'), ('data', OrderedDict([('string0', 'str'), ('dict1', OrderedDict([('string1', 'str'), ('dict2', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')])), ('*dict3', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]))]))]), OrderedDict([('struct', 'UserDefA'), ('data', OrderedDict([('boolean', 'bool')]))]), OrderedDict([('struct', 'UserDefB'), ('data', OrderedDict([('integer', 'int')]))]), OrderedDict([('struct', 'UserDefC'), ('data', OrderedDict([('string1', 'str'), ('string2', 'str')]))]),
tests/test-qmp-commands.c +17 -17
@@ -31,14 +31,14 @@ UserDefTwo *qmp_user_def_cmd2(UserDefOne *ud1a, ud1d->base =g_new0 (UserDefZero,1 ); 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 =g_new0 (UserDefTwo,1 ); + 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 +10 -7
@@ -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 +10 -7
@@ -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 +24 -24
98 lines not on this page · raw message
tests/test-visitor-serialization.c +37 -36
133 lines not on this page · raw message
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v6 31/36] qapi: Merge UserDefTwo and UserDefNested in tests
Quoted 11 lines · Eric Blake
In the testsuite, UserDefTwo and UserDefNested were identical structs 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 inline nested types in QAPI. When touching code related to allocations, convert g_malloc0(sizeof(Type)) to the more typesafe
g_new0(Type, 1).Ensure that 'make check-qapi-schema check-unit' still passes.
Signed-off-by Eric Blake <[email protected]>
PATCH v6 32/36 qapi: Drop tests for inline nested structs
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 nested structs conflicts with that goal.
More precisely, a definition in the QAPI schema associates a name with a set of properties:
Example 1: { 'struct': 'Foo', 'data': { MEMBERS... } } associates the global name 'Foo' with properties (meta-type struct) and MEMBERS...
Example 2: 'mumble': TYPE
within MEMBERS... above associates 'mumble' with properties (type TYPE) and (optional false) within type Foo
The syntax of example 1 is extensible; if we need another property, we add another name/value pair to the dictionary (such as 'base':TYPE). The syntax of example 2 is not extensible, because the right hand side can only be a type.
We have used name encoding to add a property: "'*mumble': 'int'" associates 'mumble' with (type int) and (optional true). Nice, but doesn't scale. So the solution is to change our existing uses to be syntactic sugar to an extensible form:
NAME: TYPE --> NAME: { 'type': TYPE, 'optional': false }
*ONAME: TYPE --> ONAME: { 'type': TYPE, 'optional': true }
This patch fixes the testsuite to avoid inline nested types, by breaking the nesting into explicit types; it means that the type is now boxed instead of unboxed in C code, but makes no difference on the wire (and if desired, a later patch could change the generator to not do so much boxing in C). When touching code to add new allocations, also convert existing allocations to consistently prefer typesafe g_new0 over g_malloc0 when a type name is involved.
---
v6: rebase onto earlier changes, actually use g_new0; enhance commit message with Markus' great write-up
--- 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 | 55 ++++++++++++++++++--------------- 6 files changed, 88 insertions(+), 62 deletions(-)
tests/qapi-schema/qapi-schema-test.json +9 -3
@@ -14,11 +14,17 @@ 'base': 'UserDefZero', 'data': { 'string': 'str', '*enum1': 'EnumOne' } } +{ 'struct': 'UserDefTwoDictDict', + 'data': { 'userdef': 'UserDefOne', 'string': 'str' } } + +{ 'struct': 'UserDefTwoDict', + 'data': { 'string1': 'str', + 'dict2': 'UserDefTwoDictDict', + '*dict3': 'UserDefTwoDictDict' } } + { 'struct': 'UserDefTwo', 'data': { 'string0': 'str', - 'dict1': { 'string1': 'str', - 'dict2': { 'userdef': 'UserDefOne', 'string': 'str' }, - '*dict3': { 'userdef': 'UserDefOne', 'string': 'str' } } } } + 'dict1': 'UserDefTwoDict' } } # for testing unions { 'struct': 'UserDefA',
tests/qapi-schema/qapi-schema-test.out +6 -2
@@ -2,7 +2,9 @@ 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', 'UserDefTwo'), ('data', OrderedDict([('string0', 'str'), ('dict1', OrderedDict([('string1', 'str'), ('dict2', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')])), ('*dict3', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]))]))]), + 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')]))]),
@@ -27,7 +29,9 @@ [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', 'UserDefTwo'), ('data', OrderedDict([('string0', 'str'), ('dict1', OrderedDict([('string1', 'str'), ('dict2', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')])), ('*dict3', OrderedDict([('userdef', 'UserDefOne'), ('string', 'str')]))]))]))]), + 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')]))]),
tests/test-qmp-commands.c +10 -7
@@ -33,12 +33,15 @@ UserDefTwo *qmp_user_def_cmd2(UserDefOne *ud1a, ret =g_new0 (UserDefTwo,1 ); 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_new0 (UserDefTwoDict,1 ); + ret->dict1->string1 =strdup ("blah2" ); + ret->dict1->dict2 =g_new0 (UserDefTwoDictDict,1 ); + ret->dict1->dict2->userdef = ud1c; + ret->dict1->dict2->string =strdup ("blah3" ); + ret->dict1->dict3 =g_new0 (UserDefTwoDictDict,1 ); + 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 +30 -25
73 lines not on this page · raw message
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v6 32/36] qapi: Drop tests for inline nested structs
Quoted 39 lines · Eric Blake
A 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 nested structs conflicts with that goal.
More precisely, a definition in the QAPI schema associates a name with a set of properties:
Example 1: { 'struct': 'Foo', 'data': { MEMBERS... } } associates the global name 'Foo' with properties (meta-type struct) and MEMBERS...
Example 2: 'mumble': TYPE
within MEMBERS... above associates 'mumble' with properties (type TYPE) and (optional false) within type FooThe syntax of example 1 is extensible; if we need another property, we add another name/value pair to the dictionary (such as 'base':TYPE). The syntax of example 2 is not extensible, because the right hand side can only be a type.
We have used name encoding to add a property: "'*mumble': 'int'" associates 'mumble' with (type int) and (optional true). Nice, but doesn't scale. So the solution is to change our existing uses to be syntactic sugar to an extensible form:
NAME: TYPE --> NAME: { 'type': TYPE, 'optional': false } *ONAME: TYPE --> ONAME: { 'type': TYPE, 'optional': true }This patch fixes the testsuite to avoid inline nested types, by breaking the nesting into explicit types; it means that the type is now boxed instead of unboxed in C code, but makes no difference on the wire (and if desired, a later patch could change the generator to not do so much boxing in C). When touching code to add new allocations, also convert existing allocations to consistently prefer typesafe
g_new0overg_malloc0when a type name is involved.Signed-off-by Eric Blake <[email protected]>Reviewed-by Markus Armbruster <[email protected]>
[...]
tests/test-visitor-serialization.c line 4
Quoted 10 lines
tests/test-visitor-serialization.c +1
-1@@ -1,7 +1,7 @@/* * Unit-tests for visitor-based serialization * -* Copyright IBM, Corp. 2012 +* Copyright IBM, Corp. 2012, 2015
More accurate would be:
- * Copyright IBM, Corp. 2012,2013
+ * Copyright IBM, Corp. 2014, 2015
+ * Copyright (C) 2014, 2015 Red Hat Inc.
tests/test-visitor-serialization.c line 7
Quoted 3 lines
tests/test-visitor-serialization.c +0
-0* * Authors: * Michael Roth <[email protected]>
R-by stands all the same.
Re: [Qemu-devel] [PATCH v6 32/36] qapi: Drop tests for inline nested structs
Quoted 17 lines · Markus Armbruster
tests/test-visitor-serialization.c line 4
Quoted 12 lines · Eric Blake
A 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 nested structs conflicts with that goal.
+++
b/tests/test-visitor-serialization.ctests/test-visitor-serialization.c +1
-1@@ -1,7 +1,7 @@/* * Unit-tests for visitor-based serialization * -* Copyright IBM, Corp. 2012 +* Copyright IBM, Corp. 2012, 2015 More accurate would be:
Quoted 3 lines
- * Copyright IBM, Corp. 2012,2013
+ * Copyright IBM, Corp. 2014, 2015
+ * Copyright (C) 2014, 2015 Red Hat Inc.
Bummer - serves me right for trusting emacs' ability to auto-add copyright, without checking which line it added to.
Quoted 6 lines
tests/test-visitor-serialization.c line 7
Quoted 4 lines
tests/test-visitor-serialization.c +0
-0* * Authors: * Michael Roth <[email protected]> R-by stands all the same.
I'm adding this fix to a series followup, if there is no other reason to respin.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v6 33/36 qapi: Drop inline nested struct 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 (see previous commit message for more details why); but existing use of inline nested structs conflicts with that goal. This patch fixes one of only two commands relying on nested types, by breaking the nesting into an explicit type; it means that the type is now boxed instead of unboxed in C code, but the QMP wire format is unaffected by this change.
Prefer the safer g_new0() while making the conversion.
---
v6: rebase onto earlier changes
--- hmp.c | 2 +- qapi/common.json | 26 +++++++++++++++++++------- qmp.c | 9 +++++---- 3 files changed, 25 insertions(+), 12 deletions(-)
hmp.c +1 -1
@@ -60,7 +60,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.4 +## +{ 'struct': '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 ## { 'struct': '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
2.1.0
PATCH v6 34/36 qapi: Drop inline nested structs 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 (see previous commit message for more details why); but existing use of inline nested structs conflicts with that goal. This patch fixes one of only two commands relying on nested types, by breaking the nesting into an explicit type; it means that the type is now boxed instead of unboxed in C code, but the QMP wire format is unaffected by this change.
Prefer the safer g_new0() while making the conversion, and reduce some long lines.
---
v6: rebase onto earlier changes
--- hmp.c | 26 ++++++++-------- hw/pci/pci.c | 42 ++++++++++++++------------ qapi-schema.json | 90 ++++++++++++++++++++++++++++++++++++++------------------ 3 files changed, 98 insertions(+), 60 deletions(-)
hmp.c +13 -13
@@ -648,14 +648,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);
@@ -663,25 +663,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
2.1.0
PATCH v6 35/36 qapi: Drop support for inline nested types
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 (see previous commit messages for more details why); but existing use of inline nested structs conflicts with that goal. Now that all commands have been changed to avoid inline nested structs, nuke support for them, and turn it into a hard error. Update the testsuite to reflect tighter parsing rules.
---
v6: rebase onto earlier changes
--- scripts/qapi-commands.py | 8 +++--- scripts/qapi-event.py | 4 +-- scripts/qapi-types.py | 9 ++----- scripts/qapi-visit.py | 37 ++++------------------------ scripts/qapi.py | 20 ++++++--------- tests/qapi-schema/event-nest-struct.err | 2 +- tests/qapi-schema/nested-struct-data.err | 1 + tests/qapi-schema/nested-struct-data.exit | 2 +- tests/qapi-schema/nested-struct-data.json | 2 +- tests/qapi-schema/nested-struct-data.out | 3 --- tests/qapi-schema/nested-struct-returns.err | 1 + tests/qapi-schema/nested-struct-returns.exit | 2 +- tests/qapi-schema/nested-struct-returns.json | 2 +- tests/qapi-schema/nested-struct-returns.out | 3 --- 14 files changed, 27 insertions(+), 69 deletions(-)
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 +7 -13
@@ -373,10 +373,12 @@ def check_type(expr_info, source, value, allow_array = False, for (key, arg) in value.items(): check_name(expr_info, "Member of %s" % source, key, allow_optional=allow_optional) + # Todo: allow dictionaries to represent default values of + # an optional argument. check_type(expr_info, "Member '%s' of %s" % (key, source), arg, - allow_array=True, allow_dict=True, allow_optional=True, + allow_array=True, allow_star=allow_star, allow_metas=['built-in', 'union', 'alternate', 'struct', - 'enum'], allow_star=allow_star) + 'enum']) def check_command(expr, expr_info): name = expr['command']
@@ -404,13 +406,6 @@ def check_event(expr, expr_info): check_type(expr_info, "'data' for event '%s'" % name, expr.get('data'), allow_dict=True, allow_optional=True, allow_metas=['union', 'struct']) - 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']
@@ -671,13 +666,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/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: Member 'a' of 'data' for event 'EVENT_A' should be a type name
tests/qapi-schema/nested-struct-data.err +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/nested-struct-data.json:2: Member 'a' of 'data' for command 'foo' should be a type name
tests/qapi-schema/nested-struct-data.exit +1 -1
@@ -1 +1 @@ -0 +1
tests/qapi-schema/nested-struct-data.json +1 -1
@@ -1,4 +1,4 @@ -# FIXME: inline subtypes collide with our desired future use of defaults +# inline subtypes collide with our desired future use of defaults { 'command': 'foo', 'data': { 'a' : { 'string' : 'str', 'integer': 'int' }, 'b' : 'str' }, 'returns': {} }
tests/qapi-schema/nested-struct-data.out +0 -3
@@ -1,3 +0,0 @@ -[OrderedDict([('command', 'foo'), ('data', OrderedDict([('a', OrderedDict([('string', 'str'), ('integer', 'int')])), ('b', 'str')])), ('returns', OrderedDict())])] -[] -[]
tests/qapi-schema/nested-struct-returns.err +1 -0
@@ -0,0 +1 @@ +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.exit +1 -1
@@ -1 +1 @@ -0 +1
tests/qapi-schema/nested-struct-returns.json +1 -1
@@ -1,3 +1,3 @@ -# FIXME: inline subtypes collide with our desired future use of defaults +# inline subtypes collide with our desired future use of defaults { 'command': 'foo', 'returns': { 'a' : { 'string' : 'str', 'integer': 'int' }, 'b' : 'str' } }
tests/qapi-schema/nested-struct-returns.out +0 -3
@@ -1,3 +0,0 @@ -[OrderedDict([('command', 'foo'), ('returns', OrderedDict([('a', OrderedDict([('string', 'str'), ('integer', 'int')])), ('b', 'str')]))])] -[] -[]
Signature · 1 line
2.1.0
PATCH v6 36/36 qapi: Tweak doc references to QMP when QGA is also meant
In reply to Eric BlakeWe have more than one qapi schema in use by more than one protocol. Add a new term 'Client JSON Protocol' for use throughout the document, to avoid confusion on whether something refers only to QMP and not QGA.
---
v6: rebase to earlier changes (was patch 4/5 in followup series)
--- docs/qapi-code-gen.txt | 156 +++++++++++++++++++++++++------------------------ 1 file changed, 81 insertions(+), 75 deletions(-)
docs/qapi-code-gen.txt +81 -75
@@ -13,12 +13,14 @@ functionality to internal and external users. For external users/processes, this interface is made available by a JSON-based wire format for the QEMU Monitor Protocol (QMP) for controlling qemu, as well as the QEMU Guest Agent (QGA) for communicating with the guest. +The remainder of this document uses "Client JSON Protocol" when +referring to the wire contents of a QMP or QGA connection. -To map QMP and QGA interfaces to the native C QAPI implementations, a -JSON-based schema is used to define types and function signatures, and -a set of scripts is used to generate types, signatures, and -marshaling/dispatch code. This document will describe how the schemas, -scripts, and resulting code are used. +To map Client JSON Protocol interfaces to the native C QAPI +implementations, a JSON-based schema is used to define types and +function signatures, and a set of scripts is used to generate types, +signatures, and marshaling/dispatch code. This document will describe +how the schemas, scripts, and resulting code are used. == QMP/Guest agent schema ==
@@ -34,12 +36,13 @@ generated C structs and parameter lists). Ordering doesn't matter between top-level expressions or the keys within an expression, but does matter within dictionary values for 'data' and 'returns' members of a single expression. QAPI schema input is written using 'single -quotes' instead of JSON's "double quotes" (in contrast, QMP usage is -strict JSON and only uses "double quotes", with no comments). As in -JSON, trailing commas are not permitted in arrays or dictionaries. -Input must be ASCII (although QMP supports full Unicode strings, the -QAPI parser does not). At present, there is no place where a QAPI -schema requires the use of JSON numbers or null. +quotes' instead of JSON's "double quotes" (in contrast, Client JSON +Protocol usage is strict JSON and only uses "double quotes", with no +comments). As in JSON, trailing commas are not permitted in arrays or +dictionaries. Input must be ASCII (although a Client JSON Protocol +supports full Unicode strings, the QAPI parser does not). At present, +there is no place where a QAPI schema requires the use of JSON numbers +or null. Comments are allowed; anything between an unquoted # and the following newline is ignored. Although there is not yet a documentation
@@ -81,8 +84,11 @@ that will use those types. Forward references are allowed: the parser scans in two passes, where the first pass learns all type names, and the second validates the schema and generates the code. This allows the definition of complex structs that can have mutually recursive -types, and allows for indefinite nesting of QMP that satisfies the -schema. A type name should not be defined more than once. +types, and allows for indefinite nesting of Client JSON Protocol that +satisfies the schema. A type name should not be defined more than +once. It is permissible for the schema to contain additional types +not used by any commands or events in the Client JSON Protocol, for +the side effect of generated C code used internally. There are seven top-level expressions recognized by the parser: 'include', 'command', 'struct', 'enum', 'union', 'alternate', and
@@ -181,7 +187,7 @@ struct is: 'data': { 'member1': 'str', 'member2': 'int', '*member3': 'str' } } The use of '*' as a prefix to the name means the member is optional in -the corresponding QMP usage. +the corresponding JSON protocol usage. The default initialization value of an optional argument should not be changed between versions of QEMU unless the new default maintains backward
@@ -212,8 +218,8 @@ of use. A struct definition can specify another struct as its base. In this case, the fields of the base type are included as top-level fields -of the new struct's dictionary in the QMP wire format. An example -definition is: +of the new struct's dictionary in the Client JSON Protocol wire +format. An example definition is: { 'struct': 'BlockdevOptionsGenericFormat', 'data': { 'file': 'str' } } { 'struct': 'BlockdevOptionsGenericCOWFormat',
@@ -241,19 +247,19 @@ useful. The list of strings should be lower case; if an enum name represents multiple words, use '-' between words. The string 'max' is not allowed as an enum value, and values should not be repeated. -The enumeration values are passed as strings over the QMP protocol, -but are encoded as C enum integral values in generated code. While -the C code starts numbering at 0, it is better to use explicit +The enumeration values are passed as strings over the Client JSON +Protocol, but are encoded as C enum integral values in generated code. +While the C code starts numbering at 0, it is better to use explicit comparisons to enum values than implicit comparisons to 0; the C code will also include a generated enum member ending in _MAX for tracking the size of the enum, useful when using common functions for converting between strings and enum values. Since the wire format always passes by name, it is acceptable to reorder or add new -enumeration members in any location without breaking QMP clients; -however, removing enum values would break compatibility. For any -struct that has a field that will only contain a finite set of -string values, using an enum type for that field is better than -open-coding the field to be type 'str'. +enumeration members in any location without breaking clients of Client +JSON Protocol; however, removing enum values would break +compatibility. For any struct that has a field that will only contain +a finite set of string values, using an enum type for that field is +better than open-coding the field to be type 'str'. === Union types ===
@@ -279,10 +285,10 @@ values to data types like in this example: 'data': { 'file': 'FileOptions', 'qcow2': 'Qcow2Options' } } -In the QMP wire format, a simple union is represented by a dictionary -that contains the 'type' field as a discriminator, and a 'data' field -that is of the specified data type corresponding to the discriminator -value, as in these examples: +In the Client JSON Protocol, a simple union is represented by a +dictionary that contains the 'type' field as a discriminator, and a +'data' field that is of the specified data type corresponding to the +discriminator value, as in these examples: { "type": "file", "data" : { "filename": "/some/place/my-image" } } { "type": "qcow2", "data" : { "backing-file": "/some/place/my-image",
@@ -365,16 +371,16 @@ Just like for a simple union, an implicit C enum 'NameKind' is created to enumerate the branches for the alternate 'Name'. Unlike a union, the discriminator string is never passed on the wire -for QMP. Instead, the value's JSON type serves as an implicit -discriminator, which in turn means that an alternate can only express -a choice between types represented differently in JSON. If a branch -is typed as the 'bool' built-in, the alternate accepts true and false; -if it is typed as any of the various numeric built-ins, it accepts a -JSON number; if it is typed as a 'str' built-in or named enum type, it -accepts a JSON string; and if it is typed as a complex type (struct or -union), it accepts a JSON object. Two different complex types, for -instance, aren't permitted, because both are represented as a JSON -object. +for the Client JSON Protocol. Instead, the value's JSON type serves +as an implicit discriminator, which in turn means that an alternate +can only express a choice between types represented differently in +JSON. If a branch is typed as the 'bool' built-in, the alternate +accepts true and false; if it is typed as any of the various numeric +built-ins, it accepts a JSON number; if it is typed as a 'str' +built-in or named enum type, it accepts a JSON string; and if it is +typed as a complex type (struct or union), it accepts a JSON object. +Two different complex types, for instance, aren't permitted, because +both are represented as a JSON object. The example alternate declaration above allows using both of the following example objects:
@@ -393,37 +399,37 @@ Usage: { 'command': STRING, '*data': COMPLEX-TYPE-NAME-OR-DICT, Commands are defined by using a dictionary containing several members, where three members are most common. The 'command' member is a -mandatory string, and determines the "execute" value passed in a QMP -command exchange. +mandatory string, and determines the "execute" value passed in a +Client JSON Protocol command exchange. The 'data' argument maps to the "arguments" dictionary passed in as -part of a QMP 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. +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. The 'returns' member describes what will appear in the "return" field -of a QMP reply on successful completion of a command. 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. +of a Client JSON Protocol reply on successful completion of a command. +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. -All commands use a dictionary to report failure, with no way to -specify that in QAPI. Where the error return is different than the -usual GenericError class in order to help the client react differently -to certain error conditions, it is worth documenting this in the -comments before the command declaration. +All commands in Client JSON Protocol use a dictionary to report +failure, with no way to specify that in QAPI. Where the error return +is different than the usual GenericError class in order to help the +client react differently to certain error conditions, it is worth +documenting this in the comments before the command declaration. Some example commands:
@@ -433,7 +439,7 @@ Some example commands: { 'command': 'my-second-command', 'returns': [ 'MyType' ] } -which would validate this QMP transaction: +which would validate this Client JSON Protocol transaction: => { "execute": "my-first-command", "arguments": { "arg1": "hello" } }
@@ -442,14 +448,14 @@ which would validate this QMP transaction: <= { "return": [ { "value": "one" }, { } ] } In rare cases, QAPI cannot express a type-safe representation of a -corresponding QMP command. In these cases, if the command expression -includes the key 'gen' with boolean value false, then the 'data' or -'returns' member that intends to bypass generated type-safety and do -its own manual validation should use an inline dictionary definition, -with a value of '**' rather than a valid type name for the keys that -the generated code will not validate. Please try to avoid adding new -commands that rely on this, and instead use type-safe unions. For an -example of bypass usage: +corresponding Client JSON Protocol command. In these cases, if the +command expression includes the key 'gen' with boolean value false, +then the 'data' or 'returns' member that intends to bypass generated +type-safety and do its own manual validation should use an inline +dictionary definition, with a value of '**' rather than a valid type +name for the keys that the generated code will not validate. Please +try to avoid adding new commands that rely on this, and instead use +type-safe unions. For an example of bypass usage: { 'command': 'netdev_add', 'data': {'type': 'str', 'id': 'str', '*props': '**'},
@@ -493,9 +499,9 @@ Resulting in this JSON object: Schemas are fed into 3 scripts to generate all the code/files that, paired with the core QAPI libraries, comprise everything required to take JSON -commands read in by a QMP/guest agent server, unmarshal the arguments into +commands read in by a Client JSON Protocol server, unmarshal the arguments into the underlying C types, call into the corresponding C function, and map the -response back to a QMP/guest agent response to be returned to the user. +response back to a Client JSON Protocol response to be returned to the user. As an example, we'll use the following schema, which describes a single complex user-defined type (which will produce a C struct, along with a list
Signature · 1 line
2.1.0
Quoted 6 lines · Eric Blake
We want to eventually allow qapi defaults, by making:
'data':{'*flag':'bool'}
as shorthand for something like:
'data':{'flag':{'type':'bool', 'optional':true}}
so that the default can be specified:
'data':{'flag':{'type':'bool', 'optional':true, 'default':true}}
My apologies - I mis-typed Berto's email address, so if you reply-to-all, you'll get a bounce message if you don't manually fix it. Is it worth me resending the series with an updated CC list?
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 3 lines · Eric Blake
My apologies - I mis-typed Berto's email address, so if you reply-to-all, you'll get a bounce message if you don't manually fix it. Is it worth me resending the series with an updated CC list?
For me it's not necessary, but thanks for pointing it out!
Berto
[Qemu-devel] [PATCH v6 37/36] qapi: Support (subset of) \u escapes in strings
In reply to Eric BlakeThe handling of \ inside QAPI strings was less than ideal, and really only worked JSON's \/, \\, \", and our extension of \' (an obvious extension, when you realize we use '' instead of "" for strings). For other things, like '\n', it resulted in a literal 'n' instead of a newline.
Of course, at the moment, we really have no use for escaped characters, as QAPI has to map to C identifiers, and we currently support ASCII only for that. But down the road, we may add support for default values for string parameters to a command or struct; if that happens, it would be nice to correctly support all JSON escape sequences, such as \n or \uXXXX. This gets us closer, by supporting Unicode escapes in the ASCII range.
Since JSON does not require \OCTAL or \xXX escapes, I did not add it here, but it would be an easy addition if we desired it.
---
v6: new patch
--- scripts/qapi.py | 33 +++++++++++++++++++++++++++++++- tests/Makefile | 1 + tests/qapi-schema/escape-too-big.err | 1 + tests/qapi-schema/escape-too-big.exit | 1 + tests/qapi-schema/escape-too-big.json | 3 +++ tests/qapi-schema/escape-too-big.out | 0 tests/qapi-schema/escape-too-short.err | 1 + tests/qapi-schema/escape-too-short.exit | 1 + tests/qapi-schema/escape-too-short.json | 3 +++ tests/qapi-schema/escape-too-short.out | 0 tests/qapi-schema/ident-with-escape.err | 1 - tests/qapi-schema/ident-with-escape.exit | 2 +- tests/qapi-schema/ident-with-escape.json | 2 +- tests/qapi-schema/ident-with-escape.out | 3 +++ tests/qapi-schema/unicode-str.err | 1 + tests/qapi-schema/unicode-str.exit | 1 + tests/qapi-schema/unicode-str.json | 2 ++ tests/qapi-schema/unicode-str.out | 0 18 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 tests/qapi-schema/escape-too-big.err create mode 100644 tests/qapi-schema/escape-too-big.exit create mode 100644 tests/qapi-schema/escape-too-big.json create mode 100644 tests/qapi-schema/escape-too-big.out create mode 100644 tests/qapi-schema/escape-too-short.err create mode 100644 tests/qapi-schema/escape-too-short.exit create mode 100644 tests/qapi-schema/escape-too-short.json create mode 100644 tests/qapi-schema/escape-too-short.out create mode 100644 tests/qapi-schema/unicode-str.err create mode 100644 tests/qapi-schema/unicode-str.exit create mode 100644 tests/qapi-schema/unicode-str.json create mode 100644 tests/qapi-schema/unicode-str.out
scripts/qapi.py +32 -1
@@ -173,7 +173,38 @@ class QAPISchema: raise QAPISchemaError(self, 'Missing terminating "\'"') if esc: - string += ch + if ch == 'b': + string += '\b' + elif ch == 'f': + string += '\f' + elif ch == 'n': + string += '\n' + elif ch == 'r': + string += '\r' + elif ch == 't': + string += '\t' + elif ch == 'u': + value = 0 + for x in range(0, 4): + ch = self.src[self.cursor] + self.cursor += 1 + if ch not in "0123456789abcdefABCDEF": + raise QAPISchemaError(self, + '\\u escape needs 4 ' + 'hex digits') + value = (value << 4) + int(ch, 16) + # If Python 2 and 3 didn't disagree so much on + # how to handle Unicode, then we could allow + # Unicode string defaults. But most of QAPI is + # ASCII-only, so we aren't losing much for now. + if value > 0x7f: + raise QAPISchemaError(self, + 'For now, \\u escape ' + 'only supports values ' + 'up to \\u007f') + string += chr(value) + else: + string += ch esc = False elif ch == "\\": esc = True
tests/Makefile +1 -0
@@ -212,6 +212,7 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \ enum-clash-member.json enum-max-member.json enum-union-clash.json \ enum-bad-name.json funny-char.json indented-expr.json \ missing-type.json bad-ident.json ident-with-escape.json \ + escape-too-short.json escape-too-big.json unicode-str.json \ double-type.json bad-base.json bad-type-bool.json bad-type-int.json \ bad-type-dict.json double-data.json unknown-expr-key.json \ redefined-type.json redefined-command.json redefined-builtin.json \
tests/qapi-schema/escape-too-big.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/escape-too-big.json:3:14: For now, \u escape only supports values up to \u007f
tests/qapi-schema/escape-too-big.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/escape-too-big.json new file +3 -0
@@ -0,0 +1,3 @@ +# we don't support full Unicode strings, yet +# { 'command': 'é' } +{ 'command': '\u00e9' }
tests/qapi-schema/escape-too-big.out new file +0 -0
tests/qapi-schema/escape-too-short.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/escape-too-short.json:3:14: \u escape needs 4 hex digits
tests/qapi-schema/escape-too-short.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/escape-too-short.json new file +3 -0
@@ -0,0 +1,3 @@ +# the \u escape requires 4 hex digits +# { 'command': 'a' } +{ 'command': '\u61' }
tests/qapi-schema/escape-too-short.out new file +0 -0
tests/qapi-schema/ident-with-escape.err +0 -1
@@ -1 +0,0 @@ -tests/qapi-schema/ident-with-escape.json:3: Expression is missing metatype
tests/qapi-schema/ident-with-escape.exit +1 -1
@@ -1 +1 @@ -1 +0
tests/qapi-schema/ident-with-escape.json +1 -1
@@ -1,4 +1,4 @@ -# FIXME: we should allow escape sequences in strings, if they map back to ASCII +# we allow escape sequences in strings, if they map back to ASCII # { 'command': 'fooA', 'data': { 'bar1': 'str' } } { 'c\u006fmmand': '\u0066\u006f\u006FA', 'd\u0061ta': { '\u0062\u0061\u00721': '\u0073\u0074\u0072' } }
tests/qapi-schema/ident-with-escape.out +3 -0
@@ -0,0 +1,3 @@ +[OrderedDict([('command', 'fooA'), ('data', OrderedDict([('bar1', 'str')]))])] +[] +[]
tests/qapi-schema/unicode-str.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/unicode-str.json:2: 'command' uses invalid name 'é'
tests/qapi-schema/unicode-str.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/unicode-str.json new file +2 -0
@@ -0,0 +1,2 @@ +# we don't support full Unicode strings, yet +{ 'command': 'é' }
tests/qapi-schema/unicode-str.out new file +0 -0
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH v6 37/36] qapi: Support (subset of) \u escapes in strings
Quoted 89 lines · Eric Blake
The handling of \ inside QAPI strings was less than ideal, and really only worked JSON's \/, \\, \", and our extension of \' (an obvious extension, when you realize we use '' instead of "" for strings). For other things, like '\n', it resulted in a literal 'n' instead of a newline.
Of course, at the moment, we really have no use for escaped characters, as QAPI has to map to C identifiers, and we currently support ASCII only for that. But down the road, we may add support for default values for string parameters to a command or struct; if that happens, it would be nice to correctly support all JSON escape sequences, such as \n or \uXXXX. This gets us closer, by supporting Unicode escapes in the ASCII range.
Since JSON does not require \OCTAL or \xXX escapes, I did not add it here, but it would be an easy addition if we desired it.
Signed-off-by Eric Blake <[email protected]>---
v6: new patch
--- scripts/qapi.py | 33 +++++++++++++++++++++++++++++++- tests/Makefile | 1 + tests/qapi-schema/escape-too-big.err | 1 + tests/qapi-schema/escape-too-big.exit | 1 + tests/qapi-schema/escape-too-big.json | 3 +++ tests/qapi-schema/escape-too-big.out | 0 tests/qapi-schema/escape-too-short.err | 1 + tests/qapi-schema/escape-too-short.exit | 1 + tests/qapi-schema/escape-too-short.json | 3 +++ tests/qapi-schema/escape-too-short.out | 0 tests/qapi-schema/ident-with-escape.err | 1 - tests/qapi-schema/ident-with-escape.exit | 2 +- tests/qapi-schema/ident-with-escape.json | 2 +- tests/qapi-schema/ident-with-escape.out | 3 +++ tests/qapi-schema/unicode-str.err | 1 + tests/qapi-schema/unicode-str.exit | 1 + tests/qapi-schema/unicode-str.json | 2 ++ tests/qapi-schema/unicode-str.out | 0 18 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 tests/qapi-schema/escape-too-big.err create mode 100644 tests/qapi-schema/escape-too-big.exit create mode 100644 tests/qapi-schema/escape-too-big.json create mode 100644 tests/qapi-schema/escape-too-big.out create mode 100644 tests/qapi-schema/escape-too-short.err create mode 100644 tests/qapi-schema/escape-too-short.exit create mode 100644 tests/qapi-schema/escape-too-short.json create mode 100644 tests/qapi-schema/escape-too-short.out create mode 100644 tests/qapi-schema/unicode-str.err create mode 100644 tests/qapi-schema/unicode-str.exit create mode 100644 tests/qapi-schema/unicode-str.json create mode 100644 tests/qapi-schema/unicode-str.outscripts/qapi.py +25
-1@@ -173,7 +173,38 @@ class QAPISchema: raise QAPISchemaError(self, 'Missing terminating "\'"') if esc: - string += ch + if ch == 'b': + string += '\b' + elif ch == 'f': + string += '\f' + elif ch == 'n': + string += '\n' + elif ch == 'r': + string += '\r' + elif ch == 't': + string += '\t' + elif ch == 'u': + value = 0 + for x in range(0, 4): + ch = self.src[self.cursor] + self.cursor += 1 + if ch not in "0123456789abcdefABCDEF": + raise QAPISchemaError(self, + '\\u escape needs 4 ' + 'hex digits') + value = (value << 4) + int(ch, 16) + # If Python 2 and 3 didn't disagree so much on + # how to handle Unicode, then we could allow + # Unicode string defaults. But most of QAPI is + # ASCII-only, so we aren't losing much for now. + if value > 0x7f:
scripts/qapi.py class QAPISchema: · line 210
Quoted 10 lines
scripts/qapi.py +7
-0+ raise QAPISchemaError(self, + 'For now, \\u escape ' + 'only supports values ' + 'up to \\u007f') + string += chr(value) + else: + string += ch esc = False elif ch == "\\": esc = True
RFC 7159 accepts escapes ["\/bfnrtu], where u is followed by four hexadecimal digits.
Our C JSON parser additionally accepts ', see json-lexer.c.
This code accepts any character. I'd prefer to make it consistent with our C JSON parser instead.
[...]
[Qemu-devel] [PATCH v6 38/36] qapi: Check for member name conflicts with a base class
In reply to Eric BlakeOur type inheritance for both 'struct' and for flat 'union' merges key/value pairs from the base class with those from the type in question. Although the C code currently boxes things so that there is a distinction between which member is referred to, the QMP wire format does not allow passing a key more than once in a single object. Besides, if we ever change the generated C code to not be quite so boxy, we'd want to avoid duplicate member names there, too.
Fix a testsuite entry added in an earlier patch, as well as adding a couple more tests to ensure we have appropriate coverage.
---
v6: new patch
--- scripts/qapi.py | 21 ++++++++++++++++++++- tests/Makefile | 3 ++- tests/qapi-schema/flat-union-branch-clash.err | 1 + tests/qapi-schema/flat-union-branch-clash.exit | 2 +- tests/qapi-schema/flat-union-branch-clash.json | 2 +- tests/qapi-schema/flat-union-branch-clash.out | 9 --------- tests/qapi-schema/struct-base-clash-deep.err | 1 + tests/qapi-schema/struct-base-clash-deep.exit | 1 + tests/qapi-schema/struct-base-clash-deep.json | 9 +++++++++ tests/qapi-schema/struct-base-clash-deep.out | 0 tests/qapi-schema/struct-base-clash.err | 1 + tests/qapi-schema/struct-base-clash.exit | 1 + tests/qapi-schema/struct-base-clash.json | 6 ++++++ tests/qapi-schema/struct-base-clash.out | 0 14 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 tests/qapi-schema/struct-base-clash-deep.err create mode 100644 tests/qapi-schema/struct-base-clash-deep.exit create mode 100644 tests/qapi-schema/struct-base-clash-deep.json create mode 100644 tests/qapi-schema/struct-base-clash-deep.out create mode 100644 tests/qapi-schema/struct-base-clash.err create mode 100644 tests/qapi-schema/struct-base-clash.exit create mode 100644 tests/qapi-schema/struct-base-clash.json create mode 100644 tests/qapi-schema/struct-base-clash.out
scripts/qapi.py +20 -1
@@ -429,6 +429,18 @@ def check_type(expr_info, source, value, allow_array = False, allow_metas=['built-in', 'union', 'alternate', 'struct', 'enum']) +def check_member_clash(expr_info, base_name, data, source = ""): + base = find_struct(base_name) + assert base + base_members = base['data'] + for key in data.keys(): + if key in base_members: + raise QAPIExprError(expr_info, + "Member name '%s'%s clashes with base '%s'" + %(key, source, base_name)) + if base.get('base'): + check_member_clash(expr_info, base['base'], data, source) + def check_command(expr, expr_info): name = expr['command'] allow_star = expr.has_key('gen')
@@ -518,9 +530,14 @@ def check_union(expr, expr_info): check_name(expr_info, "Member of union '%s'" % name, key) # Each value must name a known type; futhermore, in flat unions, - # branches must be a struct + # branches must be a struct with no overlapping member names check_type(expr_info, "Member '%s' of union '%s'" % (key, name), value, allow_array=True, allow_metas=allow_metas) + if base: + branch_struct = find_struct(value) + assert branch_struct + check_member_clash(expr_info, expr['base'], branch_struct['data'], + " of branch '%s'" %key) # If the discriminator names an enum type, then all members # of 'data' must also be members of the enum type.
@@ -597,6 +614,8 @@ def check_struct(expr, expr_info): allow_dict=True, allow_optional=True) check_type(expr_info, "'base' for type '%s'" % name, expr.get('base'), allow_metas=['struct']) + if expr.get('base'): + check_member_clash(expr_info, expr['base'], expr['data']) def check_exprs(schema): for expr_elem in schema.exprs:
tests/Makefile +2 -1
@@ -242,7 +242,8 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \ include-simple.json include-relpath.json include-format-err.json \ include-non-file.json include-no-file.json include-before-err.json \ include-nested-err.json include-self-cycle.json include-cycle.json \ - include-repetition.json event-nest-struct.json event-case.json) + include-repetition.json event-nest-struct.json event-case.json \ + struct-base-clash.json struct-base-clash-deep.json ) GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h \ tests/test-qmp-commands.h tests/test-qapi-event.h
tests/qapi-schema/flat-union-branch-clash.err +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/flat-union-branch-clash.json:10: Member name 'name' of branch 'value1' clashes with base 'Base'
tests/qapi-schema/flat-union-branch-clash.exit +1 -1
@@ -1 +1 @@ -0 +1
tests/qapi-schema/flat-union-branch-clash.json +1 -1
@@ -1,4 +1,4 @@ -# FIXME: we should check for no duplicate keys between branches and base +# we check for no duplicate keys between branches and base { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } { 'struct': 'Base',
tests/qapi-schema/flat-union-branch-clash.out +0 -9
@@ -1,9 +0,0 @@ -[OrderedDict([('enum', 'TestEnum'), ('data', ['value1', 'value2'])]), - OrderedDict([('struct', 'Base'), ('data', OrderedDict([('enum1', 'TestEnum'), ('name', 'str')]))]), - OrderedDict([('struct', 'Branch1'), ('data', OrderedDict([('name', 'str')]))]), - OrderedDict([('struct', 'Branch2'), ('data', OrderedDict([('value', 'int')]))]), - OrderedDict([('union', 'TestUnion'), ('base', 'Base'), ('discriminator', 'enum1'), ('data', OrderedDict([('value1', 'Branch1'), ('value2', 'Branch2')]))])] -[{'enum_name': 'TestEnum', 'enum_values': ['value1', 'value2']}] -[OrderedDict([('struct', 'Base'), ('data', OrderedDict([('enum1', 'TestEnum'), ('name', 'str')]))]), - OrderedDict([('struct', 'Branch1'), ('data', OrderedDict([('name', 'str')]))]), - OrderedDict([('struct', 'Branch2'), ('data', OrderedDict([('value', 'int')]))])]
tests/qapi-schema/struct-base-clash-deep.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/struct-base-clash-deep.json:7: Member name 'name' clashes with base 'Base'
tests/qapi-schema/struct-base-clash-deep.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/struct-base-clash-deep.json new file +9 -0
@@ -0,0 +1,9 @@ +# we check for no duplicate keys with indirect base +{ 'struct': 'Base', + 'data': { 'name': 'str' } } +{ 'struct': 'Mid', + 'base': 'Base', + 'data': { 'value': 'int' } } +{ 'struct': 'Sub', + 'base': 'Mid', + 'data': { 'name': 'str' } }
tests/qapi-schema/struct-base-clash-deep.out new file +0 -0
tests/qapi-schema/struct-base-clash.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/struct-base-clash.json:4: Member name 'name' clashes with base 'Base'
tests/qapi-schema/struct-base-clash.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/struct-base-clash.json new file +6 -0
@@ -0,0 +1,6 @@ +# we check for no duplicate keys with base +{ 'struct': 'Base', + 'data': { 'name': 'str' } } +{ 'struct': 'Sub', + 'base': 'Base', + 'data': { 'name': 'str' } }
tests/qapi-schema/struct-base-clash.out new file +0 -0
Signature · 1 line
2.1.0
Markus Armbruster
Reviewed-byRe: [Qemu-devel] [PATCH v6 38/36] qapi: Check for member name conflicts with a base class
Quoted 13 lines · Eric Blake
Our type inheritance for both 'struct' and for flat 'union' merges key/value pairs from the base class with those from the type in question. Although the C code currently boxes things so that there is a distinction between which member is referred to, the QMP wire format does not allow passing a key more than once in a single object. Besides, if we ever change the generated C code to not be quite so boxy, we'd want to avoid duplicate member names there, too.
Fix a testsuite entry added in an earlier patch, as well as adding a couple more tests to ensure we have appropriate coverage.
Signed-off-by Eric Blake <[email protected]>
[...]
Quoted 26 lines
scripts/qapi.py +12
-0@@ -429,6 +429,18 @@ def check_type(expr_info, source, value, allow_array = False, allow_metas=['built-in', 'union', 'alternate', 'struct', 'enum']) +def check_member_clash(expr_info, base_name, data, source = ""): + base = find_struct(base_name) + assert base + base_members = base['data'] + for key in data.keys(): + if key in base_members: + raise QAPIExprError(expr_info, + "Member name '%s'%s clashes with base '%s'" + %(key, source, base_name)) + if base.get('base'): + check_member_clash(expr_info, base['base'], data, source) + def check_command(expr, expr_info): name = expr['command'] allow_star = expr.has_key('gen')@@ -518,9 +530,14 @@ def check_union(expr, expr_info): check_name(expr_info, "Member of union '%s'" % name, key)
scripts/qapi.py def check_union(expr, expr_info): · line 540
Quoted 10 lines
scripts/qapi.py +6
-1# Each value must name a known type; futhermore, in flat unions, - # branches must be a struct + # branches must be a struct with no overlapping member names check_type(expr_info, "Member '%s' of union '%s'" % (key, name), value, allow_array=True, allow_metas=allow_metas) + if base: + branch_struct = find_struct(value) + assert branch_struct + check_member_clash(expr_info, expr['base'], branch_struct['data'], + " of branch '%s'" %key)
Could pass base instead of expr['base'].
Quoted 12 lines
scripts/qapi.py +2
-0# If the discriminator names an enum type, then all members # of 'data' must also be members of the enum type.@@ -597,6 +614,8 @@ def check_struct(expr, expr_info): allow_dict=True, allow_optional=True) check_type(expr_info, "'base' for type '%s'" % name, expr.get('base'), allow_metas=['struct']) + if expr.get('base'): + check_member_clash(expr_info, expr['base'], expr['data']) def check_exprs(schema): for expr_elem in schema.exprs:
[...]
Quoted 28 lines · Eric Blake
We want to eventually allow qapi defaults, by making:
'data':{'*flag':'bool'}
as shorthand for something like:
'data':{'flag':{'type':'bool', 'optional':true}}
so that the default can be specified:
'data':{'flag':{'type':'bool', 'optional':true, 'default':true}}This series does not quite get us there, but it DOES do a number of other things. It gets rid of the three uses of nested inline structs, changes anonymous unions to use a specific 'alternate' metatype rather than abusing 'union', changes the ambiguous 'type' to the obvious 'struct', and fixes lots of other parser bugs found while designing the testsuite. The testsuite changes make the bulk of this series, with a repeating pattern of writing tests that expose weaknesses in the old parser, then beefing up the generator to catch the problem during the initial parse rather than choking with an obscure python message or even causing a C compilation failure. There are a couple of ideas for things to still fix before all is said and done (such as preventing a collision of members between a struct and its base class, or fixing the parser to understand \uXXXX escape sequences in strings), but at this point, anything raised as a review comment is probably better addressed as followup patches rather than respinning a v7.
v5 was here:
https://lists.gnu.org/archive/html/qemu-devel/2015-03/msg05034.html
Quoted 6 lines
v6 changes are noted in each patch; in particular, several new patches were added (additional tests, split some patches, conversion to 'struct' instead of 'type'). But most of the changes were in direct response to review comments or rebase fallout, so I kept in Reviewed-by markings where possible, to help focus review on the remainder.
Looks good to go to me, except for new PATCH 37, where I suggested a small change. Shouldn't hold up this series. If any other patch still lacks my R-by, let me know.
Quoted 5 lines
I wrote another patch while working on this series, but it was independent enough that I posted it separately (although I based the documentation in this patch as if that, or Markus' alternative, had been applied):
https://lists.gnu.org/archive/html/qemu-devel/2015-04/msg00373.html
Both need a trivial respin to correct a pasto. Yours has a more elaborate commit message, and a test. Mine is less code, in part because it uses a single qnull object instead of allocating one for each use, and it has separate patches for the qobject and the json-parser change.
We can pick one, of we can combine the best of both into a new mini-series. Preferences?
Quoted 10 lines · Markus Armbruster
Quoted 6 lines
v6 changes are noted in each patch; in particular, several new patches were added (additional tests, split some patches, conversion to 'struct' instead of 'type'). But most of the changes were in direct response to review comments or rebase fallout, so I kept in Reviewed-by markings where possible, to help focus review on the remainder.
Looks good to go to me, except for new PATCH 37, where I suggested a small change. Shouldn't hold up this series. If any other patch still lacks my R-by, let me know.
Easier as a followup? Respin just the one patch? Or bite the bullet and rebase the entire series (fixing the other trivial items and adding R-b along the way)?
Quoted 7 lines
Quoted 6 lines
I wrote another patch while working on this series, but it was independent enough that I posted it separately (although I based the documentation in this patch as if that, or Markus' alternative, had been applied):
https://lists.gnu.org/archive/html/qemu-devel/2015-04/msg00373.html
Quoted 8 lines
Both need a trivial respin to correct a pasto. Yours has a more elaborate commit message, and a test. Mine is less code, in part because it uses a single qnull object instead of allocating one for each use, and it has separate patches for the qobject and the json-parser change.
We can pick one, of we can combine the best of both into a new mini-series. Preferences?
I'll tackle a new mini-series with the best of both (I like your idea of reusing the same object across all uses, instead of creating a new one each time, particularly since it resulted in a smaller patch)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
General question first: through which tree should this go?
MAINTAINERS doesn't cover the QAPI generators. Closest related stanza is QAPI (Luiz, Michael R.). Should it cover the generators? Next closest is QAPI Schema (Luiz, you, myself).
For completeness: because we touch qmp_query_pci_bridge() and qmp_query_pci_devices(), get_maintainers.pl also fingers the PCI tree.
If nobody objects, I can take it through my tree. Cc'ing the maintainers just mentioned to give them a chance to chime in.
Quoted 9 lines · Eric Blake
Quoted 7 lines · Markus Armbruster
Quoted 6 lines
v6 changes are noted in each patch; in particular, several new patches were added (additional tests, split some patches, conversion to 'struct' instead of 'type'). But most of the changes were in direct response to review comments or rebase fallout, so I kept in Reviewed-by markings where possible, to help focus review on the remainder.
Quoted 7 lines
Quoted 3 lines
Looks good to go to me, except for new PATCH 37, where I suggested a small change. Shouldn't hold up this series. If any other patch still lacks my R-by, let me know.
Easier as a followup? Respin just the one patch? Or bite the bullet and rebase the entire series (fixing the other trivial items and adding R-b along the way)?
I think we can either
* Respin, but keep the changes really simple. Feel free to leave some issues to followup patches.
* Merge the series except for PATCH 37, with trivial touch-ups on commit. Followup patches to address any remaining issues.
If we take it through my tree, I'm happy to do the touch-ups.
Quoted 12 lines
Quoted 12 lines
Quoted 5 lines
I wrote another patch while working on this series, but it was independent enough that I posted it separately (although I based the documentation in this patch as if that, or Markus' alternative, had been applied):
https://lists.gnu.org/archive/html/qemu-devel/2015-04/msg00373.htmlBoth need a trivial respin to correct a pasto. Yours has a more elaborate commit message, and a test. Mine is less code, in part because it uses a single qnull object instead of allocating one for each use, and it has separate patches for the qobject and the json-parser change.
Quoted 6 lines
Quoted 2 lines
We can pick one, of we can combine the best of both into a new mini-series. Preferences?
I'll tackle a new mini-series with the best of both (I like your idea of reusing the same object across all uses, instead of creating a new one each time, particularly since it resulted in a smaller patch)
Sounds good!
Quoted 11 lines · Markus Armbruster
General question first: through which tree should this go?
MAINTAINERSdoesn't cover the QAPI generators. Closest related stanza is QAPI (Luiz, Michael R.). Should it cover the generators? Next closest is QAPI Schema (Luiz, you, myself).For completeness: because we touch
qmp_query_pci_bridge()andqmp_query_pci_devices(), get_maintainers.pl also fingers the PCI tree.If nobody objects, I can take it through my tree. Cc'ing the maintainers just mentioned to give them a chance to chime in.
Works for me, but that means we may want to also add the qapi generators into MAINTAINERS along-side QAPI Schema for future changes. Of course, as a separate patch.
Quoted 8 lines
Quoted 3 lines
Easier as a followup? Respin just the one patch? Or bite the bullet and rebase the entire series (fixing the other trivial items and adding R-b along the way)?
I think we can either
* Respin, but keep the changes really simple. Feel free to leave some issues to followup patches.
Changes in the qapi schema (new structs) require a rebase, so respin on its way.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 7 lines · On Wed, 29 Apr 2015 06:34:12 -0600 Eric Blake <[email protected]> wrote:
Quoted 6 lines · Markus Armbruster
General question first: through which tree should this go?
MAINTAINERSdoesn't cover the QAPI generators. Closest related stanza is QAPI (Luiz, Michael R.). Should it cover the generators? Next closest is QAPI Schema (Luiz, you, myself).
Quoted 5 lines
Quoted 5 lines
For completeness: because we touch
qmp_query_pci_bridge()andqmp_query_pci_devices(), get_maintainers.pl also fingers the PCI tree.If nobody objects, I can take it through my tree. Cc'ing the maintainers just mentioned to give them a chance to chime in.
I not only don't object, but I support this!
Quoted 3 lines
Works for me, but that means we may want to also add the qapi generators into
MAINTAINERSalong-side QAPI Schema for future changes. Of course, as a separate patch.
Makes a lot of sense to me. Just CC me so that I'm aware which parts of QMP/QAPI you guys are taking.
Quoted 12 lines
Quoted 8 lines
Quoted 3 lines
Easier as a followup? Respin just the one patch? Or bite the bullet and rebase the entire series (fixing the other trivial items and adding R-b along the way)?
I think we can either
* Respin, but keep the changes really simple. Feel free to leave some issues to followup patches.
Changes in the qapi schema (new structs) require a rebase, so respin on its way.