[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 13/17] qapi: Fix code generated for optional conditional struct me
From: |
Markus Armbruster |
Subject: |
[PULL 13/17] qapi: Fix code generated for optional conditional struct member |
Date: |
Wed, 26 Apr 2023 07:57:40 +0200 |
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: 44ea9d9be33c (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>
---
scripts/qapi/visit.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py
index 26a584ee4c..c56ea4d724 100644
--- a/scripts/qapi/visit.py
+++ b/scripts/qapi/visit.py
@@ -74,11 +74,13 @@ def gen_visit_object_members(name: str,
sep = ''
for memb in members:
if memb.optional and not memb.need_has():
+ ret += memb.ifcond.gen_if()
ret += mcgen('''
bool has_%(c_name)s = !!obj->%(c_name)s;
''',
c_name=c_name(memb.name))
sep = '\n'
+ ret += memb.ifcond.gen_endif()
ret += sep
if base:
--
2.39.2
- [PULL 00/17] QAPI patches patches for 2023-04-26, Markus Armbruster, 2023/04/26
- [PULL 03/17] qapi: Clean up after removal of simple unions, Markus Armbruster, 2023/04/26
- [PULL 02/17] qapi/schema: Use super(), Markus Armbruster, 2023/04/26
- [PULL 08/17] qapi: Fix to reject 'data': 'mumble' in struct, Markus Armbruster, 2023/04/26
- [PULL 01/17] qapi: Fix error message format regression, Markus Armbruster, 2023/04/26
- [PULL 13/17] qapi: Fix code generated for optional conditional struct member,
Markus Armbruster <=
- [PULL 16/17] qapi: Improve specificity of type/member descriptions, Markus Armbruster, 2023/04/26
- [PULL 14/17] qapi: Require boxed for conditional command and event arguments, Markus Armbruster, 2023/04/26
- [PULL 07/17] qapi: Fix error message when type name or array is expected, Markus Armbruster, 2023/04/26
- [PULL 11/17] tests/qapi-schema: Clean up positive test for conditionals, Markus Armbruster, 2023/04/26
- [PULL 06/17] qapi: Simplify code a bit after previous commits, Markus Armbruster, 2023/04/26
- [PULL 04/17] qapi: Split up check_type(), Markus Armbruster, 2023/04/26
- [PULL 15/17] qapi: support updating expected test output via make, Markus Armbruster, 2023/04/26
- [PULL 05/17] qapi: Improve error message for unexpected array types, Markus Armbruster, 2023/04/26
- [PULL 12/17] tests/qapi-schema: Cover optional conditional struct member, Markus Armbruster, 2023/04/26
- [PULL 10/17] tests/qapi-schema: Rename a few conditionals, Markus Armbruster, 2023/04/26