Message ID | 20250206092658.1383-7-donald.hunter@gmail.com |
---|---|
State | New |
Headers | show |
Series | netlink: specs: add a spec for nl80211 wiphy | expand |
On Thu, 6 Feb 2025 09:26:54 +0000 Donald Hunter wrote: > class Type(SpecAttr): > + starts_with_digit = re.compile(r"^\d") > + > def __init__(self, family, attr_set, attr, value): > super().__init__(family, attr_set, attr, value) > > @@ -74,6 +76,8 @@ class Type(SpecAttr): > self.c_name = c_lower(self.name) > if self.c_name in _C_KW: > self.c_name += '_' > + if self.starts_with_digit.match(self.c_name): > + self.c_name = '_' + self.c_name bit heavyweight with the regex? I think this would do: if self.c_name[0].isdigit(): but either way: Acked-by: Jakub Kicinski <kuba@kernel.org>
Jakub Kicinski <kuba@kernel.org> writes: > On Thu, 6 Feb 2025 09:26:54 +0000 Donald Hunter wrote: >> class Type(SpecAttr): >> + starts_with_digit = re.compile(r"^\d") >> + >> def __init__(self, family, attr_set, attr, value): >> super().__init__(family, attr_set, attr, value) >> >> @@ -74,6 +76,8 @@ class Type(SpecAttr): >> self.c_name = c_lower(self.name) >> if self.c_name in _C_KW: >> self.c_name += '_' >> + if self.starts_with_digit.match(self.c_name): >> + self.c_name = '_' + self.c_name > > bit heavyweight with the regex? I think this would do: > > if self.c_name[0].isdigit(): Agreed. I'll use the simpler method. > but either way: > > Acked-by: Jakub Kicinski <kuba@kernel.org> TY.
diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen_c.py index 803d49bf7c33..1316a4fe798a 100755 --- a/tools/net/ynl/pyynl/ynl_gen_c.py +++ b/tools/net/ynl/pyynl/ynl_gen_c.py @@ -45,6 +45,8 @@ class BaseNlLib: class Type(SpecAttr): + starts_with_digit = re.compile(r"^\d") + def __init__(self, family, attr_set, attr, value): super().__init__(family, attr_set, attr, value) @@ -74,6 +76,8 @@ class Type(SpecAttr): self.c_name = c_lower(self.name) if self.c_name in _C_KW: self.c_name += '_' + if self.starts_with_digit.match(self.c_name): + self.c_name = '_' + self.c_name # Added by resolve(): self.enum_name = None
Turn attribute names with leading digits into valid C names by prepending an underscore, e.g. 5ghz -> _5ghz Signed-off-by: Donald Hunter <donald.hunter@gmail.com> --- tools/net/ynl/pyynl/ynl_gen_c.py | 4 ++++ 1 file changed, 4 insertions(+)