]> xenbits.xensource.com Git - xen.git/commitdiff
tools: libxl: add concept of in- and out-put only data types to IDL
authorIan Campbell <ian.campbell@citrix.com>
Wed, 20 Apr 2011 16:13:07 +0000 (17:13 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Wed, 20 Apr 2011 16:13:07 +0000 (17:13 +0100)
This allow language bindings to only emit the relevant conversion functions.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson.citrix.com>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
tools/libxl/libxl.idl
tools/libxl/libxltypes.py
tools/python/genwrap.py

index bb85f61ad2e9c799dec559b331627451d8512885..ac240a50890c40d24272d8ee74078ee158482f44 100644 (file)
@@ -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"),
index 8f0b516889b9b2539c647653557fd7836268cc94..133d67a6c4e9c51e18efa3e389e4ee1257741375 100644 (file)
@@ -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):
@@ -214,7 +227,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:
index ed92b35b7bc1081acdaaa834fc797407e42305af..af8d6465ffb4084a5fde312cfc476f088426a110 100644 (file)
@@ -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(PyTypeObject *type, PyObject *args, PyObject
     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, long long *val, long long mask);
         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()