diff options
author | Neale Ranns <nranns@cisco.com> | 2020-04-22 16:06:45 +0000 |
---|---|---|
committer | Andrew Yourtchenko <ayourtch@gmail.com> | 2020-08-13 17:20:47 +0000 |
commit | 66cb17227ca7410420123f432bb6669272c68b9f (patch) | |
tree | e19fd8ffed93631be9964ba6a3e7eb76e211239b /src | |
parent | 4e138bf173ed81224448dfe7bacd310d5bf34013 (diff) |
vapi: packed enum type generation
Type: fix
if the ,api/.json specifies that a enum should be u8/u16 that the
generated c enum needs to be packed.
Signed-off-by: Neale Ranns <nranns@cisco.com>
Change-Id: Ia0497b45e4c510a5c63cd02e966769bf20686838
(cherry picked from commit b5c0d35f9445d4d99f2c5c7bd3175e68721a8ee5)
Diffstat (limited to 'src')
-rwxr-xr-x | src/vpp-api/vapi/vapi_c_gen.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/vpp-api/vapi/vapi_c_gen.py b/src/vpp-api/vapi/vapi_c_gen.py index 9a285eb98ad..167c8a41a9c 100755 --- a/src/vpp-api/vapi/vapi_c_gen.py +++ b/src/vpp-api/vapi/vapi_c_gen.py @@ -153,6 +153,12 @@ class CSimpleType (SimpleType): 'i64': 'be64toh', 'u64': 'be64toh', } + __packed = "__attribute__((packed))" + pack_dict = { + 'i8': __packed, 'u8': __packed, + 'i16': __packed, 'u16': __packed, + } + def get_c_name(self): return self.name @@ -162,6 +168,9 @@ class CSimpleType (SimpleType): def get_swap_to_host_func_name(self): return self.swap_to_host_dict[self.name] + def get_packed_string(self): + return self.pack_dict[self.name] + def get_swap_to_be_code(self, struct, var, cast=None): x = "%s%s" % (struct, var) return "%s = %s%s(%s);" % (x, @@ -182,14 +191,18 @@ class CSimpleType (SimpleType): pass return False + def get_packed(self): + return self.pack_dict.get(self.name, "") + class CEnum(Enum): def get_c_name(self): return "vapi_enum_%s" % self.name def get_c_def(self): - return "typedef enum {\n%s\n} %s;" % ( + return "typedef enum {\n%s\n} %s %s;" % ( "\n".join([" %s = %s," % (i, j) for i, j in self.value_pairs]), + self.type.get_packed(), self.get_c_name() ) |