Use c99 struct initialization

Declutters PyTypeObject struct initialization when declaring new types.
master
Jose M. Guisado Gomez 2022-04-28 15:46:15 +02:00
parent c5ae6a3967
commit ba67cc7a7b
3 changed files with 34 additions and 111 deletions

View File

@ -200,43 +200,17 @@ static PyObject *Context_repr(ContextObject *self)
PyTypeObject ContextType = { PyTypeObject ContextType = {
PyVarObject_HEAD_INIT(NULL, 0) PyVarObject_HEAD_INIT(NULL, 0)
"libfdisk.Context", /*tp_name*/ .tp_name = "libfdisk.Context",
sizeof(ContextObject), /*tp_basicsize*/ .tp_basicsize = sizeof(ContextObject),
0, /*tp_itemsize*/ .tp_dealloc = (destructor)Context_dealloc,
(destructor)Context_dealloc, /*tp_dealloc*/ .tp_repr = (reprfunc) Context_repr,
0, /*tp_print*/ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
NULL, /*tp_getattr*/ .tp_doc = Context_HELP,
NULL, /*tp_setattr*/ .tp_methods = Context_methods,
NULL, /*tp_compare*/ .tp_members = Context_members,
(reprfunc) Context_repr, .tp_getset = Context_getseters,
NULL, /*tp_as_number*/ .tp_init = (initproc)Context_init,
NULL, /*tp_as_sequence*/ .tp_new = Context_new,
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 */
}; };
void Context_AddModuleObject(PyObject *mod) void Context_AddModuleObject(PyObject *mod)

48
label.c
View File

@ -88,43 +88,17 @@ static PyObject *Label_repr(LabelObject *self)
PyTypeObject LabelType = { PyTypeObject LabelType = {
PyVarObject_HEAD_INIT(NULL, 0) PyVarObject_HEAD_INIT(NULL, 0)
"libfdisk.Label", /*tp_name*/ .tp_name = "libfdisk.Label",
sizeof(LabelObject), /*tp_basicsize*/ .tp_basicsize = sizeof(LabelObject),
0, /*tp_itemsize*/ .tp_dealloc = (destructor)Label_dealloc,
(destructor)Label_dealloc, /*tp_dealloc*/ .tp_repr = (reprfunc) Label_repr,
0, /*tp_print*/ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
NULL, /*tp_getattr*/ .tp_doc = Label_HELP,
NULL, /*tp_setattr*/ .tp_methods = Label_methods,
NULL, /*tp_compare*/ .tp_members = Label_members,
(reprfunc) Label_repr, .tp_getset = Label_getseters,
NULL, /*tp_as_number*/ .tp_init = (initproc)Label_init,
NULL, /*tp_as_sequence*/ .tp_new = Label_new,
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 */
}; };
PyObject *PyObjectResultLabel(struct fdisk_label *lb) PyObject *PyObjectResultLabel(struct fdisk_label *lb)

View File

@ -94,43 +94,18 @@ static PyObject *Partition_repr(PartitionObject *self)
PyTypeObject PartitionType = { PyTypeObject PartitionType = {
PyVarObject_HEAD_INIT(NULL, 0) PyVarObject_HEAD_INIT(NULL, 0)
"libfdisk.Partition", /*tp_name*/ .tp_name = "libfdisk.Partition",
sizeof(PartitionObject), /*tp_basicsize*/ .tp_basicsize = sizeof(PartitionObject),
0, /*tp_itemsize*/ .tp_itemsize = 0,
(destructor)Partition_dealloc, /*tp_dealloc*/ .tp_dealloc = (destructor)Partition_dealloc,
0, /*tp_print*/ .tp_repr = (reprfunc) Partition_repr,
NULL, /*tp_getattr*/ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
NULL, /*tp_setattr*/ .tp_doc = PyDoc_STR(Partition_HELP),
NULL, /*tp_compare*/ .tp_methods = Partition_methods,
(reprfunc) Partition_repr, .tp_members = Partition_members,
NULL, /*tp_as_number*/ .tp_getset = Partition_getseters,
NULL, /*tp_as_sequence*/ .tp_init = (initproc)Partition_init,
NULL, /*tp_as_mapping*/ .tp_new = Partition_new,
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 */
}; };
PyObject *PyObjectResultPartition(struct fdisk_partition *pa) PyObject *PyObjectResultPartition(struct fdisk_partition *pa)