mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
libxl: gentypes.py: Break out libxl_C_type_do_init
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>
This commit is contained in:
1 parent
dde31350cb
commit
f710b76911
1 file changed
+14
-9
+14
-9
@@ -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 != "":
|
||||
|
||||