aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsrc/vpp-api/vapi/vapi_c_gen.py15
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()
)