libxl: cleanups for type destructor generation
PATCH 1/1 libxl: cleanups for type destructor generation
Following series cleans up a few niggles in the libxl destructor autogeneration.
PATCH 1/1 libxl: correctly free Reference types in autogenerated destroy functions
# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1282922856 -3600
# Node ID 75a3469cfac671cbf0271527d245e29b34b0e60f
# Parent 76b574e9805f6154f3e651e3610befd7847f97e3
libxl: correctly free Reference types in autogenerated destroy functions
References types should be recursively destroyed and then the actual reference itself should be destroyed.
tools/libxl/gentypes.py +7 -5
@@ -64,6 +64,11 @@ def libxl_C_type_destroy(ty, v, referenc deref = v + "->" else: deref = v + "." + + if ty.passby == libxltypes.PASS_BY_REFERENCE and not reference: + makeref = "&" + else: + makeref = "" s = "" if isinstance(ty, libxltypes.KeyedUnion):
@@ -76,6 +81,8 @@ def libxl_C_type_destroy(ty, v, referenc s += "}\n" elif isinstance(ty, libxltypes.Reference): s += libxl_C_type_destroy(ty.ref_type, v, True, indent, v) + if ty.destructor_fn is not None: + s += "%s(%s);\n" % (ty.destructor_fn, makeref + v) elif isinstance(ty, libxltypes.Struct) and (parent is None or ty.destructor_fn is None): for f in [f for f in ty.fields if not f.const]:
@@ -84,11 +91,6 @@ def libxl_C_type_destroy(ty, v, referenc else: s += libxl_C_type_destroy(f.type, deref + f.name, False, "", deref) else: - if ty.passby == libxltypes.PASS_BY_REFERENCE and not reference: - makeref = "&" - else: - makeref = "" - if ty.destructor_fn is not None: s += "%s(%s);\n" % (ty.destructor_fn, makeref + v)
PATCH 1/1 libxl: correct indentation of _libxl_types.c
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1282922856 -3600
# Node ID 228640a1efbb120939de2718e7a6c997cac2880f # Parent 75a3469cfac671cbf0271527d245e29b34b0e60f
libxl: correct indentation of _libxl_types.c
tools/libxl/gentypes.py +1 -1
@@ -159,7 +159,7 @@ if __name__ == '__main__': f.write("void %s(%s *p)\n" % (ty.destructor_fn, ty.typename)) f.write("{\n") f.write(libxl_C_type_destroy(ty, "p", True)) - f.write("\tmemset(p, LIBXL_DTOR_POISON, sizeof(*p));\n") + f.write(" memset(p, LIBXL_DTOR_POISON, sizeof(*p));\n") f.write("}\n") f.write("\n") f.close()
PATCH 1/1 libxl: builtin list types should be pass-by-reference
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1282923129 -3600
# Node ID 6b7c034c4710056bcc7ecba46971c24f99683236 # Parent 228640a1efbb120939de2718e7a6c997cac2880f
libxl: builtin list types should be pass-by-reference
This makes all _destroy functions consistent wrt freeing the actual reference passed in. Previously we were relying on the reference contained within the type itself which worked but was semantically a little confusing.
tools/libxl/libxl.c +4 -2
@@ -71,9 +71,10 @@ int libxl_ctx_free(libxl_ctx *ctx)return 0 ; } -void libxl_string_list_destroy (libxl_string_list sl) +void libxl_string_list_destroy (libxl_string_list *psl) {int i; +libxl_string_list sl = *psl;if (!sl)return ;
@@ -83,9 +84,10 @@ void libxl_string_list_destroy(libxl_strfree (sl); } -void libxl_key_value_list_destroy (libxl_key_value_list kvl) +void libxl_key_value_list_destroy (libxl_key_value_list *pkvl) {int i; +libxl_key_value_list kvl = *pkvl;if (!kvl)return ;
tools/libxl/libxl.h +2 -2
@@ -234,8 +234,8 @@ int libxl_domain_preserve(libxl_ctx *ctxint libxl_domain_preserve (libxl_ctx *ctx,uint32_t domid,libxl_domain_create_info *info,const char *name_suffix,libxl_uuid new_uuid);/* destructors for builtin data types */ -void libxl_string_list_destroy (libxl_string_list sl); -void libxl_key_value_list_destroy (libxl_key_value_list kvl); +void libxl_string_list_destroy (libxl_string_list *sl); +void libxl_key_value_list_destroy (libxl_key_value_list *kvl);void libxl_file_reference_destroy (libxl_file_reference *f);/*
tools/libxl/libxl.idl +2 -2
@@ -12,8 +12,8 @@ libxl_disk_phystype = Builtin("disk_phys libxl_disk_phystype = Builtin("disk_phystype") libxl_nic_type = Builtin("nic_type") -libxl_string_list = Builtin("string_list", destructor_fn="libxl_string_list_destroy") -libxl_key_value_list = Builtin("key_value_list", destructor_fn="libxl_key_value_list_destroy") +libxl_string_list = Builtin("string_list", destructor_fn="libxl_string_list_destroy", passby=PASS_BY_REFERENCE) +libxl_key_value_list = Builtin("key_value_list", destructor_fn="libxl_key_value_list_destroy", passby=PASS_BY_REFERENCE) libxl_cpumap = Builtin("cpumap", destructor_fn="free")
tools/libxl/libxltypes.py +2 -0
@@ -182,6 +182,8 @@ def parse(f): globs[n] = t elif isinstance(t,type(object)) and issubclass(t, Type): globs[n] = t + elif n in ['PASS_BY_REFERENCE', 'PASS_BY_VALUE']: + globs[n] = t try: execfile(f, globs, locs)