]> git.ipfire.org Git - pakfire.git/commitdiff
problem: Minor code cleanups
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 25 Oct 2024 13:48:31 +0000 (13:48 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 25 Oct 2024 13:48:31 +0000 (13:48 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/problem.c

index f9fd46042eed69981a8fa724f5bd5995cc623677..3d3b87ae63460dc06af1aea21ae75e5b681942b4 100644 (file)
@@ -21,9 +21,6 @@
 #include <errno.h>
 #include <stdlib.h>
 
-// Enable legacy logging
-#define PAKFIRE_LEGACY_LOGGING
-
 #include <pakfire/constants.h>
 #include <pakfire/ctx.h>
 #include <pakfire/dependencies.h>
@@ -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;