From: Michael Tremer Date: Fri, 27 Jun 2025 14:36:29 +0000 (+0000) Subject: problem: Create its own type X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dffb2e73bc1de56b1f420b6713bf391d5031755a;p=pakfire.git problem: Create its own type Signed-off-by: Michael Tremer --- diff --git a/src/cli/lib/terminal.c b/src/cli/lib/terminal.c index a4cda59f..4a856976 100644 --- a/src/cli/lib/terminal.c +++ b/src/cli/lib/terminal.c @@ -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); diff --git a/src/pakfire/problem.c b/src/pakfire/problem.c index 9cbdc70a..2613c1bb 100644 --- a/src/pakfire/problem.c +++ b/src/pakfire/problem.c @@ -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; diff --git a/src/pakfire/problem.h b/src/pakfire/problem.h index 3b75ad87..8e04a7e4 100644 --- a/src/pakfire/problem.h +++ b/src/pakfire/problem.h @@ -24,24 +24,24 @@ // libsolv #include -struct pakfire_problem; +typedef struct pakfire_problem pakfire_problem; #include #include -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 */ diff --git a/src/pakfire/solution.c b/src/pakfire/solution.c index c4785b10..9593b033 100644 --- a/src/pakfire/solution.c +++ b/src/pakfire/solution.c @@ -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); } diff --git a/src/pakfire/solution.h b/src/pakfire/solution.h index 78c5b417..5cbfd7b3 100644 --- a/src/pakfire/solution.h +++ b/src/pakfire/solution.h @@ -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 */ diff --git a/src/pakfire/transaction.c b/src/pakfire/transaction.c index e687df28..dfe32d5a 100644 --- a/src/pakfire/transaction.c +++ b/src/pakfire/transaction.c @@ -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); diff --git a/src/pakfire/transaction.h b/src/pakfire/transaction.h index ae608334..fa5db0f0 100644 --- a/src/pakfire/transaction.h +++ b/src/pakfire/transaction.h @@ -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); diff --git a/src/python/problem.c b/src/python/problem.c index 1b8a6b1e..96edae52 100644 --- a/src/python/problem.c +++ b/src/python/problem.c @@ -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; diff --git a/src/python/problem.h b/src/python/problem.h index ca581ad5..86fb7f0b 100644 --- a/src/python/problem.h +++ b/src/python/problem.h @@ -27,11 +27,11 @@ 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 */