Skip to content

Commit 17b8481

Browse files
committed
Correct the max_num for array
A operation can have multiple values with random order. The value of max_num in array should use the max value after traversing the ops. Signed-off-by: Zibo Gong <[email protected]>
1 parent f97a79a commit 17b8481

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

ynl-gen-cpp.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,17 +1705,20 @@ def put_op_name_fwd(family, cw):
17051705
def put_op_name(family, cw):
17061706
map_name = f"{family.c_name}_op_strmap"
17071707
max_num = "0"
1708+
max_value = 0
17081709
for op_name, op in family.msgs.items():
17091710
if op.rsp_value:
17101711
# Make sure we don't add duplicated entries, if multiple commands
17111712
# produce the same response in legacy families.
17121713
if family.rsp_by_value[op.rsp_value] != op:
17131714
continue
17141715

1715-
if op.req_value == op.rsp_value:
1716+
if op.req_value == op.rsp_value and op.rsp_value > max_value:
17161717
max_num = f"{op.enum_name}"
1717-
else:
1718+
max_value = op.rsp_value
1719+
elif op.rsp_value > max_value:
17181720
max_num = f"{op.rsp_value}"
1721+
max_value = op.rsp_value
17191722

17201723
cw.block_start(
17211724
line=f"static constexpr std::array<std::string_view, {max_num} + 1> {map_name} = []()"
@@ -2250,8 +2253,18 @@ def render_user_family(family, cw, prototype):
22502253

22512254
if family.ntfs:
22522255
max_num = "0"
2256+
max_value = 0
22532257
for ntf_op_name, ntf_op in family.ntfs.items():
2254-
max_num = ntf_op.enum_name
2258+
real_op = (
2259+
family.req_by_value[ntf_op.rsp_value] if family.is_classic() else ntf_op
2260+
)
2261+
if real_op.req_value and real_op.req_value > max_value:
2262+
max_value = real_op.req_value
2263+
max_num = real_op.enum_name
2264+
elif real_op.rsp_value and real_op.rsp_value > max_value:
2265+
max_value = real_op.rsp_value
2266+
max_num = real_op.enum_name
2267+
22552268
cw.block_start(
22562269
line=f"static constexpr std::array<ynl_ntf_info, {max_num} + 1> {family.c_name}_ntf_info = []()"
22572270
)

0 commit comments

Comments
 (0)