From: Michael Tremer Date: Tue, 28 Feb 2023 15:00:46 +0000 (+0000) Subject: pakfire_whatprovides/requires: Write to an existant list X-Git-Tag: 0.9.29~373 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=79bdcddfd479f5c7ef6f5ad3e90950f791ebad08;p=pakfire.git pakfire_whatprovides/requires: Write to an existant list Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c index 40d97bcd4..114197bdf 100644 --- a/src/_pakfire/pakfire.c +++ b/src/_pakfire/pakfire.c @@ -701,39 +701,65 @@ static PyObject* Pakfire_fetch_key(PakfireObject* self, PyObject* args, PyObject static PyObject* Pakfire_whatprovides(PakfireObject* self, PyObject* args) { const char* provides = NULL; struct pakfire_packagelist* list = NULL; + PyObject* ret = NULL; + int r; if (!PyArg_ParseTuple(args, "s", &provides)) return NULL; - int r = pakfire_whatprovides(self->pakfire, provides, 0, &list); + // Create a new list + r = pakfire_packagelist_create(&list, self->pakfire); if (r) { PyErr_SetFromErrno(PyExc_OSError); - return NULL; + goto ERROR; } - PyObject* obj = PyList_FromPackageList(list); - pakfire_packagelist_unref(list); + r = pakfire_whatprovides(self->pakfire, provides, 0, list); + if (r) { + PyErr_SetFromErrno(PyExc_OSError); + goto ERROR; + } - return obj; + // Create a Python list from the package list + ret = PyList_FromPackageList(list); + +ERROR: + if (list) + pakfire_packagelist_unref(list); + + return ret; } static PyObject* Pakfire_whatrequires(PakfireObject* self, PyObject* args) { const char* requires = NULL; struct pakfire_packagelist* list = NULL; + PyObject* ret = NULL; + int r; if (!PyArg_ParseTuple(args, "s", &requires)) return NULL; - int r = pakfire_whatrequires(self->pakfire, requires, 0, &list); + // Create a new list + r = pakfire_packagelist_create(&list, self->pakfire); if (r) { PyErr_SetFromErrno(PyExc_OSError); - return NULL; + goto ERROR; } - PyObject* obj = PyList_FromPackageList(list); - pakfire_packagelist_unref(list); + r = pakfire_whatprovides(self->pakfire, requires, 0, list); + if (r) { + PyErr_SetFromErrno(PyExc_OSError); + goto ERROR; + } - return obj; + // Create a Python list from the package list + ret = PyList_FromPackageList(list); + +ERROR: + if (list) + pakfire_packagelist_unref(list); + + return ret; } static PyObject* Pakfire_search(PakfireObject* self, PyObject* args, PyObject* kwds) { diff --git a/src/libpakfire/include/pakfire/pakfire.h b/src/libpakfire/include/pakfire/pakfire.h index 36de4efe5..54693ae09 100644 --- a/src/libpakfire/include/pakfire/pakfire.h +++ b/src/libpakfire/include/pakfire/pakfire.h @@ -77,9 +77,9 @@ struct pakfire_repolist* pakfire_get_repos(struct pakfire* pakfire); struct pakfire_repo* pakfire_get_repo(struct pakfire* pakfire, const char* name); int pakfire_whatprovides(struct pakfire* pakfire, const char* what, int flags, - struct pakfire_packagelist** list); + struct pakfire_packagelist* list); int pakfire_whatrequires(struct pakfire* pakfire, const char* what, int flags, - struct pakfire_packagelist** list); + struct pakfire_packagelist* list); // Search diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 318cf5d69..59d99e33e 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -1447,7 +1447,7 @@ ERROR: } static int pakfire_search_dep(struct pakfire* pakfire, Id type, const char* what, int flags, - struct pakfire_packagelist** list) { + struct pakfire_packagelist* list) { int r; // Get the pool ready @@ -1460,23 +1460,17 @@ static int pakfire_search_dep(struct pakfire* pakfire, Id type, const char* what return 1; } - // Reset pointer - *list = NULL; - Queue matches; queue_init(&matches); // Search for anything that matches pool_whatmatchesdep(pakfire->pool, type, dep, &matches, 0); - // Create a packagelist - r = pakfire_packagelist_create_from_queue(list, pakfire, &matches); + // Add the result to the packagelist + r = pakfire_packagelist_import_solvables(list, &matches); if (r) goto ERROR; - // Sort the list - pakfire_packagelist_sort(*list); - ERROR: queue_free(&matches); @@ -1484,12 +1478,12 @@ ERROR: } PAKFIRE_EXPORT int pakfire_whatprovides(struct pakfire* pakfire, const char* what, int flags, - struct pakfire_packagelist** list) { + struct pakfire_packagelist* list) { return pakfire_search_dep(pakfire, SOLVABLE_PROVIDES, what, flags, list); } PAKFIRE_EXPORT int pakfire_whatrequires(struct pakfire* pakfire, const char* what, int flags, - struct pakfire_packagelist** list) { + struct pakfire_packagelist* list) { return pakfire_search_dep(pakfire, SOLVABLE_REQUIRES, what, flags, list); }