]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
libxl: gentypes.py: Break out libxl_C_type_do_init
authorIan Jackson <ian.jackson@eu.citrix.com>
Tue, 29 Oct 2019 15:19:33 +0000 (15:19 +0000)
committerIan Jackson <ian.jackson@eu.citrix.com>
Tue, 19 Nov 2019 16:34:15 +0000 (16:34 +0000)
This is going to be the common way to initialise things.
_libxl_C_type_init remains the thing for generating the body of the
init function, and for some special cases.

No functional change with existing types: C output is identical.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
tools/libxl/gentypes.py

index 62883acb2e415f77be727fb65226b8a64cb062a2..124285cd666cf905a16bbb7b36c32eb2ac82c7d7 100644 (file)
@@ -165,6 +165,19 @@ def libxl_init_members(ty, nesting = 0):
     else:
         return []
     
+def libxl_C_type_do_init(ty, pass_arg, need_zero=True, indent="    "):
+    s=indent
+    if ty.init_val is not None:
+        s+= "%s = %s;\n" % (pass_arg(idl.PASS_BY_VALUE), ty.init_val)
+    elif ty.init_fn is not None:
+        s+= "%s(%s);\n" % (ty.init_fn, pass_arg(idl.PASS_BY_REFERENCE))
+    elif need_zero:
+        ptr = pass_arg(idl.PASS_BY_REFERENCE)
+        s+= "memset(%s, 0, sizeof(*%s));\n" % (ptr, ptr)
+    else:
+        s=""
+    return s
+
 def _libxl_C_type_init(ty, v, indent = "    ", parent = None, subinit=False):
     s = ""
     if isinstance(ty, idl.KeyedUnion):
@@ -309,15 +322,7 @@ def libxl_C_type_copy_deprecated(field, v, indent = "    ", vparent = None):
         if field.type.dispose_fn is not None:
             s+= "    %s(%s);\n" % (field.type.dispose_fn,
                                    field.type.pass_arg(v, vparent is None))
-
-        s+= "    "
-        if field.type.init_val is not None:
-            s+= "%s = %s;\n" % (field_val, field.type.init_val)
-        elif field.type.init_fn is not None:
-            s+= "%s(%s);\n" % (field.type.init_fn, field_ptr)
-        else:
-            s+= "memset(%s, 0, sizeof(*%s));\n" % (field_ptr, field_ptr)
-
+        s+=libxl_C_type_do_init(field.type, field_pass)
         s+= "}\n"
 
     if s != "":