[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH RFC v2 08/47] qapi-visit: Fix generated code whe
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH RFC v2 08/47] qapi-visit: Fix generated code when schema has forward refs |
Date: |
Mon, 20 Jul 2015 17:19:47 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 |
On 07/01/2015 02:21 PM, Markus Armbruster wrote:
> The visit_type_implicit_FOO() are generated on demand, right before
> their first use. Used by visit_type_STRUCT_fields() when STRUCT has
> base FOO, and by visit_type_UNION() when flat UNION has member a FOO.
>
> If the schema defines FOO after its first use as struct base or flat
> union member, visit_type_implicit_FOO() calls
> visit_type_implicit_FOO() before its definition, which doesn't
> compile.
None of our public qapi .json files currently do this, so no difference
to the generated code used in qemu proper.
>
> Rearrange qapi-schema-test.json to demonstrate the bug.
Indeed, without testsuite exposure, nothing was relying on this fix.
>
> Fix by generating the necessary forward declaration.
>
> Signed-off-by: Markus Armbruster <address@hidden>
> ---
> scripts/qapi-visit.py | 15 ++++++++++++++-
> tests/qapi-schema/qapi-schema-test.json | 30 +++++++++++++++++-------------
> tests/qapi-schema/qapi-schema-test.out | 10 +++++-----
> 3 files changed, 36 insertions(+), 19 deletions(-)
>
> +++ b/scripts/qapi-visit.py
> @@ -17,13 +17,23 @@ from qapi import *
> import re
>
> implicit_structs = []
> +struct_fields_seen = set()
>
> def generate_visit_implicit_struct(type):
> global implicit_structs
> if type in implicit_structs:
> return ''
> implicit_structs.append(type)
> - return mcgen('''
...
> + ret += mcgen('''
Oddly enough, the ''' is at the same indentation,...
>
> static void visit_type_implicit_%(c_type)s(Visitor *m, %(c_type)s **obj,
> Error **errp)
> {
> @@ -38,8 +48,11 @@ static void visit_type_implicit_%(c_type)s(Visitor *m,
> %(c_type)s **obj, Error *
> }
> ''',
> c_type=type_name(type))
> + return ret
so nothing needed to be reindented here :)
Reviewed-by: Eric Blake <address@hidden>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
- [Qemu-devel] [PATCH RFC v2 25/47] qapi: Make generators work on sorted schema expressions, (continued)
- [Qemu-devel] [PATCH RFC v2 25/47] qapi: Make generators work on sorted schema expressions, Markus Armbruster, 2015/07/01
- [Qemu-devel] [PATCH RFC v2 15/47] qapi: Fix to reject union command arguments, Markus Armbruster, 2015/07/01
- [Qemu-devel] [PATCH RFC v2 20/47] qapi: Rename class QAPISchema to QAPISchemaParser, Markus Armbruster, 2015/07/01
- [Qemu-devel] [PATCH RFC v2 18/47] qapi-commands: Don't feed output of mcgen() to mcgen() again, Markus Armbruster, 2015/07/01
- [Qemu-devel] [PATCH RFC v2 08/47] qapi-visit: Fix generated code when schema has forward refs, Markus Armbruster, 2015/07/01
- Re: [Qemu-devel] [PATCH RFC v2 08/47] qapi-visit: Fix generated code when schema has forward refs,
Eric Blake <=
- [Qemu-devel] [PATCH RFC v2 06/47] qapi: Drop unused and useless parameters and variables, Markus Armbruster, 2015/07/01
- [Qemu-devel] [PATCH RFC v2 29/47] qapi: Replace dirty is_c_ptr() by method c_null(), Markus Armbruster, 2015/07/01