coding style: line breaks

Only two line breaks separate copyright notice from source.

For the rest of the source file any function declaration or similar
block is separated with a line break from any other block.
Except when a python function definition is previously followed by
a docstring #define block.
master
Jose M. Guisado 2022-12-15 13:12:32 +01:00
parent eaf98290cf
commit 975acaf549
5 changed files with 26 additions and 11 deletions

View File

@ -16,7 +16,6 @@ static PyMemberDef Context_members[] = {
{ NULL } { NULL }
}; };
static void Context_dealloc(ContextObject *self) static void Context_dealloc(ContextObject *self)
{ {
if (!self->cxt) /* if init fails */ if (!self->cxt) /* if init fails */
@ -77,7 +76,6 @@ static int Context_init(ContextObject *self, PyObject *args, PyObject *kwds)
return 0; return 0;
} }
#define Context_assign_device_HELP "assign_device(device)\n\n" \ #define Context_assign_device_HELP "assign_device(device)\n\n" \
"Open the device, discovery topology, geometry, detect disklabel " \ "Open the device, discovery topology, geometry, detect disklabel " \
"and switch the current label driver to reflect the probing result. " "and switch the current label driver to reflect the probing result. "
@ -102,6 +100,7 @@ static PyObject *Context_assign_device(ContextObject *self, PyObject *args, PyOb
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
#define Context_partition_to_string_HELP "partition_to_string(pa, field)\n\n" \ #define Context_partition_to_string_HELP "partition_to_string(pa, field)\n\n" \
"Retrieve partition field using fdisk_partition_to_string." \ "Retrieve partition field using fdisk_partition_to_string." \
"Field constants are available as FDISK_LABEL_*" "Field constants are available as FDISK_LABEL_*"
@ -126,6 +125,7 @@ static PyObject *Context_partition_to_string(ContextObject *self, PyObject *args
return ret; return ret;
} }
#define Context_create_disklabel_HELP "create_disklabel(label)\n\n" \ #define Context_create_disklabel_HELP "create_disklabel(label)\n\n" \
"Creates a new disk label of type name . If name is NULL, " \ "Creates a new disk label of type name . If name is NULL, " \
"then it will create a default system label type, either SUN or DOS." "then it will create a default system label type, either SUN or DOS."
@ -145,6 +145,7 @@ static PyObject *Context_create_disklabel(ContextObject *self, PyObject *args, P
Py_RETURN_NONE; Py_RETURN_NONE;
} }
#define Context_write_disklabel_HELP "write_disklabel()\n\n" \ #define Context_write_disklabel_HELP "write_disklabel()\n\n" \
"This function wipes the device (if enabled by fdisk_enable_wipe()) " \ "This function wipes the device (if enabled by fdisk_enable_wipe()) " \
"and then it writes in-memory changes to disk. Be careful!" "and then it writes in-memory changes to disk. Be careful!"
@ -160,6 +161,7 @@ static PyObject *Context_write_disklabel(ContextObject *self, PyObject *args, Py
Py_RETURN_NONE; Py_RETURN_NONE;
} }
#define Context_add_partition_HELP "add_partition(fdisk.Partition)\n\n" \ #define Context_add_partition_HELP "add_partition(fdisk.Partition)\n\n" \
"Adds partition to context. Returns partno of the new partition." "Adds partition to context. Returns partno of the new partition."
static PyObject *Context_add_partition(ContextObject *self, PyObject *args, PyObject *kwds) static PyObject *Context_add_partition(ContextObject *self, PyObject *args, PyObject *kwds)
@ -186,6 +188,7 @@ static PyObject *Context_add_partition(ContextObject *self, PyObject *args, PyOb
return Py_BuildValue("n", partno); return Py_BuildValue("n", partno);
} }
static PyMethodDef Context_methods[] = { static PyMethodDef Context_methods[] = {
{"assign_device", (PyCFunction)Context_assign_device, METH_VARARGS, Context_assign_device_HELP}, {"assign_device", (PyCFunction)Context_assign_device, METH_VARARGS, Context_assign_device_HELP},
{"partition_to_string", (PyCFunction)Context_partition_to_string, METH_VARARGS, Context_partition_to_string_HELP}, {"partition_to_string", (PyCFunction)Context_partition_to_string, METH_VARARGS, Context_partition_to_string_HELP},
@ -195,19 +198,21 @@ static PyMethodDef Context_methods[] = {
{NULL} {NULL}
}; };
static PyObject *Context_get_nsectors(ContextObject *self) static PyObject *Context_get_nsectors(ContextObject *self)
{ {
return PyLong_FromUnsignedLong(fdisk_get_nsectors(self->cxt)); return PyLong_FromUnsignedLong(fdisk_get_nsectors(self->cxt));
} }
static PyObject *Context_get_sector_size(ContextObject *self) static PyObject *Context_get_sector_size(ContextObject *self)
{ {
return PyLong_FromUnsignedLong(fdisk_get_sector_size(self->cxt)); return PyLong_FromUnsignedLong(fdisk_get_sector_size(self->cxt));
} }
static PyObject *Context_get_devname(ContextObject *self) static PyObject *Context_get_devname(ContextObject *self)
{ {
return PyObjectResultStr(fdisk_get_devname(self->cxt)); return PyObjectResultStr(fdisk_get_devname(self->cxt));
} }
static PyObject *Context_get_label(ContextObject *self) static PyObject *Context_get_label(ContextObject *self)
{ {
struct fdisk_context *cxt = self->cxt; struct fdisk_context *cxt = self->cxt;
@ -218,10 +223,12 @@ static PyObject *Context_get_label(ContextObject *self)
Py_RETURN_NONE; Py_RETURN_NONE;
} }
} }
static PyObject *Context_get_nparts(ContextObject *self) static PyObject *Context_get_nparts(ContextObject *self)
{ {
return PyLong_FromLong(fdisk_table_get_nents(self->tb)); return PyLong_FromLong(fdisk_table_get_nents(self->tb));
} }
static PyObject *Context_get_partitions(ContextObject *self) static PyObject *Context_get_partitions(ContextObject *self)
{ {
PyObject *p, *list = PyList_New(0); /* XXX: null if failed*/ PyObject *p, *list = PyList_New(0); /* XXX: null if failed*/
@ -244,10 +251,12 @@ static PyObject *Context_get_partitions(ContextObject *self)
return list; return list;
} }
static PyObject *Context_get_size_unit(ContextObject *self) static PyObject *Context_get_size_unit(ContextObject *self)
{ {
return PyLong_FromLong(fdisk_get_size_unit(self->cxt)); return PyLong_FromLong(fdisk_get_size_unit(self->cxt));
} }
static int Context_set_size_unit(ContextObject *self, PyObject *value, void *closure) static int Context_set_size_unit(ContextObject *self, PyObject *value, void *closure)
{ {
int szunit; int szunit;
@ -273,6 +282,7 @@ static int Context_set_size_unit(ContextObject *self, PyObject *value, void *clo
return 0; return 0;
} }
static PyGetSetDef Context_getseters[] = { static PyGetSetDef Context_getseters[] = {
{"nsectors", (getter)Context_get_nsectors, NULL, "context number of sectors", NULL}, {"nsectors", (getter)Context_get_nsectors, NULL, "context number of sectors", NULL},
{"sector_size", (getter)Context_get_sector_size, NULL, "context sector size", NULL}, {"sector_size", (getter)Context_get_sector_size, NULL, "context sector size", NULL},

View File

@ -34,7 +34,6 @@ static PyMethodDef FdiskMethods[] = {
{NULL, NULL, 0, NULL} /* Sentinel */ {NULL, NULL, 0, NULL} /* Sentinel */
}; };
static struct PyModuleDef fdiskmodule = { static struct PyModuleDef fdiskmodule = {
PyModuleDef_HEAD_INIT, PyModuleDef_HEAD_INIT,
"fdisk", /* name of module */ "fdisk", /* name of module */

View File

@ -12,12 +12,10 @@
#include "fdisk.h" #include "fdisk.h"
static PyMemberDef Label_members[] = { static PyMemberDef Label_members[] = {
{ NULL } { NULL }
}; };
static void Label_dealloc(LabelObject *self) static void Label_dealloc(LabelObject *self)
{ {
Py_TYPE(self)->tp_free((PyObject *) self); Py_TYPE(self)->tp_free((PyObject *) self);
@ -80,6 +78,7 @@ static PyObject *Label_get_parttype_from_code(LabelObject *self, PyObject *args,
return PyObjectResultPartType(ptype); return PyObjectResultPartType(ptype);
} }
#define Label_get_parttype_from_string_HELP "get_parttype_from_string(uuid)\n\n" \ #define Label_get_parttype_from_string_HELP "get_parttype_from_string(uuid)\n\n" \
"Search by string for partition type in label-specific table." "Search by string for partition type in label-specific table."
static PyObject *Label_get_parttype_from_string(LabelObject *self, PyObject *args, PyObject *kwds) static PyObject *Label_get_parttype_from_string(LabelObject *self, PyObject *args, PyObject *kwds)
@ -100,21 +99,23 @@ static PyObject *Label_get_parttype_from_string(LabelObject *self, PyObject *arg
return PyObjectResultPartType(ptype); return PyObjectResultPartType(ptype);
} }
static PyMethodDef Label_methods[] = { static PyMethodDef Label_methods[] = {
{"get_parttype_from_code", (PyCFunction)Label_get_parttype_from_code, METH_VARARGS, Label_get_parttype_from_code_HELP}, {"get_parttype_from_code", (PyCFunction)Label_get_parttype_from_code, METH_VARARGS, Label_get_parttype_from_code_HELP},
{"get_parttype_from_string", (PyCFunction)Label_get_parttype_from_string, METH_VARARGS, Label_get_parttype_from_string_HELP}, {"get_parttype_from_string", (PyCFunction)Label_get_parttype_from_string, METH_VARARGS, Label_get_parttype_from_string_HELP},
{NULL} {NULL}
}; };
static PyObject *Label_get_type(LabelObject *self) static PyObject *Label_get_type(LabelObject *self)
{ {
return PyLong_FromLong(fdisk_label_get_type(self->lb)); return PyLong_FromLong(fdisk_label_get_type(self->lb));
} }
static PyObject *Label_get_name(LabelObject *self) static PyObject *Label_get_name(LabelObject *self)
{ {
return PyObjectResultStr(fdisk_label_get_name(self->lb)); return PyObjectResultStr(fdisk_label_get_name(self->lb));
} }
static PyGetSetDef Label_getseters[] = { static PyGetSetDef Label_getseters[] = {
{"type", (getter)Label_get_type, NULL, "label type", NULL}, {"type", (getter)Label_get_type, NULL, "label type", NULL},
{"name", (getter)Label_get_name, NULL, "label name", NULL}, {"name", (getter)Label_get_name, NULL, "label name", NULL},

View File

@ -12,12 +12,10 @@
#include "fdisk.h" #include "fdisk.h"
static PyMemberDef Partition_members[] = { static PyMemberDef Partition_members[] = {
{ NULL } { NULL }
}; };
static void Partition_dealloc(PartitionObject *self) static void Partition_dealloc(PartitionObject *self)
{ {
if (self->pa) if (self->pa)
@ -78,12 +76,10 @@ static int Partition_init(PartitionObject *self, PyObject *args, PyObject *kwds)
return 0; return 0;
} }
static PyMethodDef Partition_methods[] = { static PyMethodDef Partition_methods[] = {
{NULL} {NULL}
}; };
static PyObject *Partition_get_partno(PartitionObject *self) static PyObject *Partition_get_partno(PartitionObject *self)
{ {
if (fdisk_partition_has_partno(self->pa)) { if (fdisk_partition_has_partno(self->pa)) {
@ -91,6 +87,7 @@ static PyObject *Partition_get_partno(PartitionObject *self)
} }
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static int Partition_set_partno(PartitionObject *self, PyObject *value, void *closure) static int Partition_set_partno(PartitionObject *self, PyObject *value, void *closure)
{ {
size_t num; size_t num;
@ -113,6 +110,7 @@ static int Partition_set_partno(PartitionObject *self, PyObject *value, void *cl
return 0; return 0;
} }
static PyObject *Partition_get_size(PartitionObject *self) static PyObject *Partition_get_size(PartitionObject *self)
{ {
if (fdisk_partition_has_size(self->pa)) { if (fdisk_partition_has_size(self->pa)) {
@ -120,6 +118,7 @@ static PyObject *Partition_get_size(PartitionObject *self)
} }
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static int Partition_set_size(PartitionObject *self, PyObject *value, void *closure) static int Partition_set_size(PartitionObject *self, PyObject *value, void *closure)
{ {
uint64_t sectors; uint64_t sectors;
@ -143,6 +142,7 @@ static int Partition_set_size(PartitionObject *self, PyObject *value, void *clos
return 0; return 0;
} }
static PyObject *Partition_get_type(PartitionObject *self) static PyObject *Partition_get_type(PartitionObject *self)
{ {
struct fdisk_parttype *t; struct fdisk_parttype *t;
@ -153,6 +153,7 @@ static PyObject *Partition_get_type(PartitionObject *self)
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static int Partition_set_type(PartitionObject *self, PyObject *value, void *closure) static int Partition_set_type(PartitionObject *self, PyObject *value, void *closure)
{ {
if (!value) { if (!value) {
@ -173,6 +174,7 @@ static int Partition_set_type(PartitionObject *self, PyObject *value, void *clos
return 0; return 0;
} }
static PyGetSetDef Partition_getseters[] = { static PyGetSetDef Partition_getseters[] = {
{"partno", (getter)Partition_get_partno, (setter)Partition_set_partno, "partition number", NULL}, {"partno", (getter)Partition_get_partno, (setter)Partition_set_partno, "partition number", NULL},
{"size", (getter)Partition_get_size, (setter)Partition_set_size, "number of sectors", NULL}, {"size", (getter)Partition_get_size, (setter)Partition_set_size, "number of sectors", NULL},

View File

@ -9,6 +9,7 @@
* Author: Jose M. Guisado <jguisado@soleta.eu> * Author: Jose M. Guisado <jguisado@soleta.eu>
*/ */
#include "fdisk.h" #include "fdisk.h"
static PyMemberDef PartType_members[] = { static PyMemberDef PartType_members[] = {
@ -28,10 +29,12 @@ static PyObject *PartType_get_name(PartTypeObject *self)
{ {
return PyObjectResultStr(fdisk_parttype_get_name(self->type)); return PyObjectResultStr(fdisk_parttype_get_name(self->type));
} }
static PyObject *PartType_get_code(PartTypeObject *self) static PyObject *PartType_get_code(PartTypeObject *self)
{ {
return PyLong_FromUnsignedLong(fdisk_parttype_get_code(self->type)); return PyLong_FromUnsignedLong(fdisk_parttype_get_code(self->type));
} }
static PyGetSetDef PartType_getseters[] = { static PyGetSetDef PartType_getseters[] = {
{"name", (getter)PartType_get_name, NULL, "parttype human readable name", NULL}, {"name", (getter)PartType_get_name, NULL, "parttype human readable name", NULL},
{"code", (getter)PartType_get_code, NULL, "parttype DOS code", NULL}, {"code", (getter)PartType_get_code, NULL, "parttype DOS code", NULL},