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-changelog

[Xen-changelog] As with xs.c, change the module interface to match the c

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] As with xs.c, change the module interface to match the current Python/C
From: Xen patchbot -unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Mon, 21 Nov 2005 22:48:10 +0000
Delivery-date: Mon, 21 Nov 2005 22:48:55 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID 87b520c30cb250b737e30a7bad98ed40be38acae
# Parent  52f80621b8899b2c464135ba14f70aff434e2470
As with xs.c, change the module interface to match the current Python/C
tutorial, simplifying the interface here, and making it more conventional.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>

diff -r 52f80621b889 -r 87b520c30cb2 tools/python/xen/lowlevel/xc/xc.c
--- a/tools/python/xen/lowlevel/xc/xc.c Mon Nov 21 17:34:25 2005
+++ b/tools/python/xen/lowlevel/xc/xc.c Mon Nov 21 17:46:09 2005
@@ -23,7 +23,8 @@
 #define PyMODINIT_FUNC DL_EXPORT(void)
 #endif
 
-#define XENPKG "xen.lowlevel.xc"
+#define PKG "xen.lowlevel.xc"
+#define CLS "xc"
 
 static PyObject *xc_error, *zero;
 
@@ -1055,81 +1056,109 @@
 };
 
 
-/*
- * Definitions for the 'Xc' module wrapper.
- */
-
-staticforward PyTypeObject PyXcType;
-
-static PyObject *PyXc_new(PyObject *self, PyObject *args)
-{
-    XcObject *xc;
-
-    if ( !PyArg_ParseTuple(args, ":new") )
-        return NULL;
-
-    xc = PyObject_New(XcObject, &PyXcType);
-
-    if ( (xc->xc_handle = xc_interface_open()) == -1 )
-    {
-        PyObject_Del((PyObject *)xc);
-        return PyErr_SetFromErrno(xc_error);
+static PyObject *PyXc_getattr(PyObject *obj, char *name)
+{
+    return Py_FindMethod(pyxc_methods, obj, name);
+}
+
+static PyObject *PyXc_new(PyTypeObject *type, PyObject *args)
+{
+    XcObject *self = (XcObject *)type->tp_alloc(type, 0);
+
+    if (self == NULL)
+        return NULL;
+
+    self->xc_handle = NULL;
+
+    return (PyObject *)self;
+}
+
+static int
+PyXc_init(XcObject *self, PyObject *args, PyObject *kwds)
+{
+    if ((self->xc_handle = xc_interface_open()) == -1) {
+        PyErr_SetFromErrno(PyExc_RuntimeError);
+        return -1;
     }
 
-    return (PyObject *)xc;
-}
-
-static PyObject *PyXc_getattr(PyObject *obj, char *name)
-{
-    return Py_FindMethod(pyxc_methods, obj, name);
-}
-
-static void PyXc_dealloc(PyObject *self)
-{
-    XcObject *xc = (XcObject *)self;
-    (void)xc_interface_close(xc->xc_handle);
-    PyObject_Del(self);
+    return 0;
+}
+
+static void PyXc_dealloc(XcObject *self)
+{
+    if (self->xc_handle) {
+        xc_interface_close(self->xc_handle);
+        self->xc_handle = NULL;
+    }
+
+    self->ob_type->tp_free((PyObject *)self);
 }
 
 static PyTypeObject PyXcType = {
-    PyObject_HEAD_INIT(&PyType_Type)
+    PyObject_HEAD_INIT(NULL)
     0,
-    "Xc",
+    PKG "." CLS,
     sizeof(XcObject),
     0,
-    PyXc_dealloc,    /* tp_dealloc     */
-    NULL,            /* tp_print       */
-    PyXc_getattr,    /* tp_getattr     */
-    NULL,            /* tp_setattr     */
-    NULL,            /* tp_compare     */
-    NULL,            /* tp_repr        */
-    NULL,            /* tp_as_number   */
-    NULL,            /* tp_as_sequence */
-    NULL,            /* tp_as_mapping  */
-    NULL             /* tp_hash        */
+    (destructor)PyXc_dealloc,     /* tp_dealloc        */
+    NULL,                         /* tp_print          */
+    PyXc_getattr,                 /* tp_getattr        */
+    NULL,                         /* tp_setattr        */
+    NULL,                         /* tp_compare        */
+    NULL,                         /* tp_repr           */
+    NULL,                         /* tp_as_number      */
+    NULL,                         /* tp_as_sequence    */
+    NULL,                         /* tp_as_mapping     */
+    NULL,                         /* tp_hash           */
+    NULL,                         /* tp_call           */
+    NULL,                         /* tp_str            */
+    NULL,                         /* tp_getattro       */
+    NULL,                         /* tp_setattro       */
+    NULL,                         /* tp_as_buffer      */
+    Py_TPFLAGS_DEFAULT,           /* tp_flags          */
+    "Xen client connections",     /* tp_doc            */
+    NULL,                         /* tp_traverse       */
+    NULL,                         /* tp_clear          */
+    NULL,                         /* tp_richcompare    */
+    0,                            /* tp_weaklistoffset */
+    NULL,                         /* tp_iter           */
+    NULL,                         /* tp_iternext       */
+    pyxc_methods,                 /* tp_methods        */
+    NULL,                         /* tp_members        */
+    NULL,                         /* tp_getset         */
+    NULL,                         /* tp_base           */
+    NULL,                         /* tp_dict           */
+    NULL,                         /* tp_descr_get      */
+    NULL,                         /* tp_descr_set      */
+    0,                            /* tp_dictoffset     */
+    (initproc)PyXc_init,          /* tp_init           */
+    NULL,                         /* tp_alloc          */
+    PyXc_new,                     /* tp_new            */
 };
 
-static PyMethodDef PyXc_methods[] = {
-    { "new", PyXc_new, METH_VARARGS, "Create a new " XENPKG " object." },
-    { NULL, NULL, 0, NULL }
-};
+static PyMethodDef xc_methods[] = { { NULL } };
 
 PyMODINIT_FUNC initxc(void)
 {
-    PyObject *m, *d;
-
-    m = Py_InitModule(XENPKG, PyXc_methods);
-
-    d = PyModule_GetDict(m);
-    xc_error = PyErr_NewException(XENPKG ".error", NULL, NULL);
-    PyDict_SetItemString(d, "error", xc_error);
-    PyDict_SetItemString(d, "VIRQ_DOM_EXC", PyInt_FromLong(VIRQ_DOM_EXC));
-
+    PyObject *m;
+
+    if (PyType_Ready(&PyXcType) < 0)
+        return;
+
+    m = Py_InitModule(PKG, PyXc_methods);
+
+    if (m == NULL)
+      return;
+
+    xc_error = PyErr_NewException(PKG ".error", NULL, NULL);
     zero = PyInt_FromLong(0);
 
     /* KAF: This ensures that we get debug output in a timely manner. */
     setbuf(stdout, NULL);
     setbuf(stderr, NULL);
+
+    Py_INCREF(&PyXcType);
+    PyModule_AddObject(m, CLS, (PyObject *)&PyXcType);
 }
 
 
diff -r 52f80621b889 -r 87b520c30cb2 tools/python/xen/xend/XendCheckpoint.py
--- a/tools/python/xen/xend/XendCheckpoint.py   Mon Nov 21 17:34:25 2005
+++ b/tools/python/xen/xend/XendCheckpoint.py   Mon Nov 21 17:46:09 2005
@@ -33,7 +33,7 @@
 sizeof_unsigned_long = calcsize("L")
 
 
-xc = xen.lowlevel.xc.new()
+xc = xen.lowlevel.xc.xc()
 
 
 def write_exact(fd, buf, errmsg):
diff -r 52f80621b889 -r 87b520c30cb2 tools/python/xen/xend/XendDmesg.py
--- a/tools/python/xen/xend/XendDmesg.py        Mon Nov 21 17:34:25 2005
+++ b/tools/python/xen/xend/XendDmesg.py        Mon Nov 21 17:46:09 2005
@@ -22,7 +22,7 @@
 
 class XendDmesg:
     def __init__(self):
-        self.xc = xen.lowlevel.xc.new()
+        self.xc = xen.lowlevel.xc.xc()
 
     def info(self):
         return self.xc.readconsolering()
diff -r 52f80621b889 -r 87b520c30cb2 tools/python/xen/xend/XendDomain.py
--- a/tools/python/xen/xend/XendDomain.py       Mon Nov 21 17:34:25 2005
+++ b/tools/python/xen/xend/XendDomain.py       Mon Nov 21 17:46:09 2005
@@ -39,7 +39,7 @@
 from xen.xend.xenstore.xswatch import xswatch
 
 
-xc = xen.lowlevel.xc.new()
+xc = xen.lowlevel.xc.xc()
 xroot = XendRoot.instance()
 
 
@@ -201,7 +201,7 @@
                             "%d.  Destroying it in the hope of "
                             "recovery.", d)
                         try:
-                            xc.domain_destroy(dom = d)
+                            xc.domain_destroy(d)
                         except:
                             log.exception('Destruction of %d failed.', d)
 
@@ -378,7 +378,7 @@
             val = dominfo.destroy()
         else:
             try:
-                val = xc.domain_destroy(dom=domid)
+                val = xc.domain_destroy(domid)
             except Exception, ex:
                 raise XendError(str(ex))
         return val       
diff -r 52f80621b889 -r 87b520c30cb2 tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py   Mon Nov 21 17:34:25 2005
+++ b/tools/python/xen/xend/XendDomainInfo.py   Mon Nov 21 17:46:09 2005
@@ -93,7 +93,7 @@
 RESTART_IN_PROGRESS = 'xend/restart_in_progress'
 
 
-xc = xen.lowlevel.xc.new()
+xc = xen.lowlevel.xc.xc()
 xroot = XendRoot.instance()
 
 log = logging.getLogger("xend.XendDomainInfo")
diff -r 52f80621b889 -r 87b520c30cb2 tools/python/xen/xend/XendNode.py
--- a/tools/python/xen/xend/XendNode.py Mon Nov 21 17:34:25 2005
+++ b/tools/python/xen/xend/XendNode.py Mon Nov 21 17:46:09 2005
@@ -28,7 +28,7 @@
 class XendNode:
 
     def __init__(self):
-        self.xc = xen.lowlevel.xc.new()
+        self.xc = xen.lowlevel.xc.xc()
 
     def shutdown(self):
         return 0
@@ -40,7 +40,7 @@
         return 0
     
     def cpu_bvt_slice_set(self, ctx_allow):
-        return self.xc.bvtsched_global_set(ctx_allow=ctx_allow)
+        return self.xc.bvtsched_global_set(ctx_allow)
 
     def cpu_bvt_slice_get(self):
         return self.xc.bvtsched_global_get()
diff -r 52f80621b889 -r 87b520c30cb2 tools/python/xen/xend/image.py
--- a/tools/python/xen/xend/image.py    Mon Nov 21 17:34:25 2005
+++ b/tools/python/xen/xend/image.py    Mon Nov 21 17:46:09 2005
@@ -27,7 +27,7 @@
 from xen.xend.server.netif import randomMAC
 
 
-xc = xen.lowlevel.xc.new()
+xc = xen.lowlevel.xc.xc()
 
 
 MAX_GUEST_CMDLINE = 1024
diff -r 52f80621b889 -r 87b520c30cb2 tools/python/xen/xend/server/SrvDaemon.py
--- a/tools/python/xen/xend/server/SrvDaemon.py Mon Nov 21 17:34:25 2005
+++ b/tools/python/xen/xend/server/SrvDaemon.py Mon Nov 21 17:46:09 2005
@@ -267,7 +267,7 @@
         try:
             log.info("Xend Daemon started")
 
-            xc = xen.lowlevel.xc.new()
+            xc = xen.lowlevel.xc.xc()
             xinfo = xc.xeninfo()
             log.info("Xend changeset: %s.", xinfo['xen_changeset'])
             del xc
diff -r 52f80621b889 -r 87b520c30cb2 tools/python/xen/xend/server/iopif.py
--- a/tools/python/xen/xend/server/iopif.py     Mon Nov 21 17:34:25 2005
+++ b/tools/python/xen/xend/server/iopif.py     Mon Nov 21 17:46:09 2005
@@ -28,7 +28,7 @@
 from xen.xend.server.DevController import DevController
 
 
-xc = xen.lowlevel.xc.new()
+xc = xen.lowlevel.xc.xc()
 
 
 def parse_ioport(val):
diff -r 52f80621b889 -r 87b520c30cb2 tools/python/xen/xend/server/pciif.py
--- a/tools/python/xen/xend/server/pciif.py     Mon Nov 21 17:34:25 2005
+++ b/tools/python/xen/xend/server/pciif.py     Mon Nov 21 17:46:09 2005
@@ -27,7 +27,7 @@
 from xen.xend.server.DevController import DevController
 
 
-xc = xen.lowlevel.xc.new()
+xc = xen.lowlevel.xc.xc()
 
 
 def parse_pci(val):
diff -r 52f80621b889 -r 87b520c30cb2 tools/python/xen/xm/create.py
--- a/tools/python/xen/xm/create.py     Mon Nov 21 17:34:25 2005
+++ b/tools/python/xen/xm/create.py     Mon Nov 21 17:46:09 2005
@@ -849,7 +849,7 @@
     timeout = 20 # 2s
     ret = 1
 
-    xc = xen.lowlevel.xc.new()
+    xc = xen.lowlevel.xc.xc()
     free_mem = xc.physinfo()['free_pages'] / 256
     domU_need_mem = opts.vals.memory + SLACK 
 

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] As with xs.c, change the module interface to match the current Python/C, Xen patchbot -unstable <=