From: Wei Liu Subject: [PATCH 6/8] gentypes: set pointer to NULL Date: Tue, 24 Feb 2015 14:57:02 +0000 Message-ID: <1424789824-19946-7-git-send-email-wei.liu2@citrix.com> References: <1424789824-19946-1-git-send-email-wei.liu2@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1424789824-19946-1-git-send-email-wei.liu2@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Wei Liu , ian.jackson@eu.citrix.com, ian.campbell@citrix.com List-Id: xen-devel@lists.xenproject.org If the dispose_fn of a type is "free" it means it should be later set to NULL. Signed-off-by: Wei Liu Cc: Ian Campbell Cc: Ian Jackson --- tools/libxl/gentypes.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tools/libxl/gentypes.py b/tools/libxl/gentypes.py index 804cb59..64dc7aa 100644 --- a/tools/libxl/gentypes.py +++ b/tools/libxl/gentypes.py @@ -78,14 +78,20 @@ def libxl_C_type_dispose(ty, v, indent = " ", parent = None): raise Exception("Array type must have a parent") if ty.elem_type.dispose_fn is not None: s += "{\n" - s += " int i;\n" - s += " for (i=0; i<%s; i++)\n" % (parent + ty.lenvar.name) + s += " if (%s) {\n" % (ty.pass_arg(v, parent is None),) + s += " int i;\n" + s += " for (i=0; i<%s; i++)\n" % (parent + ty.lenvar.name) s += libxl_C_type_dispose(ty.elem_type, v+"[i]", - indent + " ", parent) + indent + " ", parent) if ty.dispose_fn is not None: if ty.elem_type.dispose_fn is not None: - s += " " + s += " " s += "%s(%s);\n" % (ty.dispose_fn, ty.pass_arg(v, parent is None)) + if ty.dispose_fn == "free": + if ty.elem_type.dispose_fn is not None: s += " " + s += " %s = NULL;\n" % (ty.pass_arg(v, parent is None),) + if ty.elem_type.dispose_fn is not None: + s += " }\n" if ty.elem_type.dispose_fn is not None: s += "}\n" elif isinstance(ty, idl.Struct) and (parent is None or ty.dispose_fn is None): @@ -95,7 +101,8 @@ def libxl_C_type_dispose(ty, v, indent = " ", parent = None): else: if ty.dispose_fn is not None: s += "%s(%s);\n" % (ty.dispose_fn, ty.pass_arg(v, parent is None)) - + if ty.dispose_fn == "free": + s += "%s = NULL;\n" % (ty.pass_arg(v, parent is None),) if s != "": s = indent + s return s.replace("\n", "\n%s" % indent).rstrip(indent) -- 1.9.1