[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] tools: libxl: add concept of in- and out-put only data types to IDL



# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1303315987 -3600
# Node ID faa31730d1c3fee5184fd26a664269737883c976
# Parent  81c5e5aa5a10a68d85d82c31315f71165c44807d
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>
Acked-by: Ian Jackson <ian.jackson.citrix.com>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
---


diff -r 81c5e5aa5a10 -r faa31730d1c3 tools/libxl/libxl.idl
--- a/tools/libxl/libxl.idl     Wed Apr 20 17:13:07 2011 +0100
+++ b/tools/libxl/libxl.idl     Wed Apr 20 17:13:07 2011 +0100
@@ -348,7 +348,7 @@
     ("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 81c5e5aa5a10 -r faa31730d1c3 tools/libxl/libxltypes.py
--- a/tools/libxl/libxltypes.py Wed Apr 20 17:13:07 2011 +0100
+++ b/tools/libxl/libxltypes.py Wed Apr 20 17:13:07 2011 +0100
@@ -3,10 +3,18 @@
 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 @@
 
         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):
@@ -214,7 +227,8 @@
             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 81c5e5aa5a10 -r faa31730d1c3 tools/python/genwrap.py
--- a/tools/python/genwrap.py   Wed Apr 20 17:13:07 2011 +0100
+++ b/tools/python/genwrap.py   Wed Apr 20 17:13:07 2011 +0100
@@ -42,10 +42,12 @@
         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 @@
     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 @@
         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-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.