WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 04 of 10] libxl: IDL: refactor code to massage a type

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 04 of 10] libxl: IDL: refactor code to massage a type into a function argument
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Thu, 23 Jun 2011 17:20:55 +0100
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Thu, 23 Jun 2011 09:26:42 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1308846051@xxxxxxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <patchbomb.1308846051@xxxxxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.6.4
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1308845927 -3600
# Node ID 34279f2359cbaaef7c16287e023cae1b023f02d3
# Parent  4186a6ca6799797e24fafa5fe39e55b474b86bf0
libxl: IDL: refactor code to massage a type into a function argument

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r 4186a6ca6799 -r 34279f2359cb tools/libxl/gentypes.py
--- a/tools/libxl/gentypes.py   Thu Jun 23 17:18:37 2011 +0100
+++ b/tools/libxl/gentypes.py   Thu Jun 23 17:18:47 2011 +0100
@@ -84,11 +84,6 @@ def libxl_C_type_destroy(ty, v, indent =
     else:
         deref = v + "."
         
-    if ty.passby == libxltypes.PASS_BY_REFERENCE and parent is not None:
-        makeref = "&"
-    else:
-        makeref = ""
-
     s = ""
     if isinstance(ty, libxltypes.KeyedUnion):
         if parent is None:
@@ -107,7 +102,7 @@ def libxl_C_type_destroy(ty, v, indent =
                 s += libxl_C_type_destroy(f.type, deref + f.name, "", deref)
     else:
         if ty.destructor_fn is not None:
-            s += "%s(%s);\n" % (ty.destructor_fn, makeref + v)
+            s += "%s(%s);\n" % (ty.destructor_fn, ty.pass_arg(v, parent is 
None))
             
     if s != "":
         s = indent + s
diff -r 4186a6ca6799 -r 34279f2359cb tools/libxl/libxltypes.py
--- a/tools/libxl/libxltypes.py Thu Jun 23 17:18:37 2011 +0100
+++ b/tools/libxl/libxltypes.py Thu Jun 23 17:18:47 2011 +0100
@@ -50,6 +50,21 @@ class Type(object):
         else:
             return "%s %s" % (self.typename, n)
         
+    def pass_arg(self, n, isref=None, passby=None):
+        if passby is None: passby = self.passby
+        if isref is None: isref = self.passby == PASS_BY_REFERENCE
+
+        if passby == PASS_BY_REFERENCE:
+            if isref:
+                return "%s" % (n)
+            else:
+                return "&%s" % (n)
+        else:
+            if isref:
+                return "*%s" % (n)
+            else:
+                return "%s" % (n)
+
 class Builtin(Type):
     """Builtin type"""
     def __init__(self, typename, **kwargs):

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel