Skip to content

Commit 9fcfc1e

Browse files
donaldhkuba-moo
authored andcommitted
tools/net/ynl: add indexed-array scalar support to ynl-gen-c
Extend ynl-gen-c.py with support for indexed-array that has a scalar sub-type. Signed-off-by: Donald Hunter <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 16cd1a5 commit 9fcfc1e

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

tools/net/ynl/pyynl/ynl_gen_c.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,10 @@ def _complex_member_type(self, ri):
688688
raise Exception(f"Sub-type {self.attr['sub-type']} not supported yet")
689689

690690
def _attr_typol(self):
691-
return f'.type = YNL_PT_NEST, .nest = &{self.nested_render_name}_nest, '
691+
if self.attr['sub-type'] in scalars:
692+
return f'.type = YNL_PT_U{c_upper(self.sub_type[1:])}, '
693+
else:
694+
return f'.type = YNL_PT_NEST, .nest = &{self.nested_render_name}_nest, '
692695

693696
def _attr_get(self, ri, var):
694697
local_vars = ['const struct nlattr *attr2;']
@@ -890,7 +893,7 @@ def new_attr(self, elem, value):
890893
elif elem['type'] == 'nest':
891894
t = TypeNest(self.family, self, elem, value)
892895
elif elem['type'] == 'indexed-array' and 'sub-type' in elem:
893-
if elem["sub-type"] == 'nest':
896+
if elem["sub-type"] in ['nest', 'u32']:
894897
t = TypeArrayNest(self.family, self, elem, value)
895898
else:
896899
raise Exception(f'new_attr: unsupported sub-type {elem["sub-type"]}')
@@ -1674,6 +1677,9 @@ def _multi_parse(ri, struct, init_lines, local_vars):
16741677
if aspec["sub-type"] == 'nest':
16751678
local_vars.append(f'const struct nlattr *attr_{aspec.c_name};')
16761679
array_nests.add(arg)
1680+
elif aspec['sub-type'] in scalars:
1681+
local_vars.append(f'const struct nlattr *attr_{aspec.c_name};')
1682+
array_nests.add(arg)
16771683
else:
16781684
raise Exception(f'Not supported sub-type {aspec["sub-type"]}')
16791685
if 'multi-attr' in aspec:
@@ -1729,11 +1735,17 @@ def _multi_parse(ri, struct, init_lines, local_vars):
17291735
ri.cw.p(f"dst->{aspec.c_name} = calloc(n_{aspec.c_name}, sizeof(*dst->{aspec.c_name}));")
17301736
ri.cw.p(f"dst->n_{aspec.c_name} = n_{aspec.c_name};")
17311737
ri.cw.p('i = 0;')
1732-
ri.cw.p(f"parg.rsp_policy = &{aspec.nested_render_name}_nest;")
1738+
if 'nested-attributes' in aspec:
1739+
ri.cw.p(f"parg.rsp_policy = &{aspec.nested_render_name}_nest;")
17331740
ri.cw.block_start(line=f"ynl_attr_for_each_nested(attr, attr_{aspec.c_name})")
1734-
ri.cw.p(f"parg.data = &dst->{aspec.c_name}[i];")
1735-
ri.cw.p(f"if ({aspec.nested_render_name}_parse(&parg, attr, ynl_attr_type(attr)))")
1736-
ri.cw.p('return YNL_PARSE_CB_ERROR;')
1741+
if 'nested-attributes' in aspec:
1742+
ri.cw.p(f"parg.data = &dst->{aspec.c_name}[i];")
1743+
ri.cw.p(f"if ({aspec.nested_render_name}_parse(&parg, attr, ynl_attr_type(attr)))")
1744+
ri.cw.p('return YNL_PARSE_CB_ERROR;')
1745+
elif aspec.sub_type in scalars:
1746+
ri.cw.p(f"dst->{aspec.c_name}[i] = ynl_attr_get_{aspec.sub_type}(attr);")
1747+
else:
1748+
raise Exception(f"Nest parsing type not supported in {aspec['name']}")
17371749
ri.cw.p('i++;')
17381750
ri.cw.block_end()
17391751
ri.cw.block_end()

0 commit comments

Comments
 (0)