qemu-e2k/scripts/qapi
Markus Armbruster 713d921aed qapi: Fix code generated for optional conditional struct member
The generated member visit neglects to emit #if around a conditional
struct member's has_ variable.  For instance,
tests/qapi-schema/qapi-schema-test.json generates

    #if defined(TEST_IF_STRUCT)
    bool visit_type_TestIfStruct_members(Visitor *v, TestIfStruct *obj, Error **errp)
    {
--->	bool has_baz = !!obj->baz;

	if (!visit_type_int(v, "foo", &obj->foo, errp)) {
	    return false;
	}
    #if defined(TEST_IF_STRUCT_MEMBER)
	if (!visit_type_int(v, "bar", &obj->bar, errp)) {
	    return false;
	}
    #endif /* defined(TEST_IF_STRUCT_MEMBER) */
    #if defined(TEST_IF_STRUCT_MEMBER)
	if (visit_optional(v, "baz", &has_baz)) {
	    if (!visit_type_str(v, "baz", &obj->baz, errp)) {
		return false;
	    }
	}
    #endif /* defined(TEST_IF_STRUCT_MEMBER) */
	return true;
    }
    [...]
    #endif /* defined(TEST_IF_STRUCT) */

Won't compile when TEST_IF_STRUCT is defined and TEST_IF_STRUCT_MEMBER
isn't.

Fix that the obvious way:

    #if defined(TEST_IF_STRUCT_MEMBER)
	bool has_baz = !!obj->baz;
    #endif /* defined(TEST_IF_STRUCT_MEMBER) */

Fixes: 44ea9d9be3 (qapi: Start to elide redundant has_FOO in generated C)
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20230316071325.492471-14-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
2023-04-24 15:21:39 +02:00
..
__init__.py
.flake8 qapi: Update flake8 config 2023-02-23 12:49:39 +01:00
.isort.cfg
commands.py qapi-gen: mark coroutine QMP command functions as coroutine_fn 2023-04-20 11:17:35 +02:00
common.py qapi: Avoid generating C identifier 'linux' 2022-07-13 12:19:18 +03:00
error.py
events.py qapi: Start to elide redundant has_FOO in generated C 2022-12-13 18:31:37 +01:00
expr.py qapi: Fix to reject 'data': 'mumble' in struct 2023-04-24 15:21:39 +02:00
gen.py qapi: Start to elide redundant has_FOO in generated C 2022-12-13 18:31:37 +01:00
introspect.py qapi: Add feature flags to enum members 2021-10-27 17:18:55 +02:00
main.py qapi: Fix error message format regression 2023-04-24 15:09:10 +02:00
mypy.ini
parser.py qapi: remove JSON value FIXME 2023-02-23 13:01:45 +01:00
pylintrc qapi: update pylint configuration 2023-02-23 12:49:39 +01:00
schema.py qapi/schema: Use super() 2023-04-24 15:09:24 +02:00
source.py
types.py qapi: Start to elide redundant has_FOO in generated C 2022-12-13 18:31:37 +01:00
visit.py qapi: Fix code generated for optional conditional struct member 2023-04-24 15:21:39 +02:00