[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [XEN PATCH for-4.13 v2 3/4] 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@xxxxxxxxxxxxx> --- tools/libxl/gentypes.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tools/libxl/gentypes.py b/tools/libxl/gentypes.py index 62883acb2e..124285cd66 100644 --- a/tools/libxl/gentypes.py +++ b/tools/libxl/gentypes.py @@ -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 != "": -- 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |