python: initialize specific fields of PyTypeObject
authorMarek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Thu, 23 Feb 2017 10:48:24 +0000 (11:48 +0100)
committerWei Liu <wei.liu2@citrix.com>
Thu, 23 Feb 2017 13:11:12 +0000 (13:11 +0000)
Fields not named here will be zero-initialized anyway, but using this
way will be much easier to support both Python2 and Python3.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
tools/python/xen/lowlevel/xc/xc.c
tools/python/xen/lowlevel/xs/xs.c

index 5d21c38879d65f939107bc30ee867b7915a051ec..ddd18d44ef0dd4f8c60ea83d6c4c6518db4434fc 100644 (file)
@@ -2675,44 +2675,15 @@ static void PyXc_dealloc(XcObject *self)
 
 static PyTypeObject PyXcType = {
     PyObject_HEAD_INIT(NULL)
-    0,
-    PKG "." CLS,
-    sizeof(XcObject),
-    0,
-    (destructor)PyXc_dealloc,     /* tp_dealloc        */
-    NULL,                         /* tp_print          */
-    NULL,                         /* 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            */
+    .tp_name = PKG "." CLS,
+    .tp_basicsize = sizeof(XcObject),
+    .tp_itemsize = 0,
+    .tp_dealloc = (destructor)PyXc_dealloc,
+    .tp_flags = Py_TPFLAGS_DEFAULT,
+    .tp_doc = "Xen client connections",
+    .tp_methods = pyxc_methods,
+    .tp_init = (initproc)PyXc_init,
+    .tp_new = PyXc_new,
 };
 
 static PyMethodDef xc_methods[] = { { NULL } };
index 74a80cade7aa87cb99020e785cb2cfc5c5f1c510..66ab08d4e6b53ab5490e3b7866aeb7972c19ec24 100644 (file)
@@ -927,44 +927,15 @@ static void xshandle_dealloc(XsHandle *self)
 
 static PyTypeObject xshandle_type = {
     PyObject_HEAD_INIT(NULL)
-    0,
-    PKG "." CLS,
-    sizeof(XsHandle),
-    0,
-    (destructor)xshandle_dealloc, /* tp_dealloc        */
-    NULL,                         /* tp_print          */
-    NULL,                         /* 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          */
-    "Xenstore connections",       /* tp_doc            */
-    NULL,                         /* tp_traverse       */
-    NULL,                         /* tp_clear          */
-    NULL,                         /* tp_richcompare    */
-    0,                            /* tp_weaklistoffset */
-    NULL,                         /* tp_iter           */
-    NULL,                         /* tp_iternext       */
-    xshandle_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)xshandle_init,      /* tp_init           */
-    NULL,                         /* tp_alloc          */
-    xshandle_new,                 /* tp_new            */
+    .tp_name = PKG "." CLS,
+    .tp_basicsize = sizeof(XsHandle),
+    .tp_itemsize = 0,
+    .tp_dealloc = (destructor)xshandle_dealloc,
+    .tp_flags = Py_TPFLAGS_DEFAULT,
+    .tp_doc = "Xenstore connections",
+    .tp_methods = xshandle_methods,
+    .tp_init = (initproc)xshandle_init,
+    .tp_new = xshandle_new,
 };
 
 static PyMethodDef xs_methods[] = { { NULL } };