From ba67cc7a7b5e69b2a39a4aab5805e7915152db16 Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado Gomez" Date: Thu, 28 Apr 2022 15:46:15 +0200 Subject: Use c99 struct initialization Declutters PyTypeObject struct initialization when declaring new types. --- context.c | 48 +++++++++++------------------------------------- label.c | 48 +++++++++++------------------------------------- partition.c | 49 ++++++++++++------------------------------------- 3 files changed, 34 insertions(+), 111 deletions(-) diff --git a/context.c b/context.c index 6841a4f..0d3e646 100644 --- a/context.c +++ b/context.c @@ -200,43 +200,17 @@ static PyObject *Context_repr(ContextObject *self) PyTypeObject ContextType = { PyVarObject_HEAD_INIT(NULL, 0) - "libfdisk.Context", /*tp_name*/ - sizeof(ContextObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - (destructor)Context_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - NULL, /*tp_getattr*/ - NULL, /*tp_setattr*/ - NULL, /*tp_compare*/ - (reprfunc) Context_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 | Py_TPFLAGS_BASETYPE, /*tp_flags*/ - Context_HELP, /* tp_doc */ - NULL, /* tp_traverse */ - NULL, /* tp_clear */ - NULL, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - NULL, /* tp_iter */ - NULL, /* tp_iternext */ - Context_methods, /* tp_methods */ - Context_members, /* tp_members */ - Context_getseters, /* tp_getset */ - NULL, /* tp_base */ - NULL, /* tp_dict */ - NULL, /* tp_descr_get */ - NULL, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)Context_init, /* tp_init */ - NULL, /* tp_alloc */ - Context_new, /* tp_new */ + .tp_name = "libfdisk.Context", + .tp_basicsize = sizeof(ContextObject), + .tp_dealloc = (destructor)Context_dealloc, + .tp_repr = (reprfunc) Context_repr, + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + .tp_doc = Context_HELP, + .tp_methods = Context_methods, + .tp_members = Context_members, + .tp_getset = Context_getseters, + .tp_init = (initproc)Context_init, + .tp_new = Context_new, }; void Context_AddModuleObject(PyObject *mod) diff --git a/label.c b/label.c index f205d36..626ca5f 100644 --- a/label.c +++ b/label.c @@ -88,43 +88,17 @@ static PyObject *Label_repr(LabelObject *self) PyTypeObject LabelType = { PyVarObject_HEAD_INIT(NULL, 0) - "libfdisk.Label", /*tp_name*/ - sizeof(LabelObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - (destructor)Label_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - NULL, /*tp_getattr*/ - NULL, /*tp_setattr*/ - NULL, /*tp_compare*/ - (reprfunc) Label_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 | Py_TPFLAGS_BASETYPE, /*tp_flags*/ - Label_HELP, /* tp_doc */ - NULL, /* tp_traverse */ - NULL, /* tp_clear */ - NULL, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - NULL, /* tp_iter */ - NULL, /* tp_iternext */ - Label_methods, /* tp_methods */ - Label_members, /* tp_members */ - Label_getseters, /* tp_getset */ - NULL, /* tp_base */ - NULL, /* tp_dict */ - NULL, /* tp_descr_get */ - NULL, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)Label_init, /* tp_init */ - NULL, /* tp_alloc */ - Label_new, /* tp_new */ + .tp_name = "libfdisk.Label", + .tp_basicsize = sizeof(LabelObject), + .tp_dealloc = (destructor)Label_dealloc, + .tp_repr = (reprfunc) Label_repr, + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + .tp_doc = Label_HELP, + .tp_methods = Label_methods, + .tp_members = Label_members, + .tp_getset = Label_getseters, + .tp_init = (initproc)Label_init, + .tp_new = Label_new, }; PyObject *PyObjectResultLabel(struct fdisk_label *lb) diff --git a/partition.c b/partition.c index a72d3ff..f1cc5e3 100644 --- a/partition.c +++ b/partition.c @@ -94,43 +94,18 @@ static PyObject *Partition_repr(PartitionObject *self) PyTypeObject PartitionType = { PyVarObject_HEAD_INIT(NULL, 0) - "libfdisk.Partition", /*tp_name*/ - sizeof(PartitionObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - (destructor)Partition_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - NULL, /*tp_getattr*/ - NULL, /*tp_setattr*/ - NULL, /*tp_compare*/ - (reprfunc) Partition_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 | Py_TPFLAGS_BASETYPE, /*tp_flags*/ - Partition_HELP, /* tp_doc */ - NULL, /* tp_traverse */ - NULL, /* tp_clear */ - NULL, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - NULL, /* tp_iter */ - NULL, /* tp_iternext */ - Partition_methods, /* tp_methods */ - Partition_members, /* tp_members */ - Partition_getseters, /* tp_getset */ - NULL, /* tp_base */ - NULL, /* tp_dict */ - NULL, /* tp_descr_get */ - NULL, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)Partition_init, /* tp_init */ - NULL, /* tp_alloc */ - Partition_new, /* tp_new */ + .tp_name = "libfdisk.Partition", + .tp_basicsize = sizeof(PartitionObject), + .tp_itemsize = 0, + .tp_dealloc = (destructor)Partition_dealloc, + .tp_repr = (reprfunc) Partition_repr, + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + .tp_doc = PyDoc_STR(Partition_HELP), + .tp_methods = Partition_methods, + .tp_members = Partition_members, + .tp_getset = Partition_getseters, + .tp_init = (initproc)Partition_init, + .tp_new = Partition_new, }; PyObject *PyObjectResultPartition(struct fdisk_partition *pa) -- cgit v1.2.3-18-g5258