]> git.ipfire.org Git - pakfire.git/commitdiff
solution: Create its own type
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 15:09:32 +0000 (15:09 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 15:09:32 +0000 (15:09 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/terminal.c
src/pakfire/problem.c
src/pakfire/problem.h
src/pakfire/solution.c
src/pakfire/solution.h
src/pakfire/transaction.c
src/pakfire/transaction.h
src/python/problem.c
src/python/solution.c
src/python/solution.h

index 4a8569764d1adcfa40c0d890a0b6051c1fedf89c..c1626b50b536d2cfd79dad4a71a1a9f9a21b3bad 100644 (file)
@@ -193,7 +193,7 @@ ERROR:
 }
 
 static int cli_term_print_problem(pakfire_problem* problem, unsigned int* num_solutions) {
-       struct pakfire_solution** solutions = NULL;
+       pakfire_solution** solutions = NULL;
 
        // Show what the problem is
        printf("  * %s\n", pakfire_problem_to_string(problem));
@@ -206,7 +206,7 @@ static int cli_term_print_problem(pakfire_problem* problem, unsigned int* num_so
                printf("    %s\n", _("Possible solutions:"));
 
                // Show all possible solutions
-               for (struct pakfire_solution** s = solutions; *s; s++) {
+               for (pakfire_solution** s = solutions; *s; s++) {
                        // Increment the solution counter
                        (*num_solutions)++;
 
@@ -217,7 +217,7 @@ static int cli_term_print_problem(pakfire_problem* problem, unsigned int* num_so
 
        // Cleanup
        if (solutions) {
-               for (struct pakfire_solution** s = solutions; *s; s++)
+               for (pakfire_solution** s = solutions; *s; s++)
                        pakfire_solution_unref(*s);
 
                free(solutions);
@@ -226,10 +226,10 @@ static int cli_term_print_problem(pakfire_problem* problem, unsigned int* num_so
        return 0;
 }
 
-static struct pakfire_solution* cli_term_find_solution(
+static pakfire_solution* cli_term_find_solution(
                pakfire_problem** problems, const unsigned int choice) {
-       struct pakfire_solution* selected_solution = NULL;
-       struct pakfire_solution** solutions = NULL;
+       pakfire_solution* selected_solution = NULL;
+       pakfire_solution** solutions = NULL;
 
        // Count solutions
        unsigned int i = 1;
@@ -240,7 +240,7 @@ static struct pakfire_solution* cli_term_find_solution(
                if (!solutions)
                        continue;
 
-               for (struct pakfire_solution** solution = solutions; *solution; solution++) {
+               for (pakfire_solution** solution = solutions; *solution; solution++) {
                        if (choice == i++)
                                selected_solution = pakfire_solution_ref(*solution);
 
@@ -259,7 +259,7 @@ static struct pakfire_solution* cli_term_find_solution(
 int cli_term_pick_solution(pakfire_ctx* ctx, struct pakfire* pakfire, void* data,
                struct pakfire_transaction* transaction) {
        pakfire_problem** problems = NULL;
-       struct pakfire_solution* solution = NULL;
+       pakfire_solution* solution = NULL;
        unsigned int num_solutions = 0;
        unsigned int choice = 0;
        int r = 0;
index 2613c1bb5f170b2813371cd71e1a878b060df415..c17b923a4d1bd262d8a410d31e218dfd85bc777c 100644 (file)
@@ -264,10 +264,10 @@ struct pakfire_transaction* pakfire_problem_get_transaction(pakfire_problem* pro
        return pakfire_transaction_ref(problem->transaction);
 }
 
-struct pakfire_solution** pakfire_problem_get_solutions(
+pakfire_solution** pakfire_problem_get_solutions(
                pakfire_problem* problem) {
-       struct pakfire_solution** solutions = NULL;
-       struct pakfire_solution* solution = NULL;
+       pakfire_solution** solutions = NULL;
+       pakfire_solution* solution = NULL;
        unsigned int count = 0;
        Id id = ID_NULL;
        int r;
@@ -304,7 +304,7 @@ ERROR:
        ERROR(problem->ctx, "Could not import solutions: %s\n", strerror(r));
 
        if (solutions) {
-               for (struct pakfire_solution** s = solutions; *s; s++)
+               for (pakfire_solution** s = solutions; *s; s++)
                        pakfire_solution_unref(*s);
 
                free(solutions);
index 8e04a7e4596c977911f75c2dae8eb1d6df69a1d4..4a3c65ec55e831df0d2d5ee2e61eac1829aefe8a 100644 (file)
@@ -34,7 +34,7 @@ pakfire_problem* pakfire_problem_unref(pakfire_problem* problem);
 
 const char* pakfire_problem_to_string(pakfire_problem* problem);
 
-struct pakfire_solution** pakfire_problem_get_solutions(
+pakfire_solution** pakfire_problem_get_solutions(
        pakfire_problem* problem);
 
 int pakfire_problem_create(pakfire_problem** problem, struct pakfire* pakfire,
index 9593b0336f10bbdebdc51c875b1c5d4bbe673d8a..aa1f3098c92e276a09157a43710705497739edd2 100644 (file)
@@ -42,9 +42,9 @@ struct pakfire_solution {
        char* string;
 };
 
-int pakfire_solution_create(struct pakfire_solution** solution,
+int pakfire_solution_create(pakfire_solution** solution,
                struct pakfire* pakfire, pakfire_problem* problem, Id id) {
-       struct pakfire_solution* s = calloc(1, sizeof(*s));
+       pakfire_solution* s = calloc(1, sizeof(*s));
        if (!s)
                return -errno;
 
@@ -64,13 +64,13 @@ int pakfire_solution_create(struct pakfire_solution** solution,
        return 0;
 }
 
-struct pakfire_solution* pakfire_solution_ref(struct pakfire_solution* solution) {
+pakfire_solution* pakfire_solution_ref(pakfire_solution* solution) {
        solution->nrefs++;
 
        return solution;
 }
 
-static void pakfire_solution_free(struct pakfire_solution* solution) {
+static void pakfire_solution_free(pakfire_solution* solution) {
        pakfire_problem_unref(solution->problem);
 
        if (solution->string)
@@ -80,7 +80,7 @@ static void pakfire_solution_free(struct pakfire_solution* solution) {
        free(solution);
 }
 
-struct pakfire_solution* pakfire_solution_unref(struct pakfire_solution* solution) {
+pakfire_solution* pakfire_solution_unref(pakfire_solution* solution) {
        if (!solution)
                return NULL;
 
@@ -91,15 +91,15 @@ struct pakfire_solution* pakfire_solution_unref(struct pakfire_solution* solutio
        return NULL;
 }
 
-pakfire_problem* pakfire_solution_get_problem(struct pakfire_solution* solution) {
+pakfire_problem* pakfire_solution_get_problem(pakfire_solution* solution) {
        return pakfire_problem_ref(solution->problem);
 }
 
-Id pakfire_solution_get_id(struct pakfire_solution* solution) {
+Id pakfire_solution_get_id(pakfire_solution* solution) {
        return solution->id;
 }
 
-static char* pakfire_solution_make_string(struct pakfire_solution* solution) {
+static char* pakfire_solution_make_string(pakfire_solution* solution) {
        struct pakfire_transaction* transaction = pakfire_problem_get_transaction(solution->problem);
        Solver* solver = pakfire_transaction_get_solver(transaction);
        Pool* pool = solver->pool;
@@ -208,7 +208,7 @@ ERROR:
        return s;
 }
 
-const char* pakfire_solution_to_string(struct pakfire_solution* solution) {
+const char* pakfire_solution_to_string(pakfire_solution* solution) {
        if (!solution->string)
                solution->string = pakfire_solution_make_string(solution);
 
index 5cbfd7b3ae63441ec377027c4e08054668ae05df..1c5b86e283e9b8484aff16cdfac6198d44c286c0 100644 (file)
 // libsolv
 #include <solv/pooltypes.h>
 
-struct pakfire_solution;
+typedef struct pakfire_solution pakfire_solution;
 
 #include <pakfire/pakfire.h>
 #include <pakfire/problem.h>
 
-struct pakfire_solution* pakfire_solution_ref(struct pakfire_solution* solution);
-struct pakfire_solution* pakfire_solution_unref(struct pakfire_solution* solution);
+pakfire_solution* pakfire_solution_ref(pakfire_solution* solution);
+pakfire_solution* pakfire_solution_unref(pakfire_solution* solution);
 
-const char* pakfire_solution_to_string(struct pakfire_solution* solution);
+const char* pakfire_solution_to_string(pakfire_solution* solution);
 
-int pakfire_solution_create(struct pakfire_solution** solution, struct pakfire* pakfire,
+int pakfire_solution_create(pakfire_solution** solution, struct pakfire* pakfire,
        pakfire_problem* problem, Id id);
-pakfire_problem* pakfire_solution_get_problem(struct pakfire_solution* solution);
-Id pakfire_solution_get_id(struct pakfire_solution* solution);
+pakfire_problem* pakfire_solution_get_problem(pakfire_solution* solution);
+Id pakfire_solution_get_id(pakfire_solution* solution);
 
 #endif /* PAKFIRE_SOLUTION_H */
index ea79d719d2003735674cd7f21adb1b6583578c19..1b251ef16e9d1e9499ba715ba8c52bed25d04d29 100644 (file)
@@ -487,11 +487,11 @@ ERROR:
 }
 
 static int pakfire_transaction_append_solutions(
-               struct pakfire_transaction* transaction, char** buffer, struct pakfire_solution** solutions) {
+               struct pakfire_transaction* transaction, char** buffer, pakfire_solution** solutions) {
        const char* s = NULL;
        int r;
 
-       for (struct pakfire_solution** solution = solutions; *solution; solution++) {
+       for (pakfire_solution** solution = solutions; *solution; solution++) {
                s = pakfire_solution_to_string(*solution);
                if (!s)
                        return -errno;
@@ -507,7 +507,7 @@ static int pakfire_transaction_append_solutions(
 
 static int pakfire_transaction_append_problems(
                struct pakfire_transaction* transaction, char** buffer, pakfire_problem** problems, int flags) {
-       struct pakfire_solution** solutions = NULL;
+       pakfire_solution** solutions = NULL;
        const char* s = NULL;
        int r;
 
@@ -530,7 +530,7 @@ static int pakfire_transaction_append_problems(
                                r = pakfire_transaction_append_solutions(transaction, buffer, solutions);
 
                                // Cleanup
-                               for (struct pakfire_solution** solution = solutions; *solution; solution++)
+                               for (pakfire_solution** solution = solutions; *solution; solution++)
                                        pakfire_solution_unref(*solution);
                                free(solutions);
 
@@ -870,7 +870,7 @@ int pakfire_transaction_request_package(struct pakfire_transaction* transaction,
 }
 
 int pakfire_transaction_take_solution(struct pakfire_transaction* transaction,
-               struct pakfire_solution* solution) {
+               pakfire_solution* solution) {
        pakfire_problem* problem = pakfire_solution_get_problem(solution);
 
        // Fetch IDs
index fa5db0f0266c65e0ebdc7b046b2e96b5ca2158e1..8af9a6ab39fba63a4948f8d42e5d5ec7a647eae7 100644 (file)
@@ -74,7 +74,7 @@ int pakfire_transaction_request_package(struct pakfire_transaction* transaction,
 
 pakfire_problem** pakfire_transaction_get_problems(struct pakfire_transaction* transaction);
 int pakfire_transaction_take_solution(
-       struct pakfire_transaction* transaction, struct pakfire_solution* solution);
+       struct pakfire_transaction* transaction, pakfire_solution* solution);
 
 size_t pakfire_transaction_count(struct pakfire_transaction* transaction);
 char* pakfire_transaction_dump(struct pakfire_transaction* transaction, size_t width);
index 96edae520c2f5ec075fd978893114f4c64083d59..d2d690477431b1622b31aaf61b0f59e6cdcdd1a2 100644 (file)
@@ -71,7 +71,7 @@ static PyObject* Problem_string(ProblemObject* self) {
 }
 
 static PyObject* Problem_get_solutions(ProblemObject* self) {
-       struct pakfire_solution** solutions = NULL;
+       pakfire_solution** solutions = NULL;
        PyObject* s = NULL;
        int r;
 
@@ -83,7 +83,7 @@ static PyObject* Problem_get_solutions(ProblemObject* self) {
        solutions = pakfire_problem_get_solutions(self->problem);
 
        if (solutions) {
-               for (struct pakfire_solution** solution = solutions; *solution; solution++) {
+               for (pakfire_solution** solution = solutions; *solution; solution++) {
                        s = new_solution(*solution);
                        if (!s)
                                goto ERROR;
@@ -96,7 +96,7 @@ static PyObject* Problem_get_solutions(ProblemObject* self) {
                }
 
                // Cleanup
-               for (struct pakfire_solution** solution = solutions; *solution; solution++)
+               for (pakfire_solution** solution = solutions; *solution; solution++)
                        pakfire_solution_unref(*solution);
                free(solutions);
        }
@@ -105,7 +105,7 @@ static PyObject* Problem_get_solutions(ProblemObject* self) {
 
 ERROR:
        if (solutions) {
-               for (struct pakfire_solution** solution = solutions; *solution; solution++)
+               for (pakfire_solution** solution = solutions; *solution; solution++)
                        pakfire_solution_unref(*solution);
                free(solutions);
        }
index 3c09887f5853a3f6451b26e10c209b77b3ab93ef..5f1c31e68e1129020fa46cce4f5068e2a33b62d2 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "solution.h"
 
-static SolutionObject* Solution_new_core(PyTypeObject* type, struct pakfire_solution* solution) {
+static SolutionObject* Solution_new_core(PyTypeObject* type, pakfire_solution* solution) {
        SolutionObject* self = (SolutionObject *)type->tp_alloc(type, 0);
        if (self) {
                self->solution = solution;
@@ -34,7 +34,7 @@ static SolutionObject* Solution_new_core(PyTypeObject* type, struct pakfire_solu
        return self;
 }
 
-PyObject* new_solution(struct pakfire_solution* solution) {
+PyObject* new_solution(pakfire_solution* solution) {
        SolutionObject* s = Solution_new_core(&SolutionType, solution);
 
        return (PyObject*)s;
index cd5bb3e05626e46cbadb365709e5d38b2f21fe12..4f68afa7852b6e94373dd34441e57e9719d02665 100644 (file)
 
 typedef struct {
        PyObject_HEAD
-       struct pakfire_solution* solution;
+       pakfire_solution* solution;
 } SolutionObject;
 
 extern PyTypeObject SolutionType;
 
-PyObject* new_solution(struct pakfire_solution* solution);
+PyObject* new_solution(pakfire_solution* solution);
 
 #endif /* PYTHON_PAKFIRE_SOLUTION_H */