From 843fcc66a4ddf4e235a4039ae1f5cd9654c74c51 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 15 Jan 2018 19:59:01 +0100 Subject: [PATCH] libpakfire: Make Pakfire parent object of Repo This allows us to phase out the Pool object Signed-off-by: Michael Tremer --- src/_pakfire/package.c | 3 +- src/_pakfire/package.h | 2 + src/_pakfire/pakfire.c | 39 +++++++++++++++ src/_pakfire/pool.c | 38 --------------- src/_pakfire/pool.h | 3 -- src/_pakfire/repo.c | 23 ++++----- src/_pakfire/repo.h | 12 ++--- src/libpakfire/include/pakfire/pakfire.h | 3 ++ src/libpakfire/include/pakfire/pool.h | 3 -- src/libpakfire/include/pakfire/repo.h | 6 +-- src/libpakfire/include/pakfire/repocache.h | 2 +- src/libpakfire/libpakfire.sym | 5 +- src/libpakfire/pakfire.c | 22 +++++++++ src/libpakfire/pool.c | 18 ------- src/libpakfire/repo.c | 55 ++++++++++++++++------ src/pakfire/repository/__init__.py | 2 +- src/pakfire/repository/base.py | 2 +- 17 files changed, 133 insertions(+), 105 deletions(-) diff --git a/src/_pakfire/package.c b/src/_pakfire/package.c index 42027ba95..3be41aee0 100644 --- a/src/_pakfire/package.c +++ b/src/_pakfire/package.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "package.h" @@ -458,7 +459,7 @@ static PyObject* Package_get_repo(PackageObject* self) { const char* name = pakfire_repo_get_name(repo); pakfire_repo_unref(repo); - return new_repo(self->pool, name); + return new_repo(self->pakfire, name); } static int Package_set_repo(PackageObject* self, PyObject* value) { diff --git a/src/_pakfire/package.h b/src/_pakfire/package.h index 530dbb09e..d88c8cd49 100644 --- a/src/_pakfire/package.h +++ b/src/_pakfire/package.h @@ -26,10 +26,12 @@ #include #include +#include "pakfire.h" #include "pool.h" typedef struct { PyObject_HEAD + PakfireObject* pakfire; PoolObject* pool; PakfirePackage package; } PackageObject; diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c index bdcc3a92b..dd0c8bcfd 100644 --- a/src/_pakfire/pakfire.c +++ b/src/_pakfire/pakfire.c @@ -22,9 +22,11 @@ #include #include +#include #include "key.h" #include "pakfire.h" +#include "repo.h" static PyObject* Pakfire_new(PyTypeObject* type, PyObject* args, PyObject* kwds) { PakfireObject* self = (PakfireObject *)type->tp_alloc(type, 0); @@ -75,6 +77,36 @@ static PyObject* Pakfire_get_arch(PakfireObject* self) { return PyUnicode_FromString(arch); } +static PyObject* Pakfire_get_installed_repo(PakfireObject* self) { + PakfireRepo repo = pakfire_get_installed_repo(self->pakfire); + if (!repo) + Py_RETURN_NONE; + + PyObject* obj = new_repo(self, pakfire_repo_get_name(repo)); + Py_XINCREF(obj); + + return obj; +} + +static int Pakfire_set_installed_repo(PakfireObject* self, PyObject* value) { +#if 0 + if (PyObject_Not(value)) { + pakfire_pool_set_installed_repo(self->pool, NULL); + return 0; + } +#endif + + if (!PyObject_TypeCheck(value, &RepoType)) { + PyErr_SetString(PyExc_ValueError, "Argument must be a _pakfire.Repo object"); + return -1; + } + + RepoObject* repo = (RepoObject *)value; + pakfire_set_installed_repo(self->pakfire, repo->repo); + + return 0; +} + static PyObject* _import_keylist(PakfireObject* pakfire, PakfireKey* keys) { PyObject* list = PyList_New(0); @@ -168,6 +200,13 @@ static struct PyGetSetDef Pakfire_getsetters[] = { NULL, NULL }, + { + "installed_repo", + (getter)Pakfire_get_installed_repo, + (setter)Pakfire_set_installed_repo, + NULL, + NULL + }, { "keys", (getter)Pakfire_get_keys, diff --git a/src/_pakfire/pool.c b/src/_pakfire/pool.c index 6d09e5f06..4f4f1f9a9 100644 --- a/src/_pakfire/pool.c +++ b/src/_pakfire/pool.c @@ -32,7 +32,6 @@ #include "pakfire.h" #include "pool.h" #include "relation.h" -#include "repo.h" #include "util.h" static PyObject* Pool_new(PyTypeObject* type, PyObject* args, PyObject* kwds) { @@ -79,36 +78,6 @@ static Py_ssize_t Pool_len(PoolObject* self) { return pakfire_pool_count(self->pool); } -static PyObject* Pool_get_installed_repo(PoolObject* self) { - PakfireRepo repo = pakfire_pool_get_installed_repo(self->pool); - if (!repo) - Py_RETURN_NONE; - - PyObject* obj = new_repo(self, pakfire_repo_get_name(repo)); - Py_XINCREF(obj); - - return obj; -} - -static int Pool_set_installed_repo(PoolObject* self, PyObject* value) { -#if 0 - if (PyObject_Not(value)) { - pakfire_pool_set_installed_repo(self->pool, NULL); - return 0; - } -#endif - - if (!PyObject_TypeCheck(value, &RepoType)) { - PyErr_SetString(PyExc_ValueError, "Argument must be a _pakfire.Repo object"); - return -1; - } - - RepoObject* repo = (RepoObject *)value; - pakfire_pool_set_installed_repo(self->pool, repo->repo); - - return 0; -} - static PyObject* Pool_get_installonly(PoolObject* self) { const char** installonly = pakfire_pool_get_installonly(self->pool); @@ -228,13 +197,6 @@ static struct PyGetSetDef Pool_getsetters[] = { NULL, NULL }, - { - "installed_repo", - (getter)Pool_get_installed_repo, - (setter)Pool_set_installed_repo, - NULL, - NULL - }, { "installonly", (getter)Pool_get_installonly, diff --git a/src/_pakfire/pool.h b/src/_pakfire/pool.h index a4a135212..80f90e7c1 100644 --- a/src/_pakfire/pool.h +++ b/src/_pakfire/pool.h @@ -28,9 +28,6 @@ typedef struct { PyObject_HEAD PakfirePool pool; - - // XXX COMPAT - Pool* _pool; } PoolObject; extern PyTypeObject PoolType; diff --git a/src/_pakfire/repo.c b/src/_pakfire/repo.c index 25d5d19a9..11669b63b 100644 --- a/src/_pakfire/repo.c +++ b/src/_pakfire/repo.c @@ -29,8 +29,8 @@ #include "package.h" #include "repo.h" -PyObject* new_repo(PoolObject* pool, const char* name) { - PyObject* args = Py_BuildValue("Os", (PyObject *)pool, name); +PyObject* new_repo(PakfireObject* pakfire, const char* name) { + PyObject* args = Py_BuildValue("Os", (PyObject *)pakfire, name); PyObject* repo = PyObject_CallObject((PyObject *)&RepoType, args); Py_DECREF(args); @@ -41,7 +41,7 @@ PyObject* new_repo(PoolObject* pool, const char* name) { static PyObject* Repo_new(PyTypeObject* type, PyObject* args, PyObject* kwds) { RepoObject* self = (RepoObject *)type->tp_alloc(type, 0); if (self) { - self->pool = NULL; + self->pakfire = NULL; self->repo = NULL; } @@ -51,21 +51,21 @@ static PyObject* Repo_new(PyTypeObject* type, PyObject* args, PyObject* kwds) { static void Repo_dealloc(RepoObject* self) { pakfire_repo_unref(self->repo); - Py_XDECREF(self->pool); + Py_XDECREF(self->pakfire); Py_TYPE(self)->tp_free((PyObject *)self); } static int Repo_init(RepoObject* self, PyObject* args, PyObject* kwds) { - PyObject* pool; + PakfireObject* pakfire; const char* name; - if (!PyArg_ParseTuple(args, "O!s", &PoolType, &pool, &name)) + if (!PyArg_ParseTuple(args, "O!s", &PakfireType, &pakfire, &name)) return -1; - self->pool = (PoolObject *)pool; - Py_INCREF(self->pool); + self->pakfire = pakfire; + Py_INCREF(self->pakfire); - self->repo = pakfire_repo_create(self->pool->pool, name); + self->repo = pakfire_repo_create(self->pakfire->pakfire, name); return 0; } @@ -220,10 +220,11 @@ static PyObject* Repo__add_package(RepoObject* self, PyObject* args) { if (!PyArg_ParseTuple(args, "sss", &name, &evr, &arch)) return NULL; - PakfirePool pool = pakfire_repo_pool(self->repo); + PakfirePool pool = pakfire_repo_get_pool(self->repo); PakfirePackage pkg = pakfire_package_create2(pool, self->repo, name, evr, arch); - return new_package(self->pool, pakfire_package_id(pkg)); + // XXX must be self->pakfire instead of NULL + return new_package(NULL /* self->pakfire */, pakfire_package_id(pkg)); } static PyObject* Repo_cache_age(RepoObject* self, PyObject* args) { diff --git a/src/_pakfire/repo.h b/src/_pakfire/repo.h index 5780a7c73..ecda9a28c 100644 --- a/src/_pakfire/repo.h +++ b/src/_pakfire/repo.h @@ -23,22 +23,18 @@ #include -#include -#include +#include -#include "pool.h" +#include "pakfire.h" typedef struct { PyObject_HEAD - PoolObject* pool; + PakfireObject* pakfire; PakfireRepo repo; - - // XXX COMPAT - void* _repo; } RepoObject; extern PyTypeObject RepoType; -PyObject* new_repo(PoolObject* pool, const char* name); +PyObject* new_repo(PakfireObject* pakfire, const char* name); #endif /* PYTHON_PAKFIRE_REPO_H */ diff --git a/src/libpakfire/include/pakfire/pakfire.h b/src/libpakfire/include/pakfire/pakfire.h index e56a0ed79..e62dc73a4 100644 --- a/src/libpakfire/include/pakfire/pakfire.h +++ b/src/libpakfire/include/pakfire/pakfire.h @@ -35,4 +35,7 @@ const char* pakfire_get_arch(Pakfire pakfire); PakfirePool pakfire_get_pool(Pakfire pakfire); +PakfireRepo pakfire_get_installed_repo(Pakfire pakfire); +void pakfire_set_installed_repo(Pakfire pakfire, PakfireRepo repo); + #endif /* PAKFIRE_PAKFIRE_H */ diff --git a/src/libpakfire/include/pakfire/pool.h b/src/libpakfire/include/pakfire/pool.h index bc96543e8..8ba4f2b36 100644 --- a/src/libpakfire/include/pakfire/pool.h +++ b/src/libpakfire/include/pakfire/pool.h @@ -30,9 +30,6 @@ 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); -PakfireRepo pakfire_pool_get_installed_repo(PakfirePool pool); -void pakfire_pool_set_installed_repo(PakfirePool pool, PakfireRepo repo); - const char** pakfire_pool_get_installonly(PakfirePool pool); void pakfire_pool_set_installonly(PakfirePool pool, const char** installonly); diff --git a/src/libpakfire/include/pakfire/repo.h b/src/libpakfire/include/pakfire/repo.h index 9c00d860a..baf985205 100644 --- a/src/libpakfire/include/pakfire/repo.h +++ b/src/libpakfire/include/pakfire/repo.h @@ -23,12 +23,12 @@ #include -PakfireRepo pakfire_repo_create(PakfirePool pool, const char* name); +PakfireRepo pakfire_repo_create(Pakfire pakfire, const char* name); PakfireRepo pakfire_repo_ref(PakfireRepo repo); PakfireRepo pakfire_repo_unref(PakfireRepo repo); -PakfirePool pakfire_repo_pool(PakfireRepo repo); +PakfirePool pakfire_repo_get_pool(PakfireRepo repo); int pakfire_repo_identical(PakfireRepo repo1, PakfireRepo repo2); int pakfire_repo_cmp(PakfireRepo repo1, PakfireRepo repo2); @@ -61,7 +61,7 @@ int pakfire_repo_clean(PakfireRepo repo); #include -PakfireRepo pakfire_repo_create_from_repo(PakfirePool pool, Repo* r); +PakfireRepo pakfire_repo_create_from_repo(Pakfire pakfire, Repo* r); PakfirePackage pakfire_repo_add_package(PakfireRepo repo); diff --git a/src/libpakfire/include/pakfire/repocache.h b/src/libpakfire/include/pakfire/repocache.h index 19824165e..02f5307ae 100644 --- a/src/libpakfire/include/pakfire/repocache.h +++ b/src/libpakfire/include/pakfire/repocache.h @@ -46,7 +46,7 @@ struct _PakfireRepoCache { }; inline PakfirePool pakfire_repocache_pool(PakfireRepoCache repo_cache) { - return pakfire_repo_pool(repo_cache->repo); + return pakfire_repo_get_pool(repo_cache->repo); } inline PakfireCache pakfire_repocache_cache(PakfireRepoCache repo_cache) { diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index 5ab0b22e6..687692099 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -24,9 +24,11 @@ global: pakfire_init; pakfire_create; pakfire_get_arch; + pakfire_get_installed_repo; pakfire_get_path; pakfire_get_pool; pakfire_ref; + pakfire_set_installed_repo; pakfire_unref; # archive @@ -198,12 +200,10 @@ global: pakfire_pool_count; pakfire_pool_create; 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; @@ -226,6 +226,7 @@ global: pakfire_repo_get_cache; pakfire_repo_get_name; pakfire_repo_get_enabled; + pakfire_repo_get_pool; pakfire_repo_get_priority; pakfire_repo_identical; pakfire_repo_internalize; diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 89675a80a..a65c1e004 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -18,10 +18,13 @@ # # #############################################################################*/ +#include + #include #include #include #include +#include #include #include #include @@ -96,3 +99,22 @@ PAKFIRE_EXPORT const char* pakfire_get_arch(Pakfire pakfire) { PAKFIRE_EXPORT PakfirePool pakfire_get_pool(Pakfire pakfire) { return pakfire_pool_ref(pakfire->pool); } + +PAKFIRE_EXPORT PakfireRepo pakfire_get_installed_repo(Pakfire pakfire) { + Pool* p = pakfire_pool_get_solv_pool(pakfire->pool); + if (!p->installed) + return NULL; + + return pakfire_repo_create_from_repo(pakfire, p->installed); +} + +PAKFIRE_EXPORT void pakfire_set_installed_repo(Pakfire pakfire, PakfireRepo repo) { + Pool* p = pakfire_pool_get_solv_pool(pakfire->pool); + + if (!repo) { + pool_set_installed(p, NULL); + return; + } + + pool_set_installed(p, pakfire_repo_get_repo(repo)); +} diff --git a/src/libpakfire/pool.c b/src/libpakfire/pool.c index 6ad59bd91..6bbf4f719 100644 --- a/src/libpakfire/pool.c +++ b/src/libpakfire/pool.c @@ -136,24 +136,6 @@ void pakfire_pool_apply_changes(PakfirePool pool) { } } -PAKFIRE_EXPORT PakfireRepo pakfire_pool_get_installed_repo(PakfirePool pool) { - Pool* p = pool->pool; - - if (!p->installed) - return NULL; - - return pakfire_repo_create_from_repo(pool, p->installed); -} - -PAKFIRE_EXPORT void pakfire_pool_set_installed_repo(PakfirePool pool, PakfireRepo repo) { - if (!repo) { - pool_set_installed(pool->pool, NULL); - return; - } - - pool_set_installed(pool->pool, pakfire_repo_get_repo(repo)); -} - PAKFIRE_EXPORT const char** pakfire_pool_get_installonly(PakfirePool pool) { Queue q; queue_init_clone(&q, &pool->installonly); diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index bab4435fe..518fc2ff0 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -44,7 +45,7 @@ const uint8_t XZ_HEADER_MAGIC[] = { 0xFD, '7', 'z', 'X', 'Z', 0x00 }; const size_t XZ_HEADER_LENGTH = sizeof(XZ_HEADER_MAGIC); struct _PakfireRepo { - PakfirePool pool; + Pakfire pakfire; Repo* repo; PakfireRepoCache cache; Repodata* filelist; @@ -74,23 +75,29 @@ static PakfireRepo get_pakfire_repo_by_name(PakfirePool pool, const char* name) return NULL; } -PAKFIRE_EXPORT PakfireRepo pakfire_repo_create(PakfirePool pool, const char* name) { +PAKFIRE_EXPORT PakfireRepo pakfire_repo_create(Pakfire pakfire, const char* name) { + PakfirePool pool = pakfire_get_pool(pakfire); + PakfireRepo repo = get_pakfire_repo_by_name(pool, name); if (repo) { repo->nrefs++; + + pakfire_pool_unref(pool); + return repo; } Pool* p = pakfire_pool_get_solv_pool(pool); + pakfire_pool_unref(pool); Repo* r = get_repo_by_name(p, name); if (!r) r = repo_create(p, name); - return pakfire_repo_create_from_repo(pool, r); + return pakfire_repo_create_from_repo(pakfire, r); } -PAKFIRE_EXPORT PakfireRepo pakfire_repo_create_from_repo(PakfirePool pool, Repo* r) { +PAKFIRE_EXPORT PakfireRepo pakfire_repo_create_from_repo(Pakfire pakfire, Repo* r) { // Return existing object if we have one if (r->appdata) return pakfire_repo_ref(r->appdata); @@ -100,7 +107,7 @@ PAKFIRE_EXPORT PakfireRepo pakfire_repo_create_from_repo(PakfirePool pool, Repo* DEBUG("Allocated Repo at %p\n", repo); repo->nrefs = 1; - repo->pool = pakfire_pool_ref(pool); + repo->pakfire = pakfire_ref(pakfire); repo->repo = r; repo->cache = pakfire_repocache_create(repo); @@ -124,7 +131,7 @@ static void pakfire_repo_free(PakfireRepo repo) { if (repo->cache) pakfire_repocache_free(repo->cache); - pakfire_pool_unref(repo->pool); + pakfire_unref(repo->pakfire); pakfire_free(repo); DEBUG("Released Repo at %p\n", repo); @@ -149,8 +156,17 @@ Repodata* pakfire_repo_get_repodata(PakfireRepo repo) { return repo->filelist; } -PAKFIRE_EXPORT PakfirePool pakfire_repo_pool(PakfireRepo repo) { - return repo->pool; +PAKFIRE_EXPORT PakfirePool pakfire_repo_get_pool(PakfireRepo repo) { + return pakfire_get_pool(repo->pakfire); +} + +static Pool* pakfire_repo_get_solv_pool(PakfireRepo repo) { + PakfirePool pool = pakfire_repo_get_pool(repo); + + Pool* p = pakfire_pool_get_solv_pool(pool); + pakfire_pool_unref(pool); + + return p; } PAKFIRE_EXPORT int pakfire_repo_identical(PakfireRepo repo1, PakfireRepo repo2) { @@ -174,7 +190,7 @@ PAKFIRE_EXPORT int pakfire_repo_cmp(PakfireRepo repo1, PakfireRepo repo2) { } PAKFIRE_EXPORT int pakfire_repo_count(PakfireRepo repo) { - Pool* pool = pakfire_pool_get_solv_pool(repo->pool); + Pool* pool = pakfire_repo_get_solv_pool(repo); int cnt = 0; for (int i = 2; i < pool->nsolvables; i++) { @@ -205,8 +221,9 @@ PAKFIRE_EXPORT int pakfire_repo_get_enabled(PakfireRepo repo) { PAKFIRE_EXPORT void pakfire_repo_set_enabled(PakfireRepo repo, int enabled) { repo->repo->disabled = !enabled; - PakfirePool pool = pakfire_repo_pool(repo); + PakfirePool pool = pakfire_repo_get_pool(repo); pakfire_pool_has_changed(pool); + pakfire_pool_unref(pool); } PAKFIRE_EXPORT int pakfire_repo_get_priority(PakfireRepo repo) { @@ -218,11 +235,13 @@ PAKFIRE_EXPORT void pakfire_repo_set_priority(PakfireRepo repo, int priority) { } PAKFIRE_EXPORT int pakfire_repo_is_installed_repo(PakfireRepo repo) { - PakfirePool pool = pakfire_repo_pool(repo); + PakfireRepo installed_repo = pakfire_get_installed_repo(repo->pakfire); + + int r = pakfire_repo_identical(repo, installed_repo); - PakfireRepo installed_repo = pakfire_pool_get_installed_repo(pool); + pakfire_repo_unref(installed_repo); - return pakfire_repo_identical(repo, installed_repo); + return r; } PAKFIRE_EXPORT int pakfire_repo_read_solv(PakfireRepo repo, const char* filename, int flags) { @@ -384,7 +403,9 @@ PAKFIRE_EXPORT int pakfire_repo_read_solv_fp(PakfireRepo repo, FILE *f, int flag return PAKFIRE_E_SOLV_CORRUPTED; } - pakfire_pool_has_changed(repo->pool); + PakfirePool pool = pakfire_get_pool(repo->pakfire); + pakfire_pool_has_changed(pool); + pakfire_pool_unref(pool); return ret; } @@ -410,7 +431,11 @@ PAKFIRE_EXPORT int pakfire_repo_write_solv_fp(PakfireRepo repo, FILE *f, int fla PAKFIRE_EXPORT PakfirePackage pakfire_repo_add_package(PakfireRepo repo) { Id id = repo_add_solvable(repo->repo); - return pakfire_package_create(repo->pool, id); + PakfirePool pool = pakfire_get_pool(repo->pakfire); + PakfirePackage pkg = pakfire_package_create(pool, id); + pakfire_pool_unref(pool); + + return pkg; } PAKFIRE_EXPORT PakfireRepoCache pakfire_repo_get_cache(PakfireRepo repo) { diff --git a/src/pakfire/repository/__init__.py b/src/pakfire/repository/__init__.py index 3d2098ad8..1cbcb1ed8 100644 --- a/src/pakfire/repository/__init__.py +++ b/src/pakfire/repository/__init__.py @@ -54,7 +54,7 @@ class Repositories(object): self.dummy = base.RepositoryDummy(self.pakfire) # Create the local repository. - self.local = self.pool.installed_repo = RepositorySystem(self.pakfire) + self.local = self.pakfire.installed_repo = RepositorySystem(self.pakfire) self.add_repo(self.local) # If we running in build mode, we include our local build repository. diff --git a/src/pakfire/repository/base.py b/src/pakfire/repository/base.py index 52e697e14..ea56d0eb0 100644 --- a/src/pakfire/repository/base.py +++ b/src/pakfire/repository/base.py @@ -31,7 +31,7 @@ class RepositoryFactory(_pakfire.Repo): self.pakfire = pakfire # Inherit - _pakfire.Repo.__init__(self, self.pakfire.pool, name) + _pakfire.Repo.__init__(self, self.pakfire, name) # Save description self.description = description -- 2.39.5