]> git.ipfire.org Git - pakfire.git/commitdiff
problems: Drop pakfire_problem_get_solutions in favour of *_next_solution
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 1 Nov 2022 14:28:32 +0000 (14:28 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 1 Nov 2022 14:28:32 +0000 (14:28 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/problem.c
src/libpakfire/include/pakfire/problem.h
src/libpakfire/libpakfire.sym
src/libpakfire/problem.c

index 66a123a48c2e5945a52e0ac652c29032c54dbdfe..15a0f2bb13c1ad184cd6f30ee3f2600493599369 100644 (file)
@@ -82,30 +82,38 @@ static PyObject* Problem_string(ProblemObject* self) {
 }
 
 static PyObject* Problem_get_solutions(ProblemObject* self) {
-       struct pakfire_solution** solutions = NULL;
-
-       // Fetch all solutions
-       int r = pakfire_problem_get_solutions(self->problem, &solutions);
-       if (r) {
-               PyErr_SetFromErrno(PyExc_OSError);
-               return NULL;
-       }
+       struct pakfire_solution* solution = NULL;
+       PyObject* solution_obj = NULL;
+       int r;
 
        PyObject* list = PyList_New(0);
        if (!list)
                return NULL;
 
-       // Return the empty list if there are no solutions
-       if (!solutions)
-               return list;
+       for (;;) {
+               r = pakfire_problem_next_solution(self->problem, &solution);
+               if (r)
+                       goto ERROR;
+
+               // No more solutions
+               if (!solution)
+                       break;
+
+               // Create a new Solution object
+               solution_obj = new_solution(solution);
+               if (!solution_obj) {
+                       pakfire_solution_unref(solution);
+                       goto ERROR;
+               }
 
-       for (struct pakfire_solution** solution = solutions; *solution; solution++) {
-               PyObject* s = new_solution(*solution);
-               if (!s)
+               // Append the solution to the list
+               r = PyList_Append(list, solution_obj);
+               if (r) {
+                       pakfire_solution_unref(solution);
                        goto ERROR;
+               }
 
-               PyList_Append(list, s);
-               Py_DECREF(s);
+               Py_DECREF(solution_obj);
        }
 
        return list;
index 046d0b1e453b009bc8150f4e84558c1c8f52eef3..b9f7e6844e025af9d0c9c68ac9edc08a9df79951 100644 (file)
@@ -31,8 +31,9 @@ struct pakfire_problem* pakfire_problem_unref(struct pakfire_problem* problem);
 const char* pakfire_problem_to_string(struct pakfire_problem* problem);
 
 struct pakfire_request* pakfire_problem_get_request(struct pakfire_problem* problem);
-int pakfire_problem_get_solutions(struct pakfire_problem* problem,
-       struct pakfire_solution*** solutions);
+
+int pakfire_problem_next_solution(
+       struct pakfire_problem* problem, struct pakfire_solution** solution);
 
 #ifdef PAKFIRE_PRIVATE
 
@@ -44,9 +45,6 @@ int pakfire_problem_create(struct pakfire_problem** problem, struct pakfire* pak
 struct pakfire* pakfire_problem_get_pakfire(struct pakfire_problem* problem);
 Id pakfire_problem_get_id(struct pakfire_problem* problem);
 
-int pakfire_problem_next_solution(
-       struct pakfire_problem* problem, struct pakfire_solution** solution);
-
 #endif
 
 #endif /* PAKFIRE_PROBLEM_H */
index 757db5115d22b6697a046028aaa74c6c09038ec8..5133995718c124ffda9005f95ac4c92a3db9b18f 100644 (file)
@@ -198,7 +198,7 @@ global:
        pakfire_packagelist_unref;
 
        # problem
-       pakfire_problem_get_solutions;
+       pakfire_problem_next_solution;
        pakfire_problem_ref;
        pakfire_problem_to_string;
        pakfire_problem_unref;
index 4bc7ebffb5a4a7a51939ab34a4b9efa6fe1cd396..67d403f1e81248c40860948e133696f2f762be18 100644 (file)
@@ -246,53 +246,7 @@ PAKFIRE_EXPORT struct pakfire_request* pakfire_problem_get_request(struct pakfir
        return pakfire_request_ref(problem->request);
 }
 
-PAKFIRE_EXPORT int pakfire_problem_get_solutions(struct pakfire_problem* problem,
-               struct pakfire_solution*** solutions) {
-       Solver* solver = pakfire_request_get_solver(problem->request);
-       int r;
-
-       // How many solutions are there?
-       unsigned int count = solver_solution_count(solver, problem->id);
-       if (!count) {
-               *solutions = NULL;
-               return 0;
-       }
-
-       // Allocate a solutions array
-       *solutions = calloc(count + 1, sizeof(**solutions));
-       if (!*solutions)
-               return 1;
-
-       struct pakfire_solution* solution = NULL;
-
-       Id s = 0;
-       for (unsigned int i = 0; i < count; i++) {
-               s = solver_next_solution(solver, problem->id, s);
-               if (!s)
-                       break;
-
-               // Create a new solution object
-               r = pakfire_solution_create(&solution, problem, s);
-               if (r)
-                       goto ERROR;
-
-               // Append solution to array
-               (*solutions)[i] = solution;
-       }
-
-       return 0;
-
-ERROR:
-       if (*solutions) {
-               for (struct pakfire_solution** _solution = *solutions; *_solution; _solution++)
-                       pakfire_solution_unref(*_solution);
-               free(*solutions);
-       }
-
-       return r;
-}
-
-int pakfire_problem_next_solution(
+PAKFIRE_EXPORT int pakfire_problem_next_solution(
                struct pakfire_problem* problem, struct pakfire_solution** solution) {
        Solver* solver = pakfire_request_get_solver(problem->request);
        Id id = 0;