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 03 of 10] libxl: IDL: handle generation of pass-by-re

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 03 of 10] libxl: IDL: handle generation of pass-by-reference arguments
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Thu, 23 Jun 2011 17:20:54 +0100
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Thu, 23 Jun 2011 09:25:47 -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 1308845917 -3600
# Node ID 4186a6ca6799797e24fafa5fe39e55b474b86bf0
# Parent  ba383ce75f8bba3e08a84c660c8383c26d23aaa8
libxl: IDL: handle generation of pass-by-reference arguments.

Up until now everything with a destructor function happened to be
pass-by-reference so the current code worked but this will not be the case for
*_to_string and *_to_json. Put some infrastructure in place and use it.

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

diff -r ba383ce75f8b -r 4186a6ca6799 tools/libxl/gentypes.py
--- a/tools/libxl/gentypes.py   Thu Jun 23 17:18:24 2011 +0100
+++ b/tools/libxl/gentypes.py   Thu Jun 23 17:18:37 2011 +0100
@@ -178,10 +178,10 @@ if __name__ == '__main__':
     for ty in types:
         f.write(libxl_C_type_define(ty) + ";\n")
         if ty.destructor_fn is not None:
-            f.write("void %s(%s *p);\n" % (ty.destructor_fn, ty.typename))
+            f.write("void %s(%s);\n" % (ty.destructor_fn, ty.make_arg("p")))
         if isinstance(ty, libxltypes.Enumeration):
-            f.write("const char *%s_to_string(%s e);\n" % (ty.typename, 
ty.typename))
-            f.write("int %s_from_string(const char *s, %s *e);\n" % 
(ty.typename, ty.typename))
+            f.write("const char *%s_to_string(%s);\n" % (ty.typename, 
ty.make_arg("p")))
+            f.write("int %s_from_string(const char *s, %s);\n" % (ty.typename, 
ty.make_arg("e", passby=libxltypes.PASS_BY_REFERENCE)))
             f.write("extern libxl_enum_string_table %s_string_table[];\n" % 
(ty.typename))
         f.write("\n")
 
@@ -213,7 +213,7 @@ if __name__ == '__main__':
 """ % " ".join(sys.argv))
 
     for ty in [t for t in types if t.destructor_fn is not None and 
t.autogenerate_destructor]:
-        f.write("void %s(%s *p)\n" % (ty.destructor_fn, ty.typename))
+        f.write("void %s(%s)\n" % (ty.destructor_fn, ty.make_arg("p")))
         f.write("{\n")
         f.write(libxl_C_type_destroy(ty, "p"))
         f.write("    memset(p, LIBXL_DTOR_POISON, sizeof(*p));\n")
diff -r ba383ce75f8b -r 4186a6ca6799 tools/libxl/libxl.idl
--- a/tools/libxl/libxl.idl     Thu Jun 23 17:18:24 2011 +0100
+++ b/tools/libxl/libxl.idl     Thu Jun 23 17:18:37 2011 +0100
@@ -4,8 +4,8 @@
 #
 
 libxl_domid = Builtin("domid")
-libxl_uuid = Builtin("uuid")
-libxl_mac = Builtin("mac")
+libxl_uuid = Builtin("uuid", passby=PASS_BY_REFERENCE)
+libxl_mac = Builtin("mac", passby=PASS_BY_REFERENCE)
 libxl_cpumap = Builtin("cpumap", destructor_fn="libxl_cpumap_destroy", 
passby=PASS_BY_REFERENCE)
 libxl_cpuarray = Builtin("cpuarray", destructor_fn="libxl_cpuarray_destroy", 
passby=PASS_BY_REFERENCE)
 libxl_cpuid_policy_list = Builtin("cpuid_policy_list", 
destructor_fn="libxl_cpuid_destroy", passby=PASS_BY_REFERENCE)
diff -r ba383ce75f8b -r 4186a6ca6799 tools/libxl/libxltypes.py
--- a/tools/libxl/libxltypes.py Thu Jun 23 17:18:24 2011 +0100
+++ b/tools/libxl/libxltypes.py Thu Jun 23 17:18:37 2011 +0100
@@ -42,6 +42,14 @@ class Type(object):
     def marshal_out(self):
         return self.dir in [DIR_OUT, DIR_BOTH]
 
+    def make_arg(self, n, passby=None):
+        if passby is None: passby = self.passby
+        
+        if passby == PASS_BY_REFERENCE:
+            return "%s *%s" % (self.typename, n)
+        else:
+            return "%s %s" % (self.typename, n)
+        
 class Builtin(Type):
     """Builtin type"""
     def __init__(self, typename, **kwargs):

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