From: Michael Tremer Date: Wed, 9 Oct 2024 14:19:37 +0000 (+0000) Subject: python: Correctly initialize and cast keyword arguments X-Git-Tag: 0.9.30~1112 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=254d84893cd2eafd4e7e3f4d9430b3901d02ea20;p=pakfire.git python: Correctly initialize and cast keyword arguments Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/archive.c b/src/_pakfire/archive.c index f3a34dea9..da293ba31 100644 --- a/src/_pakfire/archive.c +++ b/src/_pakfire/archive.c @@ -137,11 +137,11 @@ static PyObject* Archive_verify(ArchiveObject* self) { } static PyObject* Archive_extract(ArchiveObject* self, PyObject* args, PyObject* kwargs) { - char* kwlist[] = { "path", NULL }; + const char* kwlist[] = { "path", NULL }; const char* path = NULL; const int flags = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|z", kwlist, &path)) + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|z", (char**)kwlist, &path)) return NULL; // Extract payload diff --git a/src/_pakfire/key.c b/src/_pakfire/key.c index 9bf6935ce..dcda49b61 100644 --- a/src/_pakfire/key.c +++ b/src/_pakfire/key.c @@ -146,7 +146,7 @@ ERROR: } static PyObject* Key_sign(KeyObject* self, PyObject* args, PyObject* kwargs) { - char* kwlist[] = { "data", "comment", NULL }; + const char* kwlist[] = { "data", "comment", NULL }; PyObject* object = NULL; const char* data = NULL; Py_ssize_t data_length = 0; @@ -155,7 +155,7 @@ static PyObject* Key_sign(KeyObject* self, PyObject* args, PyObject* kwargs) { size_t signature_length = 0; int r; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y#|z", kwlist, + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y#|z", (char**)kwlist, &data, &data_length, &comment)) return NULL; diff --git a/src/_pakfire/package.c b/src/_pakfire/package.c index a28bca09d..17c8e3a19 100644 --- a/src/_pakfire/package.c +++ b/src/_pakfire/package.c @@ -686,12 +686,12 @@ static int Package_set_filelist(PackageObject* self, PyObject* value) { } static PyObject* Package_dump(PackageObject* self, PyObject *args, PyObject* kwds) { - static char* kwlist[] = {"long", "filelist", NULL}; + const char* kwlist[] = { "long", "filelist", NULL }; int long_format = 0; int filelist = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ii", kwlist, &long_format, &filelist)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ii", (char**)kwlist, &long_format, &filelist)) return NULL; int flags = 0; diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c index 4a387b64e..61c366e14 100644 --- a/src/_pakfire/pakfire.c +++ b/src/_pakfire/pakfire.c @@ -58,13 +58,7 @@ static PyObject* Pakfire_new(PyTypeObject* type, PyObject* args, PyObject* kwds) } static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) { - char* kwlist[] = { - "ctx", - "path", - "arch", - "conf", - NULL, - }; + const char* kwlist[] = { "ctx", "path", "arch", "conf", NULL }; CtxObject* ctx = NULL; const char* path = NULL; const char* arch = NULL; @@ -73,7 +67,7 @@ static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) { FILE* fconf = NULL; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|zzO", kwlist, + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|zzO", (char**)kwlist, &CtxType, &ctx, &path, &arch, &conf)) goto ERROR; @@ -174,12 +168,12 @@ static PyObject* Pakfire_get_repo(PakfireObject* self, PyObject* args) { XXX This could be moved out of here as this no longer depends on Pakfire */ static PyObject* Pakfire_generate_key(PakfireObject* self, PyObject* args, PyObject* kwds) { - char* kwlist[] = { "algorithm", "comment", NULL }; + const char* kwlist[] = { "algorithm", "comment", NULL }; struct pakfire_key* key = NULL; pakfire_key_algo_t algo = PAKFIRE_KEY_ALGO_NULL; const char* comment = NULL; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "is", kwlist, &algo, &comment)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "is", (char**)kwlist, &algo, &comment)) return NULL; // Generate a new key @@ -305,7 +299,7 @@ ERROR: } static PyObject* Pakfire_search(PakfireObject* self, PyObject* args, PyObject* kwds) { - char* kwlist[] = { "pattern", "name_only", NULL }; + const char* kwlist[] = { "pattern", "name_only", NULL }; struct pakfire_packagelist* list = NULL; const char* pattern = NULL; int name_only = 0; @@ -313,7 +307,7 @@ static PyObject* Pakfire_search(PakfireObject* self, PyObject* args, PyObject* k PyObject* ret = NULL; int r; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|$p", kwlist, &pattern, &name_only)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|$p", (char**)kwlist, &pattern, &name_only)) return NULL; // Search for package names only @@ -393,14 +387,7 @@ ERROR: } static PyObject* Pakfire_execute(PakfireObject* self, PyObject* args, PyObject* kwds) { - char* kwlist[] = { - "command", - "environ", - "bind", - "callback", - "nice", - NULL - }; + const char* kwlist[] = { "command", "environ", "bind", "callback", "nice", NULL }; struct pakfire_jail* jail = NULL; const char** argv = NULL; @@ -413,7 +400,7 @@ static PyObject* Pakfire_execute(PakfireObject* self, PyObject* args, PyObject* PyObject* callback = NULL; int nice = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OOOi", kwlist, &command, &environ, + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OOOi", (char**)kwlist, &command, &environ, &bind, &callback, &nice)) return NULL; @@ -696,14 +683,15 @@ static PyObject* Pakfire_open(PakfireObject* self, PyObject* args) { } static PyObject* Pakfire_repo_compose(PakfireObject* self, PyObject* args, PyObject* kwargs) { - char* kwlist[] = { "path", "files", "key", NULL }; + const char* kwlist[] = { "path", "files", "key", NULL }; const char* path = NULL; PyObject* list = NULL; KeyObject* key = NULL; PyObject* ret = NULL; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO|O!", kwlist, &path, &list, &KeyType, &key)) + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO|O!", (char**)kwlist, + &path, &list, &KeyType, &key)) return NULL; // List must be a sequence diff --git a/src/_pakfire/repo.c b/src/_pakfire/repo.c index 497185ae5..8e29cacd7 100644 --- a/src/_pakfire/repo.c +++ b/src/_pakfire/repo.c @@ -216,11 +216,11 @@ static int Repo_set_mirrorlist(RepoObject* self, PyObject* value) { } static PyObject* Repo_refresh(RepoObject* self, PyObject* args, PyObject* kwds) { - char* kwlist[] = { "force", NULL }; + const char* kwlist[] = { "force", NULL }; int force = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|p", kwlist, &force)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|p", (char**)kwlist, &force)) return NULL; Py_BEGIN_ALLOW_THREADS