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 4 of 4] pyxl: Add _get_attribs() method to all classe

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 4 of 4] pyxl: Add _get_attribs() method to all classes
From: Gianni Tedesco <gianni.tedesco@xxxxxxxxxx>
Date: Thu, 9 Dec 2010 13:54:03 +0000
Delivery-date: Thu, 09 Dec 2010 06:06:16 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1291902839@xxxxxxxxxxxxxxxxxxxxxxx>
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.1291902839@xxxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.6.3
 tools/python/genwrap.py           |  18 ++++++++++++++++--
 tools/python/xen/lowlevel/xl/xl.c |  25 +++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 2 deletions(-)


# HG changeset patch
# User Gianni Tedesco <gianni.tedesco@xxxxxxxxxx>
# Date 1291900689 0
# Node ID 35dd6a11ce56488d01f9f1cb365e6035687390ca
# Parent  521af80c82bb6fc8e4403bbe2313b3a8b3c78841
pyxl: Add _get_attribs() method to all classes

This returns a dictionary of (attrib_name, value) tuples corresponding to all
fields of the libxl data-type that is being wrapped. This allows for creation
of super-classes of those types after they have been returned from libxl.

Signed-off-by: Gianni Tedesco <gianni.tedesco@xxxxxxxxxx>

diff -r 521af80c82bb -r 35dd6a11ce56 tools/python/genwrap.py
--- a/tools/python/genwrap.py   Thu Dec 09 13:16:19 2010 +0000
+++ b/tools/python/genwrap.py   Thu Dec 09 13:18:09 2010 +0000
@@ -127,6 +127,17 @@ static PyObject *Py%(rawname)s_new(PyTyp
     l.append('    { .name = NULL }')
     l.append('};')
     struct="""
+static PyObject *Py%s__get_attribs(PyObject *self, PyObject *args)
+{
+    return genwrap__get_attribs(self, Py%s_getset);
+}
+
+static PyMethodDef Py%s_methods[] = {
+    {"_get_attribs", (PyCFunction)Py%s__get_attribs, METH_NOARGS,
+         "Get all attributes as dictionary"},
+    {NULL, NULL, 0, NULL}
+};
+
 static PyTypeObject Py%s_Type= {
     PyObject_HEAD_INIT(NULL)
     0,
@@ -156,7 +167,7 @@ static PyTypeObject Py%s_Type= {
     0,                            /* tp_weaklistoffset */
     NULL,                         /* tp_iter           */
     NULL,                         /* tp_iternext       */
-    NULL,                         /* tp_methods        */
+    Py%s_methods,                 /* tp_methods        */
     NULL,                         /* tp_members        */
     Py%s_getset,                  /* tp_getset         */
     NULL,                         /* tp_base           */
@@ -178,7 +189,7 @@ int Py%s_Check(PyObject *self)
 {
     return (self->ob_type == &Py%s_Type);
 }
-"""%tuple(ty.rawname for x in range(15))
+"""%tuple(ty.rawname for x in range(20))
     return funcs + '\n'.join(l) + "\n" + struct
 
 def py_initfuncs(types):
@@ -237,6 +248,9 @@ _hidden void genwrap__init(PyObject *m);
 /* Generic type initialiser */
 _hidden int genwrap__obj_init(PyObject *self, PyObject *args, PyObject *kwds);
 
+/* Generic type dictionary getter */
+_hidden PyObject *genwrap__get_attribs(PyObject *self, PyGetSetDef *getsets);
+
 /* Auto-generated get/set functions for simple data-types */
 _hidden int genwrap__string_set(PyObject *v, char **str);
 _hidden PyObject *genwrap__string_get(char **str);
diff -r 521af80c82bb -r 35dd6a11ce56 tools/python/xen/lowlevel/xl/xl.c
--- a/tools/python/xen/lowlevel/xl/xl.c Thu Dec 09 13:16:19 2010 +0000
+++ b/tools/python/xen/lowlevel/xl/xl.c Thu Dec 09 13:18:09 2010 +0000
@@ -57,6 +57,31 @@
 
 static PyObject *xl_error_obj;
 
+PyObject *genwrap__get_attribs(PyObject *self, PyGetSetDef *getsets)
+{
+    PyObject *dict;
+    PyGetSetDef *cur;
+
+    dict = PyDict_New();
+    if ( NULL == dict ) {
+        PyErr_SetString(PyExc_MemoryError, "Allocating dictionary");
+        return NULL;
+    }
+
+    for(cur = getsets; cur->name; cur++) {
+        PyObject *tmp;
+        tmp = (*cur->get)(self, cur->closure);
+        if ( NULL == tmp ) {
+            Py_DECREF(dict);
+            return NULL;
+        }
+        PyDict_SetItemString(dict, cur->name, tmp);
+        Py_DECREF(tmp);
+    }
+
+    return dict;
+}
+
 int genwrap__obj_init(PyObject *self, PyObject *args, PyObject *kwds)
 {
     PyObject *key, *value;

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