diff options
author | Klement Sekera <klement.sekera@gmail.com> | 2024-03-19 11:06:59 +0100 |
---|---|---|
committer | Ole Tr�an <otroan@employees.org> | 2024-10-07 11:40:48 +0000 |
commit | 22c7420dfbc0528a8b06138beb8f3b760f316d6e (patch) | |
tree | 7b4e853d4908dd9ff4b1e1936685d4f062b5adaf /src/vpp-api/vapi | |
parent | 911c0fb23aef158567aaf38b0798ac48fd957d8e (diff) |
vapi: don't store dict in length field
Rather validate the format and use proper Field call.
Type: fix
Fixes: d7a32ebd9948ff37c15d8b6e0e5d9cf243026239
Change-Id: I78ac1e62911d613dc0d7a9bd6e8784fbe7f0a797
Signed-off-by: Klement Sekera <klement.sekera@gmail.com>
Diffstat (limited to 'src/vpp-api/vapi')
-rw-r--r-- | src/vpp-api/vapi/vapi_json_parser.py | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/src/vpp-api/vapi/vapi_json_parser.py b/src/vpp-api/vapi/vapi_json_parser.py index c06cb8cf77b..0fd0663dcab 100644 --- a/src/vpp-api/vapi/vapi_json_parser.py +++ b/src/vpp-api/vapi/vapi_json_parser.py @@ -26,25 +26,11 @@ class Field(object): def __str__(self): if self.len is None: - return "Field(name: %s, type: %s)" % (self.name, self.type) - elif type(self.len) == dict: - return "Field(name: %s, type: %s, length: %s)" % ( - self.name, - self.type, - self.len, - ) + return f"Field(name: {self.name}, type: {self.type})" elif self.len > 0: - return "Field(name: %s, type: %s, length: %s)" % ( - self.name, - self.type, - self.len, - ) + return "Field(name: {self.name}, type: {self.type}, length: {self.len})" else: - return "Field(name: %s, type: %s, variable length stored in: %s)" % ( - self.name, - self.type, - self.nelem_field, - ) + return "Field(name: {self.name}, type: {self.type}, VLA length in: {self.nelem_field})" def is_vla(self): return self.nelem_field is not None @@ -282,6 +268,22 @@ class StructType(Type, Struct): "While parsing type `%s': array `%s' has " "variable length" % (name, field[1]) ) + elif type(field[2]) is dict: + # the concept of default values is broken beyond repair: + # + # if following is allowed: + # typedef feature1 { u32 table_id[default=0xffffffff]; } + # typedef feature2 { u32 hash_buckets[default=1024]; } + # union here_we_go { vl_api_feature1_t this; vl_api_feature2_t that; }; + # + # what does it mean to set the defaults for instance of here_we_go? + # + # because of that, we parse it here, but don't do anything about it... + if len(field[2]) != 1 or "default" not in field[2]: + raise ParseError( + f"Don't know how to parse field `{field}' of type definition for type `{t}'" + ) + p = field_class(field_name=field[1], field_type=field_type) else: p = field_class( field_name=field[1], field_type=field_type, array_len=field[2] |