From: Michael Tremer Date: Mon, 27 Jan 2025 16:34:26 +0000 (+0000) Subject: python: Use the string array function for arches X-Git-Tag: 0.9.30~344 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18a47f59803c689cbfc075a152c9c7d278767f59;p=pakfire.git python: Use the string array function for arches Signed-off-by: Michael Tremer --- diff --git a/src/python/package.c b/src/python/package.c index fc0e9396..5022d43a 100644 --- a/src/python/package.c +++ b/src/python/package.c @@ -242,7 +242,7 @@ static PyObject* Package_get_url(PackageObject* self) { static PyObject* Package_get_groups(PackageObject* self) { char** groups = pakfire_package_get_strings(self->package, PAKFIRE_PKG_GROUPS); - PyObject* ret = PyUnicodeList_FromStringArray(groups); + PyObject* ret = PyUnicodeList_FromStringArray((const char**)groups); // Cleanup if (groups) @@ -306,7 +306,7 @@ static PyObject* Package_get_build_arches(PackageObject* self) { char** build_arches = pakfire_package_get_strings(self->package, PAKFIRE_PKG_BUILD_ARCHES); // Make a new list - PyObject* ret = PyUnicodeList_FromStringArray(build_arches); + PyObject* ret = PyUnicodeList_FromStringArray((const char**)build_arches); // Cleanup if (build_arches) diff --git a/src/python/pakfiremodule.c b/src/python/pakfiremodule.c index d32602d0..276954af 100644 --- a/src/python/pakfiremodule.c +++ b/src/python/pakfiremodule.c @@ -47,41 +47,16 @@ PyObject* PyExc_CheckError; PyObject* PyExc_CheckFileVerificationError; static PyObject* Pakfire_supported_arches(void) { - int r; + const char** arches = NULL; // Fetch all architectures - const char** arches = pakfire_supported_arches(); + arches = pakfire_supported_arches(); if (!arches) { PyErr_SetFromErrno(PyExc_OSError); return NULL; } - // Create a new list - PyObject* list = PyList_New(0); - if (!list) - return NULL; - - // Append all architectures - for (const char** arch = arches; *arch; arch++) { - PyObject* object = PyUnicode_FromString(*arch); - if (!object) - goto ERROR; - - // Append to list - r = PyList_Append(list, object); - if (r) { - Py_DECREF(object); - goto ERROR; - } - - Py_DECREF(object); - } - - return list; - -ERROR: - Py_DECREF(list); - return NULL; + return PyUnicodeList_FromStringArray(arches); } static PyObject* Pakfire_version_compare(PyObject* self, PyObject* args) { diff --git a/src/python/util.c b/src/python/util.c index 8db50722..f1abd0cd 100644 --- a/src/python/util.c +++ b/src/python/util.c @@ -33,7 +33,7 @@ #include "package.h" #include "util.h" -PyObject* PyUnicodeList_FromStringArray(char** l) { +PyObject* PyUnicodeList_FromStringArray(const char** l) { PyObject* list = NULL; PyObject* s = NULL; int r; diff --git a/src/python/util.h b/src/python/util.h index 0d286e64..79cc72eb 100644 --- a/src/python/util.h +++ b/src/python/util.h @@ -26,7 +26,7 @@ #include #include -PyObject* PyUnicodeList_FromStringArray(char** l); +PyObject* PyUnicodeList_FromStringArray(const char** l); PyObject* PyList_FromPackageList(struct pakfire_packagelist* packagelist); PyObject* PyList_FromFileList(struct pakfire_filelist* filelist);