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 11 of 32] tools: libxl: add concept of in- and out-pu

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 11 of 32] tools: libxl: add concept of in- and out-put only data types to IDL
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Mon, 18 Apr 2011 14:53:33 +0100
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Mon, 18 Apr 2011 07:08:53 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1303134802@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.1303134802@xxxxxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.6.4
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1303134044 -3600
# Node ID 51e2379b91a72cfc1e218412100e873e1bc80045
# Parent  4f5a79bd1170afd940f225b7b3e3a83792f4bca1
tools: libxl: add concept of in- and out-put only data types to IDL

This allow language bindings to only emit the relevant conversion functions.

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

diff -r 4f5a79bd1170 -r 51e2379b91a7 tools/libxl/libxl.idl
--- a/tools/libxl/libxl.idl     Mon Apr 18 14:40:15 2011 +0100
+++ b/tools/libxl/libxl.idl     Mon Apr 18 14:40:44 2011 +0100
@@ -348,7 +348,7 @@ libxl_physinfo = Struct("physinfo", [
     ("nr_nodes", uint32),
     ("hw_cap", libxl_hwcap),
     ("phys_cap", uint32),
-    ], destructor_fn=None)
+    ], destructor_fn=None, dir=DIR_OUT)
 
 libxl_topologyinfo = Struct("topologyinfo", [
     ("coremap", libxl_cpuarray,   False, "cpu to core map"),
diff -r 4f5a79bd1170 -r 51e2379b91a7 tools/libxl/libxltypes.py
--- a/tools/libxl/libxltypes.py Mon Apr 18 14:40:15 2011 +0100
+++ b/tools/libxl/libxltypes.py Mon Apr 18 14:40:44 2011 +0100
@@ -3,10 +3,18 @@ import sys
 PASS_BY_VALUE = 1
 PASS_BY_REFERENCE = 2
 
+DIR_NONE = 0
+DIR_IN   = 1
+DIR_OUT  = 2
+DIR_BOTH = 3
+
 class Type(object):
     def __init__(self, typename, **kwargs):
         self.comment = kwargs.setdefault('comment', None)
         self.namespace = kwargs.setdefault('namespace', "libxl_")
+        self.dir = kwargs.setdefault('dir', DIR_BOTH)
+        if self.dir not in [DIR_NONE, DIR_IN, DIR_OUT, DIR_BOTH]:
+            raise ValueError
 
         self.passby = kwargs.setdefault('passby', PASS_BY_VALUE)
         if self.passby not in [PASS_BY_VALUE, PASS_BY_REFERENCE]:
@@ -29,6 +37,11 @@ class Type(object):
 
         self.autogenerate_destructor = 
kwargs.setdefault('autogenerate_destructor', True)
 
+    def marshal_in(self):
+        return self.dir in [DIR_IN, DIR_BOTH]
+    def marshal_out(self):
+        return self.dir in [DIR_OUT, DIR_BOTH]
+
 class Builtin(Type):
     """Builtin type"""
     def __init__(self, typename, **kwargs):
@@ -224,7 +237,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']:
+        elif n in ['PASS_BY_REFERENCE', 'PASS_BY_VALUE',
+                   'DIR_NONE', 'DIR_IN', 'DIR_OUT', 'DIR_BOTH']:
             globs[n] = t
 
     try:
diff -r 4f5a79bd1170 -r 51e2379b91a7 tools/python/genwrap.py
--- a/tools/python/genwrap.py   Mon Apr 18 14:40:15 2011 +0100
+++ b/tools/python/genwrap.py   Mon Apr 18 14:40:44 2011 +0100
@@ -42,10 +42,12 @@ def py_decls(ty):
         for f in ty.fields:
             if py_type(f.type) is not None:
                 continue
-            l.append('_hidden PyObject *attrib__%s_get(%s *%s);'%(\
-                fsanitize(f.type.typename), f.type.typename, f.name))
-            l.append('_hidden int attrib__%s_set(PyObject *v, %s *%s);'%(\
-                fsanitize(f.type.typename), f.type.typename, f.name))
+            if ty.marshal_out():
+                l.append('_hidden PyObject *attrib__%s_get(%s *%s);'%(\
+                    fsanitize(f.type.typename), f.type.typename, f.name))
+            if ty.marshal_in():
+                l.append('_hidden int attrib__%s_set(PyObject *v, %s *%s);'%(\
+                    fsanitize(f.type.typename), f.type.typename, f.name))
     return '\n'.join(l) + "\n"
 
 def py_attrib_get(ty, f):
@@ -128,8 +130,15 @@ static PyObject *Py%(rawname)s_new(PyTyp
     l.append('static PyGetSetDef Py%s_getset[] = {'%ty.rawname)
     for f in ty.fields:
         l.append('    { .name = "%s", '%f.name)
-        l.append('      .get = (getter)py_%s_%s_get, '%(ty.rawname, f.name))
-        l.append('      .set = (setter)py_%s_%s_set },'%(ty.rawname, f.name))
+        if ty.marshal_out():
+            l.append('      .get = (getter)py_%s_%s_get, '%(ty.rawname, 
f.name))
+        else:
+            l.append('      .get = (getter)NULL, ')
+        if ty.marshal_in():
+            l.append('      .set = (setter)py_%s_%s_set,'%(ty.rawname, f.name))
+        else:
+            l.append('      .set = (setter)NULL,')
+        l.append('    },')
     l.append('    { .name = NULL }')
     l.append('};')
     struct="""
@@ -289,8 +298,10 @@ _hidden int genwrap__ll_set(PyObject *v,
         if isinstance(ty, libxltypes.Aggregate):
             f.write('/* Attribute get/set functions for %s */\n'%ty.typename)
             for a in ty.fields:
-                f.write(py_attrib_get(ty,a))
-                f.write(py_attrib_set(ty,a))
+                if ty.marshal_out():
+                    f.write(py_attrib_get(ty,a))
+                if ty.marshal_in():
+                    f.write(py_attrib_set(ty,a))
             f.write(py_object_def(ty))
     f.write(py_initfuncs(types))
     f.close()

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

<Prev in Thread] Current Thread [Next in Thread>