Ian Campbell
2010-Aug-27 15:32 UTC
[Xen-devel] [PATCH 0 of 3] libxl: cleanups for type destructor generation
Following series cleans up a few niggles in the libxl destructor autogeneration. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Aug-27 15:32 UTC
[Xen-devel] [PATCH 1 of 3] libxl: correctly free Reference types in autogenerated destroy functions
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # 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. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 76b574e9805f -r 75a3469cfac6 tools/libxl/gentypes.py --- a/tools/libxl/gentypes.py Fri Aug 27 16:27:36 2010 +0100 +++ b/tools/libxl/gentypes.py Fri Aug 27 16:27:36 2010 +0100 @@ -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) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Aug-27 15:32 UTC
[Xen-devel] [PATCH 2 of 3] libxl: correct indentation of _libxl_types.c
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1282922856 -3600 # Node ID 228640a1efbb120939de2718e7a6c997cac2880f # Parent 75a3469cfac671cbf0271527d245e29b34b0e60f libxl: correct indentation of _libxl_types.c Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 75a3469cfac6 -r 228640a1efbb tools/libxl/gentypes.py --- a/tools/libxl/gentypes.py Fri Aug 27 16:27:36 2010 +0100 +++ b/tools/libxl/gentypes.py Fri Aug 27 16:27:36 2010 +0100 @@ -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() _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Aug-27 15:32 UTC
[Xen-devel] [PATCH 3 of 3] libxl: builtin list types should be pass-by-reference
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # 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. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 228640a1efbb -r 6b7c034c4710 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Fri Aug 27 16:27:36 2010 +0100 +++ b/tools/libxl/libxl.c Fri Aug 27 16:32:09 2010 +0100 @@ -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_str free(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; diff -r 228640a1efbb -r 6b7c034c4710 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Fri Aug 27 16:27:36 2010 +0100 +++ b/tools/libxl/libxl.h Fri Aug 27 16:32:09 2010 +0100 @@ -234,8 +234,8 @@ int libxl_domain_preserve(libxl_ctx *ctx int 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); /* diff -r 228640a1efbb -r 6b7c034c4710 tools/libxl/libxl.idl --- a/tools/libxl/libxl.idl Fri Aug 27 16:27:36 2010 +0100 +++ b/tools/libxl/libxl.idl Fri Aug 27 16:32:09 2010 +0100 @@ -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") diff -r 228640a1efbb -r 6b7c034c4710 tools/libxl/libxltypes.py --- a/tools/libxl/libxltypes.py Fri Aug 27 16:27:36 2010 +0100 +++ b/tools/libxl/libxltypes.py Fri Aug 27 16:32:09 2010 +0100 @@ -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) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Reasonably Related Threads
- [PATCH 00 of 16] libxl: autogenerate type definitions and destructor functions
- [PATCH]: add libxl python binding
- [PATCH] libxl: do not overwrite user supplied config when running bootloader
- [PATCH 00/28] libxl: ocaml: improve the bindings
- [PATCH 00 of 10 v3] Automatic NUMA placement for xl