]> git.ipfire.org Git - pakfire.git/commitdiff
problem: Create its own type
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 14:36:29 +0000 (14:36 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 14:36:29 +0000 (14:36 +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/problem.h

index a4cda59f5c4811c472429985465860d2d73c58c3..4a8569764d1adcfa40c0d890a0b6051c1fedf89c 100644 (file)
@@ -192,7 +192,7 @@ ERROR:
        return r;
 }
 
-static int cli_term_print_problem(struct pakfire_problem* problem, unsigned int* num_solutions) {
+static int cli_term_print_problem(pakfire_problem* problem, unsigned int* num_solutions) {
        struct pakfire_solution** solutions = NULL;
 
        // Show what the problem is
@@ -227,14 +227,14 @@ static int cli_term_print_problem(struct pakfire_problem* problem, unsigned int*
 }
 
 static struct pakfire_solution* cli_term_find_solution(
-               struct pakfire_problem** problems, const unsigned int choice) {
+               pakfire_problem** problems, const unsigned int choice) {
        struct pakfire_solution* selected_solution = NULL;
        struct pakfire_solution** solutions = NULL;
 
        // Count solutions
        unsigned int i = 1;
 
-       for (struct pakfire_problem** problem = problems; *problem; problem++) {
+       for (pakfire_problem** problem = problems; *problem; problem++) {
                // Fetch solutions
                solutions = pakfire_problem_get_solutions(*problem);
                if (!solutions)
@@ -258,7 +258,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) {
-       struct pakfire_problem** problems = NULL;
+       pakfire_problem** problems = NULL;
        struct pakfire_solution* solution = NULL;
        unsigned int num_solutions = 0;
        unsigned int choice = 0;
@@ -277,7 +277,7 @@ int cli_term_pick_solution(pakfire_ctx* ctx, struct pakfire* pakfire, void* data
                printf("%s\n", _("One or more problems have occurred solving your request:"));
 
                // Show all problems
-               for (struct pakfire_problem** p = problems; *p; p++) {
+               for (pakfire_problem** p = problems; *p; p++) {
                        r = cli_term_print_problem(*p, &num_solutions);
                        if (r)
                                goto ERROR;
@@ -306,7 +306,7 @@ int cli_term_pick_solution(pakfire_ctx* ctx, struct pakfire* pakfire, void* data
 
 ERROR:
        if (problems) {
-               for (struct pakfire_problem** p = problems; *p; p++)
+               for (pakfire_problem** p = problems; *p; p++)
                        pakfire_problem_unref(*p);
 
                free(problems);
index 9cbdc70a27b08cbaf8440734e7f0e3c8227bc224..2613c1bb5f170b2813371cd71e1a878b060df415 100644 (file)
@@ -44,7 +44,7 @@ struct pakfire_problem {
        Solver* solver;
 };
 
-static char* pakfire_problem_make_string(struct pakfire_problem* problem) {
+static char* pakfire_problem_make_string(pakfire_problem* problem) {
        Solver* solver = pakfire_transaction_get_solver(problem->transaction);
        Pool* pool = solver->pool;
 
@@ -190,9 +190,9 @@ static char* pakfire_problem_make_string(struct pakfire_problem* problem) {
        return s;
 }
 
-int pakfire_problem_create(struct pakfire_problem** problem,
+int pakfire_problem_create(pakfire_problem** problem,
                struct pakfire* pakfire, struct pakfire_transaction* transaction, Id id) {
-       struct pakfire_problem* p = NULL;
+       pakfire_problem* p = NULL;
 
        // Allocate some memory
        p = calloc(1, sizeof(*p));
@@ -223,7 +223,7 @@ int pakfire_problem_create(struct pakfire_problem** problem,
        return 0;
 }
 
-static void pakfire_problem_free(struct pakfire_problem* problem) {
+static void pakfire_problem_free(pakfire_problem* problem) {
        if (problem->transaction)
                pakfire_transaction_unref(problem->transaction);
        if (problem->string)
@@ -235,13 +235,13 @@ static void pakfire_problem_free(struct pakfire_problem* problem) {
        free(problem);
 }
 
-struct pakfire_problem* pakfire_problem_ref(struct pakfire_problem* problem) {
+pakfire_problem* pakfire_problem_ref(pakfire_problem* problem) {
        problem->nrefs++;
 
        return problem;
 }
 
-struct pakfire_problem* pakfire_problem_unref(struct pakfire_problem* problem) {
+pakfire_problem* pakfire_problem_unref(pakfire_problem* problem) {
        if (--problem->nrefs > 0)
                return problem;
 
@@ -249,23 +249,23 @@ struct pakfire_problem* pakfire_problem_unref(struct pakfire_problem* problem) {
        return NULL;
 }
 
-const char* pakfire_problem_to_string(struct pakfire_problem* problem) {
+const char* pakfire_problem_to_string(pakfire_problem* problem) {
        if (!problem->string)
                problem->string = pakfire_problem_make_string(problem);
 
        return problem->string;
 }
 
-Id pakfire_problem_get_id(struct pakfire_problem* problem) {
+Id pakfire_problem_get_id(pakfire_problem* problem) {
        return problem->id;
 }
 
-struct pakfire_transaction* pakfire_problem_get_transaction(struct pakfire_problem* problem) {
+struct pakfire_transaction* pakfire_problem_get_transaction(pakfire_problem* problem) {
        return pakfire_transaction_ref(problem->transaction);
 }
 
 struct pakfire_solution** pakfire_problem_get_solutions(
-               struct pakfire_problem* problem) {
+               pakfire_problem* problem) {
        struct pakfire_solution** solutions = NULL;
        struct pakfire_solution* solution = NULL;
        unsigned int count = 0;
index 3b75ad87191e4ee9754331d0b5332a36cc72ecc2..8e04a7e4596c977911f75c2dae8eb1d6df69a1d4 100644 (file)
 // libsolv
 #include <solv/pooltypes.h>
 
-struct pakfire_problem;
+typedef struct pakfire_problem pakfire_problem;
 
 #include <pakfire/solution.h>
 #include <pakfire/transaction.h>
 
-struct pakfire_problem* pakfire_problem_ref(struct pakfire_problem* problem);
-struct pakfire_problem* pakfire_problem_unref(struct pakfire_problem* problem);
+pakfire_problem* pakfire_problem_ref(pakfire_problem* problem);
+pakfire_problem* pakfire_problem_unref(pakfire_problem* problem);
 
-const char* pakfire_problem_to_string(struct pakfire_problem* problem);
+const char* pakfire_problem_to_string(pakfire_problem* problem);
 
 struct pakfire_solution** pakfire_problem_get_solutions(
-       struct pakfire_problem* problem);
+       pakfire_problem* problem);
 
-int pakfire_problem_create(struct pakfire_problem** problem, struct pakfire* pakfire,
+int pakfire_problem_create(pakfire_problem** problem, struct pakfire* pakfire,
        struct pakfire_transaction* transaction, Id id);
 
-struct pakfire_transaction* pakfire_problem_get_transaction(struct pakfire_problem* problem);
+struct pakfire_transaction* pakfire_problem_get_transaction(pakfire_problem* problem);
 
-Id pakfire_problem_get_id(struct pakfire_problem* problem);
+Id pakfire_problem_get_id(pakfire_problem* problem);
 
 #endif /* PAKFIRE_PROBLEM_H */
index c4785b10fdf89729d6344d083cd2862d87b2c32c..9593b0336f10bbdebdc51c875b1c5d4bbe673d8a 100644 (file)
@@ -37,13 +37,13 @@ struct pakfire_solution {
        struct pakfire* pakfire;
        int nrefs;
 
-       struct pakfire_problem* problem;
+       pakfire_problem* problem;
        Id id;
        char* string;
 };
 
 int pakfire_solution_create(struct pakfire_solution** solution,
-               struct pakfire* pakfire, struct pakfire_problem* problem, Id id) {
+               struct pakfire* pakfire, pakfire_problem* problem, Id id) {
        struct pakfire_solution* s = calloc(1, sizeof(*s));
        if (!s)
                return -errno;
@@ -91,7 +91,7 @@ struct pakfire_solution* pakfire_solution_unref(struct pakfire_solution* solutio
        return NULL;
 }
 
-struct pakfire_problem* pakfire_solution_get_problem(struct pakfire_solution* solution) {
+pakfire_problem* pakfire_solution_get_problem(struct pakfire_solution* solution) {
        return pakfire_problem_ref(solution->problem);
 }
 
index 78c5b417a4b17642ff9ab03fa82291803f6b9ee8..5cbfd7b3ae63441ec377027c4e08054668ae05df 100644 (file)
@@ -35,8 +35,8 @@ struct pakfire_solution* pakfire_solution_unref(struct pakfire_solution* solutio
 const char* pakfire_solution_to_string(struct pakfire_solution* solution);
 
 int pakfire_solution_create(struct pakfire_solution** solution, struct pakfire* pakfire,
-       struct pakfire_problem* problem, Id id);
-struct pakfire_problem* pakfire_solution_get_problem(struct pakfire_solution* solution);
+       pakfire_problem* problem, Id id);
+pakfire_problem* pakfire_solution_get_problem(struct pakfire_solution* solution);
 Id pakfire_solution_get_id(struct pakfire_solution* solution);
 
 #endif /* PAKFIRE_SOLUTION_H */
index e687df2881ee756f621cdab7537ca2856b200c3e..dfe32d5afda7484260d650ab7084ef48b168c0a5 100644 (file)
@@ -435,10 +435,10 @@ struct pakfire_transaction* pakfire_transaction_unref(
        return NULL;
 }
 
-struct pakfire_problem** pakfire_transaction_get_problems(
+pakfire_problem** pakfire_transaction_get_problems(
                struct pakfire_transaction* transaction) {
-       struct pakfire_problem** problems = NULL;
-       struct pakfire_problem* problem = NULL;
+       pakfire_problem** problems = NULL;
+       pakfire_problem* problem = NULL;
        unsigned int count = 0;
        Id id = ID_NULL;
        int r;
@@ -478,7 +478,7 @@ ERROR:
        ERROR(transaction->ctx, "Could not import problems: %s\n", strerror(r));
 
        if (problems) {
-               for (struct pakfire_problem** p = problems; *p; p++)
+               for (pakfire_problem** p = problems; *p; p++)
                        pakfire_problem_unref(*p);
                free(problems);
        }
@@ -506,12 +506,12 @@ static int pakfire_transaction_append_solutions(
 }
 
 static int pakfire_transaction_append_problems(
-               struct pakfire_transaction* transaction, char** buffer, struct pakfire_problem** problems, int flags) {
+               struct pakfire_transaction* transaction, char** buffer, pakfire_problem** problems, int flags) {
        struct pakfire_solution** solutions = NULL;
        const char* s = NULL;
        int r;
 
-       for (struct pakfire_problem** problem = problems; *problem; problem++) {
+       for (pakfire_problem** problem = problems; *problem; problem++) {
                s = pakfire_problem_to_string(*problem);
                if (!s)
                        return -errno;
@@ -545,7 +545,7 @@ static int pakfire_transaction_append_problems(
 
 static char* pakfire_transaction_get_problem_string(
                struct pakfire_transaction* transaction, int flags) {
-       struct pakfire_problem** problems = NULL;
+       pakfire_problem** problems = NULL;
        char* buffer = NULL;
        int r;
 
@@ -565,7 +565,7 @@ static char* pakfire_transaction_get_problem_string(
 
                // Cleanup
                if (problems) {
-                       for (struct pakfire_problem** problem = problems; *problem; problem++)
+                       for (pakfire_problem** problem = problems; *problem; problem++)
                                pakfire_problem_unref(*problem);
 
                        free(problems);
@@ -871,7 +871,7 @@ int pakfire_transaction_request_package(struct pakfire_transaction* transaction,
 
 int pakfire_transaction_take_solution(struct pakfire_transaction* transaction,
                struct pakfire_solution* solution) {
-       struct pakfire_problem* problem = pakfire_solution_get_problem(solution);
+       pakfire_problem* problem = pakfire_solution_get_problem(solution);
 
        // Fetch IDs
        Id problem_id = pakfire_problem_get_id(problem);
index ae608334def958b58ba12f95b182e40cb4d744ac..fa5db0f0266c65e0ebdc7b046b2e96b5ca2158e1 100644 (file)
@@ -72,7 +72,7 @@ int pakfire_transaction_request(struct pakfire_transaction* transaction,
 int pakfire_transaction_request_package(struct pakfire_transaction* transaction,
        const enum pakfire_job_action action, pakfire_package* package, int flags);
 
-struct pakfire_problem** pakfire_transaction_get_problems(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);
 
index 1b8a6b1e1bdf82a70fc1330cb97ee3bd6214bfe4..96edae520c2f5ec075fd978893114f4c64083d59 100644 (file)
@@ -27,7 +27,7 @@
 #include "problem.h"
 #include "solution.h"
 
-static ProblemObject* Problem_new_core(PyTypeObject* type, struct pakfire_problem* problem) {
+static ProblemObject* Problem_new_core(PyTypeObject* type, pakfire_problem* problem) {
        ProblemObject* self = (ProblemObject *)type->tp_alloc(type, 0);
        if (self) {
                self->problem = problem;
@@ -36,7 +36,7 @@ static ProblemObject* Problem_new_core(PyTypeObject* type, struct pakfire_proble
        return self;
 }
 
-PyObject* new_problem(struct pakfire_problem* problem) {
+PyObject* new_problem(pakfire_problem* problem) {
        ProblemObject* p = Problem_new_core(&ProblemType, problem);
 
        return (PyObject*)p;
index ca581ad5bf611c0168588f9ac05566115ee2658d..86fb7f0b931b6324b381ccd4c7df6bbf7c33e7c2 100644 (file)
 
 typedef struct {
        PyObject_HEAD
-       struct pakfire_problem* problem;
+       pakfire_problem* problem;
 } ProblemObject;
 
 extern PyTypeObject ProblemType;
 
-PyObject* new_problem(struct pakfire_problem* problem);
+PyObject* new_problem(pakfire_problem* problem);
 
 #endif /* PYTHON_PAKFIRE_PROBLEM_H */