api: enforce vla is last and fixed string type
[vpp.git] / src / tools / vppapigen / vppapigen_c.py
index 6c4ca35..c1bc11d 100644 (file)
@@ -13,6 +13,7 @@ top_boilerplate = '''\
  * Automatically generated: please edit the input file NOT this file!
  */
 
+#include <stdbool.h>
 #if defined(vl_msg_id)||defined(vl_union_id) \\
     || defined(vl_printfun) ||defined(vl_endianfun) \\
     || defined(vl_api_version)||defined(vl_typedefs) \\
@@ -152,8 +153,15 @@ def typedefs(objs, aliases, filename):
                     if b.lengthfield:
                         output += "    %s %s[0];\n" % (api2c(b.fieldtype), b.fieldname)
                     else:
-                        output += "    %s %s[%s];\n" % (api2c(b.fieldtype), b.fieldname,
-                                                        b.length)
+                        # Fixed length strings decay to nul terminated u8
+                        if b.fieldtype == 'string':
+                            if b.modern_vla:
+                                output += '    {} {};\n'.format(api2c(b.fieldtype), b.fieldname)
+                            else:
+                                output += '    u8 {}[{}];\n'.format(b.fieldname, b.length)
+                        else:
+                            output += "    %s %s[%s];\n" % (api2c(b.fieldtype), b.fieldname,
+                                                            b.length)
                 else:
                     raise ValueError("Error in processing array type %s" % b)
 
@@ -227,6 +235,7 @@ endian_strings = {
     'i16': 'clib_net_to_host_u16',
     'i32': 'clib_net_to_host_u32',
     'i64': 'clib_net_to_host_u64',
+    'f64': 'clib_net_to_host_u64',
 }
 
 
@@ -294,7 +303,7 @@ def version_tuple(s, module):
 #
 # Plugin entry point
 #
-def run(input_filename, s, file_crc):
+def run(input_filename, s):
     basename = os.path.basename(input_filename)
     filename, file_extension = os.path.splitext(basename)
     output = top_boilerplate.format(datestring=datestring,
@@ -307,6 +316,6 @@ def run(input_filename, s, file_crc):
     output += endianfun(s['types'] + s['Define'])
     output += version_tuple(s, basename)
     output += bottom_boilerplate.format(input_filename=basename,
-                                        file_crc=file_crc)
+                                        file_crc=s['file_crc'])
 
     return output