[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v1 1/1] libxl/gentypes: add range init to array elements in json parsing



From: Oleksandr Grytsov <oleksandr_grytsov@xxxxxxxx>

Add initialization of array elements in parse json function.

Currently, array elements are initialized with calloc. Which means
initialize all element fields with zero values. If entries are missed in
json for such fields, it will be equal to zero instead of default values.
The fix is to add range init function before parsing array element for
structures which have defined range init function.

Signed-off-by: Oleksandr Grytsov <oleksandr_grytsov@xxxxxxxx>
---
 tools/libxl/gentypes.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/libxl/gentypes.py b/tools/libxl/gentypes.py
index 6417c9dd8c..4ff5d8a2d0 100644
--- a/tools/libxl/gentypes.py
+++ b/tools/libxl/gentypes.py
@@ -456,6 +456,8 @@ def libxl_C_type_parse_json(ty, w, v, indent = "    ", 
parent = None, discrimina
         s += "        goto out;\n"
         s += "    }\n"
         s += "    for (i=0; (t=libxl__json_array_get(x,i)); i++) {\n"
+        if ty.elem_type.init_fn is not None and 
ty.elem_type.autogenerate_init_fn:
+            s += indent + "    "+"%s_init(&%s[i]);\n" % 
(ty.elem_type.typename, v)
         s += libxl_C_type_parse_json(ty.elem_type, "t", v+"[i]",
                                      indent + "    ", parent)
         s += "    }\n"
-- 
2.17.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.