Received: from eggs.gnu.org ([2001:4830:134:3::10]:45784) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJcsQ-0007MQ-Fr for qemu-devel@nongnu.org; Mon, 27 Jul 2015 03:31:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZJcsP-0005RB-Fc for qemu-devel@nongnu.org; Mon, 27 Jul 2015 03:31:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39565) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJcsP-0005Qq-AE for qemu-devel@nongnu.org; Mon, 27 Jul 2015 03:31:09 -0400 From: Markus Armbruster References: <1435782155-31412-1-git-send-email-armbru@redhat.com> <1435782155-31412-9-git-send-email-armbru@redhat.com> <55AD8213.80702@redhat.com> Date: Mon, 27 Jul 2015 09:31:06 +0200 In-Reply-To: <55AD8213.80702@redhat.com> (Eric Blake's message of "Mon, 20 Jul 2015 17:19:47 -0600") Message-ID: <87oaiyt5tx.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH RFC v2 08/47] qapi-visit: Fix generated code when schema has forward refs List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: kwolf@redhat.com, berto@igalia.com, qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com Eric Blake writes: > 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. Yes, we've intentionally avoided forward references. Nevertheless, the generators either have to catch and reject them, or make them work. Making them work is easy, so I did that. >> 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 >> --- >> 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 Thanks!