From: Michael Tremer Date: Fri, 25 Oct 2024 13:48:31 +0000 (+0000) Subject: problem: Minor code cleanups X-Git-Tag: 0.9.30~889 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=00f4e6a1aac6deb428daf2d9821b5b87ebaefa68;p=pakfire.git problem: Minor code cleanups Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/problem.c b/src/libpakfire/problem.c index f9fd46042..3d3b87ae6 100644 --- a/src/libpakfire/problem.c +++ b/src/libpakfire/problem.c @@ -21,9 +21,6 @@ #include #include -// Enable legacy logging -#define PAKFIRE_LEGACY_LOGGING - #include #include #include @@ -196,28 +193,35 @@ static char* pakfire_problem_make_string(struct pakfire_problem* problem) { int pakfire_problem_create(struct pakfire_problem** problem, struct pakfire* pakfire, struct pakfire_transaction* transaction, Id id) { - struct pakfire_problem* p = calloc(1, sizeof(*p)); + struct pakfire_problem* p = NULL; + + // Allocate some memory + p = calloc(1, sizeof(*p)); if (!p) - return 1; + return -errno; + // Store a reference to the context p->ctx = pakfire_ctx(pakfire); + + // Store a reference to Pakfire p->pakfire = pakfire_ref(pakfire); + + // Initialize the reference counter p->nrefs = 1; + // Store a reference to the transaction p->transaction = pakfire_transaction_ref(transaction); + + // Store the ID p->id = id; // Fetch a reference to the solver p->solver = pakfire_transaction_get_solver(transaction); + // Return the pointer *problem = p; - return 0; -} - -PAKFIRE_EXPORT struct pakfire_problem* pakfire_problem_ref(struct pakfire_problem* problem) { - problem->nrefs++; - return problem; + return 0; } static void pakfire_problem_free(struct pakfire_problem* problem) { @@ -232,6 +236,12 @@ static void pakfire_problem_free(struct pakfire_problem* problem) { free(problem); } +PAKFIRE_EXPORT struct pakfire_problem* pakfire_problem_ref(struct pakfire_problem* problem) { + problem->nrefs++; + + return problem; +} + PAKFIRE_EXPORT struct pakfire_problem* pakfire_problem_unref(struct pakfire_problem* problem) { if (--problem->nrefs > 0) return problem;