From: Michael Tremer Date: Thu, 23 Nov 2017 17:56:14 +0000 (+0100) Subject: libpakfire: Always add a pool to Pakfire X-Git-Tag: 0.9.28~1285^2~1292 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af2ad1e0d981783df7c55ebeb301b6f99029a3d8;p=pakfire.git libpakfire: Always add a pool to Pakfire Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/pool.c b/src/_pakfire/pool.c index 3c0fc8206..5061f908b 100644 --- a/src/_pakfire/pool.c +++ b/src/_pakfire/pool.c @@ -24,10 +24,12 @@ #include #include +#include #include #include #include "constants.h" +#include "pakfire.h" #include "pool.h" #include "relation.h" #include "repo.h" @@ -45,25 +47,20 @@ static PyObject* Pool_new(PyTypeObject* type, PyObject* args, PyObject* kwds) { static void Pool_dealloc(PoolObject* self) { if (self->pool) - pakfire_pool_free(self->pool); + pakfire_pool_unref(self->pool); Py_TYPE(self)->tp_free((PyObject *)self); } static int Pool_init(PoolObject* self, PyObject* args, PyObject* kwds) { - const char* arch; + PakfireObject* pakfire = NULL; - if (!PyArg_ParseTuple(args, "s", &arch)) + if (!PyArg_ParseTuple(args, "O!", &PakfireType, &pakfire)) return -1; - self->pool = pakfire_pool_create(arch); - if (self->pool == NULL) { - switch(pakfire_get_errno()) { - default: - assert(0); - } + self->pool = pakfire_get_pool(pakfire->pakfire); + if (!self->pool) return -1; - } return 0; } diff --git a/src/libpakfire/include/pakfire/pakfire.h b/src/libpakfire/include/pakfire/pakfire.h index ce81b3fb9..0ba4b276d 100644 --- a/src/libpakfire/include/pakfire/pakfire.h +++ b/src/libpakfire/include/pakfire/pakfire.h @@ -31,11 +31,14 @@ void pakfire_unref(Pakfire pakfire); const char* pakfire_get_path(Pakfire pakfire); const char* pakfire_get_arch(Pakfire pakfire); +PakfirePool pakfire_get_pool(Pakfire pakfire); + #ifdef PAKFIRE_PRIVATE struct _Pakfire { - char* path; - char* arch; + char* path; + char* arch; + PakfirePool pool; int nrefs; }; diff --git a/src/libpakfire/include/pakfire/pool.h b/src/libpakfire/include/pakfire/pool.h index 0613879ca..e99719822 100644 --- a/src/libpakfire/include/pakfire/pool.h +++ b/src/libpakfire/include/pakfire/pool.h @@ -25,8 +25,9 @@ #include -PakfirePool pakfire_pool_create(const char* arch); -void pakfire_pool_free(PakfirePool pool); +PakfirePool pakfire_pool_create(Pakfire pakfire); +PakfirePool pakfire_pool_ref(PakfirePool pool); +void pakfire_pool_unref(PakfirePool pool); int pakfire_pool_version_compare(PakfirePool pool, const char* evr1, const char* evr2); int pakfire_pool_count(PakfirePool pool); @@ -52,6 +53,7 @@ struct _PakfirePool { Queue installonly; PakfireCache cache; + int nrefs; }; void pakfire_pool_make_provides_ready(PakfirePool pool); diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index 42172ad67..abd048723 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -24,6 +24,7 @@ global: pakfire_create; pakfire_get_arch; pakfire_get_path; + pakfire_get_pool; pakfire_ref; pakfire_unref; @@ -165,14 +166,15 @@ global: # pool pakfire_pool_count; pakfire_pool_create; - pakfire_pool_free; pakfire_pool_get_cache_path; pakfire_pool_get_installed_repo; pakfire_pool_get_installonly; + pakfire_pool_ref; pakfire_pool_search; pakfire_pool_set_cache_path; pakfire_pool_set_installed_repo; pakfire_pool_set_installonly; + pakfire_pool_unref; pakfire_pool_version_compare; pakfire_pool_whatprovides; diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index c2b2c10ec..3c38df967 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -19,38 +19,50 @@ #############################################################################*/ #include +#include #include #include Pakfire pakfire_create(const char* path, const char* arch) { - Pakfire pakfire = pakfire_calloc(1, sizeof(*pakfire)); - if (pakfire) { - pakfire->path = pakfire_strdup(path); - pakfire->arch = pakfire_strdup(arch); - } + Pakfire pakfire = pakfire_calloc(1, sizeof(*pakfire)); + if (pakfire) { + pakfire->nrefs = 1; - return pakfire; + pakfire->path = pakfire_strdup(path); + pakfire->arch = pakfire_strdup(arch); + + // Initialize the pool + pakfire->pool = pakfire_pool_create(pakfire); + } + + return pakfire; } Pakfire pakfire_ref(Pakfire pakfire) { - ++pakfire->nrefs; + ++pakfire->nrefs; - return pakfire; + return pakfire; } void pakfire_unref(Pakfire pakfire) { - if (--pakfire->nrefs > 0) - return; + if (--pakfire->nrefs > 0) + return; + + pakfire_pool_unref(pakfire->pool); - pakfire_free(pakfire->path); - pakfire_free(pakfire->arch); - pakfire_free(pakfire); + pakfire_free(pakfire->path); + pakfire_free(pakfire->arch); + pakfire_free(pakfire); } const char* pakfire_get_path(Pakfire pakfire) { - return pakfire->path; + return pakfire->path; } const char* pakfire_get_arch(Pakfire pakfire) { - return pakfire->arch; + return pakfire->arch; +} + +PakfirePool pakfire_get_pool(Pakfire pakfire) { + return pakfire_pool_ref(pakfire->pool); } diff --git a/src/libpakfire/pool.c b/src/libpakfire/pool.c index 26e2460b4..a81c25a3a 100644 --- a/src/libpakfire/pool.c +++ b/src/libpakfire/pool.c @@ -29,18 +29,23 @@ #include #include #include +#include #include #include #include #include -PakfirePool pakfire_pool_create(const char* arch) { +PakfirePool pakfire_pool_create(Pakfire pakfire) { PakfirePool pool = pakfire_calloc(1, sizeof(*pool)); + if (pool) { + pool->nrefs = 1; + } pool->pool = pool_create(); queue_init(&pool->installonly); // Set architecture + const char* arch = pakfire_get_arch(pakfire); pool_setarch(pool->pool, arch); return pool; @@ -59,7 +64,7 @@ static void pakfire_pool_free_repos(Pool* pool) { } } -void pakfire_pool_free(PakfirePool pool) { +static void pakfire_pool_free(PakfirePool pool) { pakfire_pool_free_repos(pool->pool); queue_free(&pool->installonly); @@ -68,6 +73,19 @@ void pakfire_pool_free(PakfirePool pool) { pakfire_free(pool); } +PakfirePool pakfire_pool_ref(PakfirePool pool) { + ++pool->nrefs; + + return pool; +} + +void pakfire_pool_unref(PakfirePool pool) { + if (--pool->nrefs > 0) + return; + + pakfire_pool_free(pool); +} + int pakfire_pool_version_compare(PakfirePool pool, const char* evr1, const char* evr2) { return pool_evrcmp_str(pool->pool, evr1, evr2, EVRCMP_COMPARE); } diff --git a/src/pakfire/base.py b/src/pakfire/base.py index 33024fa2a..21e5c8e38 100644 --- a/src/pakfire/base.py +++ b/src/pakfire/base.py @@ -64,7 +64,7 @@ class Pakfire(_pakfire.Pakfire): # Initialize the keyring #self.keyring = keyring.Keyring(self) - self.pool = _pakfire.Pool(self.arch) + self.pool = _pakfire.Pool(self) self.pool.cache_path = cache_path or \ os.path.join(CACHE_DIR, self.distro.sname, self.distro.release)