summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2023-01-10 10:15:24 +0100
committerJose M. Guisado <jguisado@soleta.eu>2023-01-10 10:15:24 +0100
commitdce0b0c1e30a728537abfd25cbe8a55dce22db37 (patch)
tree42a5d41ee2c35d736f468748e2bd7d359d5c373e
parent78cdaef9c6c5acf7328d9d81847295ea74e2ba80 (diff)
context: fix assign_device
Fixes a bug where calling assign_device with readonly keyword parameter raises exception stating it takes no keyword arguments. Context_assign_device has positional and keyword arguments. Adds flags METH_KEYWORDS in method declaration (see Context_methods). Replaces format string in PyArg_ParseTupleAndKeywords from "s|p" to "s|$p". Adds $ after |, meaning all later optional arguments are also keyword only. (See https://docs.python.org/3/c-api/arg.html#other-objects) Empty names in the kwlist array correspond to positional arguments. Replaces fname variable name with device for better readability. Fixes 88c7374db2309e708e9f9713a3d55acb1472f339 ("context: check self->cxt and rc in assign_device")
-rw-r--r--context.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/context.c b/context.c
index 04eb113..ba63b4a 100644
--- a/context.c
+++ b/context.c
@@ -83,9 +83,9 @@ static int Context_init(ContextObject *self, PyObject *args, PyObject *kwds)
"and switch the current label driver to reflect the probing result. "
static PyObject *Context_assign_device(ContextObject *self, PyObject *args, PyObject *kwds)
{
- static char *kwlist[] = { "readonly", NULL };
+ static char *kwlist[] = { "", "readonly", NULL };
int rc, readonly = 0;
- char *fname;
+ char *device;
if (!self->cxt) {
PyErr_SetString(PyExc_TypeError, ARG_ERR);
@@ -93,13 +93,13 @@ static PyObject *Context_assign_device(ContextObject *self, PyObject *args, PyOb
}
if (!PyArg_ParseTupleAndKeywords(args,
- kwds, "s|p", kwlist,
- &readonly)) {
+ kwds, "s|$p", kwlist,
+ &device, &readonly)) {
PyErr_SetString(PyExc_TypeError, ARG_ERR);
return NULL;
}
- if ((rc = fdisk_assign_device(self->cxt, fname, readonly)) < 0) {
+ if ((rc = fdisk_assign_device(self->cxt, device, readonly)) < 0) {
set_PyErr_from_rc(-rc);
return NULL;
}
@@ -198,7 +198,7 @@ static PyObject *Context_add_partition(ContextObject *self, PyObject *args, PyOb
}
static PyMethodDef Context_methods[] = {
- {"assign_device", (PyCFunction)Context_assign_device, METH_VARARGS, Context_assign_device_HELP},
+ {"assign_device", (PyCFunction)Context_assign_device, METH_VARARGS | METH_KEYWORDS, Context_assign_device_HELP},
{"partition_to_string", (PyCFunction)Context_partition_to_string, METH_VARARGS, Context_partition_to_string_HELP},
{"create_disklabel", (PyCFunction)Context_create_disklabel, METH_VARARGS, Context_create_disklabel_HELP},
{"write_disklabel", (PyCFunction)Context_write_disklabel, METH_NOARGS, Context_write_disklabel_HELP},