aboutsummaryrefslogtreecommitdiffstats
path: root/tools/python
diff options
context:
space:
mode:
authorIan Campbell <ian.campbell@citrix.com>2011-04-20 17:13:07 +0100
committerIan Campbell <ian.campbell@citrix.com>2011-04-20 17:13:07 +0100
commit8b403a1dfdbd5bb06abbfca927097037a9ef8280 (patch)
treed0b377d65ee8923f617c7b2dd88e2d9ebf260b12 /tools/python
parent2da839263c4dd02b1433115583b8771b6d0fff36 (diff)
downloadxen-8b403a1dfdbd5bb06abbfca927097037a9ef8280.tar.gz
xen-8b403a1dfdbd5bb06abbfca927097037a9ef8280.tar.bz2
xen-8b403a1dfdbd5bb06abbfca927097037a9ef8280.zip
tools: libxl: add an Enumeration type to the IDL
The IDL requires a specific value for each enumerate, this make it much easier to avoid (or at least track) ABI changes since they must now be explicit. I believe I have used the same values as would have been chosen previoulsy but have not confirmed. 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>
Diffstat (limited to 'tools/python')
-rw-r--r--tools/python/genwrap.py53
-rw-r--r--tools/python/xen/lowlevel/xl/xl.c29
2 files changed, 32 insertions, 50 deletions
diff --git a/tools/python/genwrap.py b/tools/python/genwrap.py
index 314e39dacf..d707d4f011 100644
--- a/tools/python/genwrap.py
+++ b/tools/python/genwrap.py
@@ -9,6 +9,8 @@ import libxltypes
def py_type(ty):
if ty == libxltypes.bool or isinstance(ty, libxltypes.BitField) and ty.width == 1:
return TYPE_BOOL
+ if isinstance(ty, libxltypes.Enumeration):
+ return TYPE_UINT
if isinstance(ty, libxltypes.Number):
if ty.signed:
return TYPE_INT
@@ -34,15 +36,16 @@ def fsanitize(name):
def py_decls(ty):
l = []
- l.append('_hidden Py_%s *Py%s_New(void);\n'%(ty.rawname, ty.rawname))
- l.append('_hidden int Py%s_Check(PyObject *self);\n'%ty.rawname)
- 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 isinstance(ty, libxltypes.Aggregate):
+ l.append('_hidden Py_%s *Py%s_New(void);\n'%(ty.rawname, ty.rawname))
+ l.append('_hidden int Py%s_Check(PyObject *self);\n'%ty.rawname)
+ 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))
return '\n'.join(l) + "\n"
def py_attrib_get(ty, f):
@@ -189,16 +192,23 @@ def py_initfuncs(types):
l.append('void genwrap__init(PyObject *m)')
l.append('{')
for ty in types:
- l.append(' if (PyType_Ready(&Py%s_Type) >= 0) {'%ty.rawname)
- l.append(' Py_INCREF(&Py%s_Type);'%ty.rawname)
- l.append(' PyModule_AddObject(m, "%s", (PyObject *)&Py%s_Type);'%(ty.rawname, ty.rawname))
- l.append(' }')
+ if isinstance(ty, libxltypes.Enumeration):
+ for v in ty.values:
+ l.append(' PyModule_AddIntConstant(m, "%s", %s);' % (v.rawname, v.name))
+ elif isinstance(ty, libxltypes.Aggregate):
+ l.append(' if (PyType_Ready(&Py%s_Type) >= 0) {'%ty.rawname)
+ l.append(' Py_INCREF(&Py%s_Type);'%ty.rawname)
+ l.append(' PyModule_AddObject(m, "%s", (PyObject *)&Py%s_Type);'%(ty.rawname, ty.rawname))
+ l.append(' }')
+ else:
+ raise NotImplementedError("unknown type %s (%s)" % (ty.typename, type(ty)))
+
l.append('}')
return '\n'.join(l) + "\n\n"
def tree_frob(types):
ret = types[:]
- for ty in ret:
+ for ty in [ty for ty in ret if isinstance(ty, libxltypes.Aggregate)]:
ty.fields = filter(lambda f:f.name is not None and f.type.typename is not None, ty.fields)
return ret
@@ -249,8 +259,8 @@ _hidden PyObject *genwrap__ll_get(long long val);
_hidden int genwrap__ll_set(PyObject *v, long long *val, long long mask);
""" % " ".join(sys.argv))
- for ty in types:
- f.write('/* Internal APU for %s wrapper */\n'%ty.typename)
+ for ty in [ty for ty in types if isinstance(ty, libxltypes.Aggregate)]:
+ f.write('/* Internal API for %s wrapper */\n'%ty.typename)
f.write(py_wrapstruct(ty))
f.write(py_decls(ty))
f.write('\n')
@@ -276,10 +286,11 @@ _hidden int genwrap__ll_set(PyObject *v, long long *val, long long mask);
""" % tuple((' '.join(sys.argv),) + (os.path.split(decls)[-1:]),))
for ty in types:
- 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))
- f.write(py_object_def(ty))
+ 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))
+ f.write(py_object_def(ty))
f.write(py_initfuncs(types))
f.close()
diff --git a/tools/python/xen/lowlevel/xl/xl.c b/tools/python/xen/lowlevel/xl/xl.c
index 16a05392cc..ba8bd7c548 100644
--- a/tools/python/xen/lowlevel/xl/xl.c
+++ b/tools/python/xen/lowlevel/xl/xl.c
@@ -769,35 +769,6 @@ PyMODINIT_FUNC initxl(void)
_INT_CONST(m, SHUTDOWN_crash);
_INT_CONST(m, SHUTDOWN_watchdog);
- _INT_CONST_LIBXL(m, DOMAIN_TYPE_FV);
- _INT_CONST_LIBXL(m, DOMAIN_TYPE_PV);
-
- _INT_CONST_LIBXL(m, CONSOLE_TYPE_SERIAL);
- _INT_CONST_LIBXL(m, CONSOLE_TYPE_PV);
-
- _INT_CONST_LIBXL(m, CONSOLE_BACKEND_XENCONSOLED);
- _INT_CONST_LIBXL(m, CONSOLE_BACKEND_IOEMU);
-
- _INT_CONST_LIBXL(m, DISK_FORMAT_UNKNOWN);
- _INT_CONST_LIBXL(m, DISK_FORMAT_QCOW);
- _INT_CONST_LIBXL(m, DISK_FORMAT_QCOW2);
- _INT_CONST_LIBXL(m, DISK_FORMAT_VHD);
- _INT_CONST_LIBXL(m, DISK_FORMAT_RAW);
- _INT_CONST_LIBXL(m, DISK_FORMAT_EMPTY);
-
- _INT_CONST_LIBXL(m, DISK_BACKEND_UNKNOWN);
- _INT_CONST_LIBXL(m, DISK_BACKEND_PHY);
- _INT_CONST_LIBXL(m, DISK_BACKEND_TAP);
- _INT_CONST_LIBXL(m, DISK_BACKEND_QDISK);
-
- _INT_CONST_LIBXL(m, NIC_TYPE_IOEMU);
- _INT_CONST_LIBXL(m, NIC_TYPE_VIF);
-
- _INT_CONST_LIBXL(m, EVENT_TYPE_DOMAIN_DEATH);
- _INT_CONST_LIBXL(m, EVENT_TYPE_DISK_EJECT);
-
- _INT_CONST_LIBXL(m, BUTTON_POWER);
- _INT_CONST_LIBXL(m, BUTTON_SLEEP);
genwrap__init(m);
}