From: Michael Tremer Date: Thu, 30 Nov 2017 18:36:36 +0000 (+0100) Subject: libpakfire: Make PakfirePool obscure X-Git-Tag: 0.9.28~1285^2~1219 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f1c7996e0a912f3eec826535487c3a360be5e861;p=pakfire.git libpakfire: Make PakfirePool obscure Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/include/pakfire/package.h b/src/libpakfire/include/pakfire/package.h index 5cfc545cc..31e260edc 100644 --- a/src/libpakfire/include/pakfire/package.h +++ b/src/libpakfire/include/pakfire/package.h @@ -154,14 +154,6 @@ struct _PakfirePackage { PakfireFile filelist; }; -static inline PakfirePool pakfire_package_pool(PakfirePackage pkg) { - return pkg->pool; -} - -static inline Pool* pakfire_package_solv_pool(PakfirePackage pkg) { - return pakfire_package_pool(pkg)->pool; -} - #endif #endif /* PAKFIRE_PACKAGE_H */ diff --git a/src/libpakfire/include/pakfire/pool.h b/src/libpakfire/include/pakfire/pool.h index e99719822..bc96543e8 100644 --- a/src/libpakfire/include/pakfire/pool.h +++ b/src/libpakfire/include/pakfire/pool.h @@ -21,8 +21,6 @@ #ifndef PAKFIRE_POOL_H #define PAKFIRE_POOL_H -#include - #include PakfirePool pakfire_pool_create(Pakfire pakfire); @@ -47,18 +45,16 @@ PakfirePackageList pakfire_pool_search(PakfirePool pool, const char* what, int f #ifdef PAKFIRE_PRIVATE -struct _PakfirePool { - Pool* pool; - int provides_ready; - Queue installonly; - - PakfireCache cache; - int nrefs; -}; +#include -void pakfire_pool_make_provides_ready(PakfirePool pool); +Pool* pakfire_pool_get_solv_pool(PakfirePool pool); char* pakfire_pool_tmpdup(Pool* pool, const char* s); +void pakfire_pool_has_changed(PakfirePool pool); +void pakfire_pool_apply_changes(PakfirePool pool); + +Queue* pakfire_pool_get_installonly_queue(PakfirePool pool); + #endif #endif /* PAKFIRE_POOL_H */ diff --git a/src/libpakfire/include/pakfire/relation.h b/src/libpakfire/include/pakfire/relation.h index 7df98869a..1ff7a1e9c 100644 --- a/src/libpakfire/include/pakfire/relation.h +++ b/src/libpakfire/include/pakfire/relation.h @@ -46,12 +46,8 @@ struct _PakfireRelation { Id id; }; -static inline PakfirePool pakfire_relation_pool(PakfireRelation relation) { - return relation->pool; -} - static inline Pool* pakfire_relation_solv_pool(PakfireRelation relation) { - return pakfire_relation_pool(relation)->pool; + return pakfire_pool_get_solv_pool(relation->pool); } #endif diff --git a/src/libpakfire/include/pakfire/repo.h b/src/libpakfire/include/pakfire/repo.h index 44ac244d9..20b8f8e63 100644 --- a/src/libpakfire/include/pakfire/repo.h +++ b/src/libpakfire/include/pakfire/repo.h @@ -72,7 +72,7 @@ struct _PakfireRepo { PakfirePackage pakfire_repo_add_package(PakfireRepo repo); static inline Pool* pakfire_repo_solv_pool(PakfireRepo repo) { - return pakfire_repo_pool(repo)->pool; + return pakfire_pool_get_solv_pool(repo->pool); } static inline Repo* pakfire_repo_get_solv_repo(PakfireRepo repo) { diff --git a/src/libpakfire/include/pakfire/selector.h b/src/libpakfire/include/pakfire/selector.h index 8b967340e..cfc804859 100644 --- a/src/libpakfire/include/pakfire/selector.h +++ b/src/libpakfire/include/pakfire/selector.h @@ -47,12 +47,8 @@ struct _PakfireSelector { PakfireFilter f_arch; }; -static inline PakfirePool pakfire_selector_pool(PakfireSelector selector) { - return selector->pool; -} - static inline Pool* pakfire_selector_solv_pool(PakfireSelector selector) { - return pakfire_selector_pool(selector)->pool; + return pakfire_pool_get_solv_pool(selector->pool); } #endif diff --git a/src/libpakfire/package.c b/src/libpakfire/package.c index c0afc72da..1c2db7527 100644 --- a/src/libpakfire/package.c +++ b/src/libpakfire/package.c @@ -43,6 +43,10 @@ #include #include +static Pool* pakfire_package_get_solv_pool(PakfirePackage pkg) { + return pakfire_pool_get_solv_pool(pkg->pool); +} + static void pakfire_package_add_self_provides(PakfirePool pool, PakfirePackage pkg, const char* name, const char* evr) { #if 1 PakfireRelation relation = pakfire_relation_create(pool, name, PAKFIRE_EQ, evr); @@ -99,9 +103,9 @@ PAKFIRE_EXPORT void pakfire_package_free(PakfirePackage pkg) { } static Solvable* get_solvable(PakfirePackage pkg) { - PakfirePool pool = pakfire_package_pool(pkg); + Pool* pool = pakfire_package_get_solv_pool(pkg); - return pool_id2solvable(pool->pool, pkg->id); + return pool_id2solvable(pool, pkg->id); } static Repo* pakfire_package_solv_repo(PakfirePackage pkg) { @@ -111,7 +115,7 @@ static Repo* pakfire_package_solv_repo(PakfirePackage pkg) { } static Id pakfire_package_get_handle(PakfirePackage pkg) { - Pool* pool = pakfire_package_solv_pool(pkg); + Pool* pool = pakfire_package_get_solv_pool(pkg); Solvable* s = get_solvable(pkg); return s - pool->solvables; @@ -122,7 +126,7 @@ PAKFIRE_EXPORT int pakfire_package_identical(PakfirePackage pkg1, PakfirePackage } PAKFIRE_EXPORT int pakfire_package_cmp(PakfirePackage pkg1, PakfirePackage pkg2) { - Pool* pool = pakfire_package_solv_pool(pkg1); + Pool* pool = pakfire_package_get_solv_pool(pkg1); Solvable* s1 = get_solvable(pkg1); Solvable* s2 = get_solvable(pkg2); @@ -162,7 +166,7 @@ PAKFIRE_EXPORT int pakfire_package_cmp(PakfirePackage pkg1, PakfirePackage pkg2) } PAKFIRE_EXPORT int pakfire_package_evr_cmp(PakfirePackage pkg1, PakfirePackage pkg2) { - Pool* pool = pakfire_package_solv_pool(pkg1); + Pool* pool = pakfire_package_get_solv_pool(pkg1); Solvable* s1 = get_solvable(pkg1); Solvable* s2 = get_solvable(pkg2); @@ -175,7 +179,7 @@ PAKFIRE_EXPORT Id pakfire_package_id(PakfirePackage pkg) { } PAKFIRE_EXPORT char* pakfire_package_get_nevra(PakfirePackage pkg) { - Pool* pool = pakfire_package_solv_pool(pkg); + Pool* pool = pakfire_package_get_solv_pool(pkg); Solvable* s = get_solvable(pkg); const char* nevra = pool_solvable2str(pool, s); @@ -184,28 +188,28 @@ PAKFIRE_EXPORT char* pakfire_package_get_nevra(PakfirePackage pkg) { } PAKFIRE_EXPORT const char* pakfire_package_get_name(PakfirePackage pkg) { - Pool* pool = pakfire_package_solv_pool(pkg); + Pool* pool = pakfire_package_get_solv_pool(pkg); Solvable* s = get_solvable(pkg); return pool_id2str(pool, s->name); } PAKFIRE_EXPORT void pakfire_package_set_name(PakfirePackage pkg, const char* name) { - Pool* pool = pakfire_package_solv_pool(pkg); + Pool* pool = pakfire_package_get_solv_pool(pkg); Solvable* s = get_solvable(pkg); s->name = pool_str2id(pool, name, 1); } PAKFIRE_EXPORT const char* pakfire_package_get_evr(PakfirePackage pkg) { - Pool* pool = pakfire_package_solv_pool(pkg); + Pool* pool = pakfire_package_get_solv_pool(pkg); Solvable* s = get_solvable(pkg); return pool_id2str(pool, s->evr); } PAKFIRE_EXPORT void pakfire_package_set_evr(PakfirePackage pkg, const char* evr) { - Pool* pool = pakfire_package_solv_pool(pkg); + Pool* pool = pakfire_package_get_solv_pool(pkg); Solvable* s = get_solvable(pkg); s->evr = pool_str2id(pool, evr, 1); @@ -239,7 +243,7 @@ static void split_evr(Pool* pool, const char* evr_c, char** epoch, char** versio } PAKFIRE_EXPORT unsigned long pakfire_package_get_epoch(PakfirePackage pkg) { - Pool* pool = pakfire_package_solv_pool(pkg); + Pool* pool = pakfire_package_get_solv_pool(pkg); char *e, *v, *r, *endptr; unsigned long epoch = 0; @@ -257,7 +261,7 @@ PAKFIRE_EXPORT unsigned long pakfire_package_get_epoch(PakfirePackage pkg) { } PAKFIRE_EXPORT const char* pakfire_package_get_version(PakfirePackage pkg) { - Pool* pool = pakfire_package_solv_pool(pkg); + Pool* pool = pakfire_package_get_solv_pool(pkg); char *e, *v, *r; split_evr(pool, pakfire_package_get_evr(pkg), &e, &v, &r); @@ -265,7 +269,7 @@ PAKFIRE_EXPORT const char* pakfire_package_get_version(PakfirePackage pkg) { } PAKFIRE_EXPORT const char* pakfire_package_get_release(PakfirePackage pkg) { - Pool* pool = pakfire_package_solv_pool(pkg); + Pool* pool = pakfire_package_get_solv_pool(pkg); char *e, *v, *r; split_evr(pool, pakfire_package_get_evr(pkg), &e, &v, &r); @@ -273,14 +277,14 @@ PAKFIRE_EXPORT const char* pakfire_package_get_release(PakfirePackage pkg) { } PAKFIRE_EXPORT const char* pakfire_package_get_arch(PakfirePackage pkg) { - Pool* pool = pakfire_package_solv_pool(pkg); + Pool* pool = pakfire_package_get_solv_pool(pkg); Solvable* s = get_solvable(pkg); return pool_id2str(pool, s->arch); } PAKFIRE_EXPORT void pakfire_package_set_arch(PakfirePackage pkg, const char* arch) { - Pool* pool = pakfire_package_solv_pool(pkg); + Pool* pool = pakfire_package_get_solv_pool(pkg); Solvable* s = get_solvable(pkg); s->arch = pool_str2id(pool, arch, 1); @@ -430,7 +434,7 @@ PAKFIRE_EXPORT void pakfire_package_set_filename(PakfirePackage pkg, const char* } PAKFIRE_EXPORT int pakfire_package_is_installed(PakfirePackage pkg) { - Pool* pool = pakfire_package_solv_pool(pkg); + Pool* pool = pakfire_package_get_solv_pool(pkg); Solvable* s = get_solvable(pkg); return pool->installed == s->repo; @@ -499,8 +503,7 @@ static PakfireRelationList pakfire_package_get_relationlist(PakfirePackage pkg, Solvable* s = get_solvable(pkg); solvable_lookup_idarray(s, type, &q); - PakfirePool pool = pakfire_package_pool(pkg); - PakfireRelationList relationlist = pakfire_relationlist_from_queue(pool, q); + PakfireRelationList relationlist = pakfire_relationlist_from_queue(pkg->pool, q); queue_free(&q); @@ -884,7 +887,7 @@ static PakfireFile pakfire_package_fetch_legacy_filelist(PakfirePackage pkg) { PakfireFile file = NULL; PakfireRepo repo = pakfire_package_get_repo(pkg); Solvable* s = get_solvable(pkg); - Pool* p = pakfire_package_solv_pool(pkg); + Pool* p = pakfire_package_get_solv_pool(pkg); Repo* r = pakfire_repo_get_solv_repo(repo); int found_marker = 0; @@ -923,7 +926,7 @@ static PakfireFile pakfire_package_fetch_filelist(PakfirePackage pkg) { pakfire_package_internalize_repo(pkg); PakfireFile file = NULL; - Pool* pool = pakfire_package_solv_pool(pkg); + Pool* pool = pakfire_package_get_solv_pool(pkg); Repo* repo = pakfire_package_solv_repo(pkg); Id handle = pakfire_package_get_handle(pkg); diff --git a/src/libpakfire/packagelist.c b/src/libpakfire/packagelist.c index a604e6787..0644bb9db 100644 --- a/src/libpakfire/packagelist.c +++ b/src/libpakfire/packagelist.c @@ -94,7 +94,7 @@ PAKFIRE_EXPORT void pakfire_packagelist_push_if_not_exists(PakfirePackageList li PAKFIRE_EXPORT PakfirePackageList pakfire_packagelist_from_queue(PakfirePool _pool, Queue* q) { PakfirePackageList list = pakfire_packagelist_create(); - Pool* pool = _pool->pool; + Pool* pool = pakfire_pool_get_solv_pool(_pool); Id p, pp; for (int i = 0; i < q->count; i += 2) { FOR_JOB_SELECT(p, pp, q->elements[i], q->elements[i + 1]) { diff --git a/src/libpakfire/pool.c b/src/libpakfire/pool.c index 0b4bf2acf..f05f7d809 100644 --- a/src/libpakfire/pool.c +++ b/src/libpakfire/pool.c @@ -36,6 +36,15 @@ #include #include +struct _PakfirePool { + Pool* pool; + int provides_ready; + Queue installonly; + + PakfireCache cache; + int nrefs; +}; + PAKFIRE_EXPORT PakfirePool pakfire_pool_create(Pakfire pakfire) { PakfirePool pool = pakfire_calloc(1, sizeof(*pool)); if (pool) { @@ -88,6 +97,10 @@ PAKFIRE_EXPORT void pakfire_pool_unref(PakfirePool pool) { pakfire_pool_free(pool); } +Pool* pakfire_pool_get_solv_pool(PakfirePool pool) { + return pool->pool; +} + PAKFIRE_EXPORT int pakfire_pool_version_compare(PakfirePool pool, const char* evr1, const char* evr2) { return pool_evrcmp_str(pool->pool, evr1, evr2, EVRCMP_COMPARE); } @@ -104,7 +117,11 @@ PAKFIRE_EXPORT int pakfire_pool_count(PakfirePool pool) { return cnt; } -PAKFIRE_EXPORT void pakfire_pool_make_provides_ready(PakfirePool pool) { +void pakfire_pool_has_changed(PakfirePool pool) { + pool->provides_ready = 0; +} + +void pakfire_pool_apply_changes(PakfirePool pool) { if (!pool->provides_ready) { pool_addfileprovides(pool->pool); pool_createwhatprovides(pool->pool); @@ -148,6 +165,10 @@ PAKFIRE_EXPORT const char** pakfire_pool_get_installonly(PakfirePool pool) { return installonly; } +Queue* pakfire_pool_get_installonly_queue(PakfirePool pool) { + return &pool->installonly; +} + PAKFIRE_EXPORT void pakfire_pool_set_installonly(PakfirePool pool, const char** installonly) { queue_empty(&pool->installonly); @@ -182,7 +203,7 @@ PAKFIRE_EXPORT PakfireCache pakfire_pool_get_cache(PakfirePool pool) { static PakfirePackageList pakfire_pool_dataiterator(PakfirePool pool, const char* what, int key, int flags) { PakfirePackageList list = pakfire_packagelist_create(); - pakfire_pool_make_provides_ready(pool); + pakfire_pool_apply_changes(pool); int di_flags = 0; if (flags & PAKFIRE_SUBSTRING) @@ -209,7 +230,7 @@ static PakfirePackageList pakfire_pool_dataiterator(PakfirePool pool, const char static PakfirePackageList pakfire_pool_search_name(PakfirePool _pool, const char* name, int flags) { if (!flags) { PakfirePackageList list = pakfire_packagelist_create(); - pakfire_pool_make_provides_ready(_pool); + pakfire_pool_apply_changes(_pool); Pool* pool = _pool->pool; Id id = pool_str2id(pool, name, 0); @@ -235,7 +256,7 @@ static PakfirePackageList pakfire_pool_search_name(PakfirePool _pool, const char static PakfirePackageList pakfire_pool_search_provides(PakfirePool _pool, const char* provides, int flags) { if (!flags) { PakfirePackageList list = pakfire_packagelist_create(); - pakfire_pool_make_provides_ready(_pool); + pakfire_pool_apply_changes(_pool); Pool* pool = _pool->pool; Id id = pool_str2id(pool, provides, 0); diff --git a/src/libpakfire/relation.c b/src/libpakfire/relation.c index 09c2eeff4..a1fe2c3a7 100644 --- a/src/libpakfire/relation.c +++ b/src/libpakfire/relation.c @@ -45,7 +45,7 @@ static int cmptype2relflags(int type) { } PAKFIRE_EXPORT PakfireRelation pakfire_relation_create(PakfirePool pool, const char* name, int cmp_type, const char* evr) { - Pool* p = pool->pool; + Pool* p = pakfire_pool_get_solv_pool(pool); Id id = pool_str2id(p, name, 1); diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index 9d4281cbe..39ef4b64a 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -55,7 +55,9 @@ static Repo* get_repo_by_name(Pool* pool, const char* name) { } static PakfireRepo get_pakfire_repo_by_name(PakfirePool pool, const char* name) { - Repo* repo = get_repo_by_name(pool->pool, name); + Pool* p = pakfire_pool_get_solv_pool(pool); + + Repo* repo = get_repo_by_name(p, name); if (repo) return repo->appdata; @@ -70,9 +72,11 @@ PAKFIRE_EXPORT PakfireRepo pakfire_repo_create(PakfirePool pool, const char* nam return repo; } - Repo* r = get_repo_by_name(pool->pool, name); + Pool* p = pakfire_pool_get_solv_pool(pool); + + Repo* r = get_repo_by_name(p, name); if (!r) - r = repo_create(pool->pool, name); + r = repo_create(p, name); return pakfire_repo_create_from_repo(pool, r); } @@ -173,7 +177,7 @@ PAKFIRE_EXPORT void pakfire_repo_set_enabled(PakfireRepo repo, int enabled) { repo->repo->disabled = !enabled; PakfirePool pool = pakfire_repo_pool(repo); - pool->provides_ready = 0; + pakfire_pool_has_changed(pool); } PAKFIRE_EXPORT int pakfire_repo_get_priority(PakfireRepo repo) { @@ -351,7 +355,7 @@ PAKFIRE_EXPORT int pakfire_repo_read_solv_fp(PakfireRepo repo, FILE *f, int flag return PAKFIRE_E_SOLV_CORRUPTED; } - repo->pool->provides_ready = 0; + pakfire_pool_has_changed(repo->pool); return ret; } diff --git a/src/libpakfire/request.c b/src/libpakfire/request.c index c87878c36..a1dbb3350 100644 --- a/src/libpakfire/request.c +++ b/src/libpakfire/request.c @@ -74,8 +74,9 @@ PAKFIRE_EXPORT PakfirePool pakfire_request_pool(PakfireRequest request) { static void init_solver(PakfireRequest request, int flags) { PakfirePool pool = pakfire_request_pool(request); + Pool* p = pakfire_pool_get_solv_pool(pool); - Solver* solver = solver_create(pool->pool); + Solver* solver = solver_create(p); /* Free older solver */ if (request->solver) { @@ -111,7 +112,7 @@ static int solve(PakfireRequest request, Queue* queue) { request->transaction = NULL; } - pakfire_pool_make_provides_ready(request->pool); + pakfire_pool_apply_changes(request->pool); if (solver_solve(request->solver, queue)) { #ifdef DEBUG @@ -143,10 +144,10 @@ PAKFIRE_EXPORT int pakfire_request_solve(PakfireRequest request, int flags) { } /* turn off implicit obsoletes for installonly packages */ - PakfirePool pool = request->pool; - for (int i = 0; i < pool->installonly.count; i++) + Queue* installonly = pakfire_pool_get_installonly_queue(request->pool); + for (int i = 0; i < installonly->count; i++) queue_push2(&queue, SOLVER_MULTIVERSION|SOLVER_SOLVABLE_PROVIDES, - pool->installonly.elements[i]); + installonly->elements[i]); // XXX EXCLUDES diff --git a/src/libpakfire/selector.c b/src/libpakfire/selector.c index f0120c64f..b70b899f5 100644 --- a/src/libpakfire/selector.c +++ b/src/libpakfire/selector.c @@ -164,7 +164,8 @@ static int filter_arch2queue(PakfirePool pool, const PakfireFilter f, Queue* que assert(f->cmp_type == PAKFIRE_EQ); - Id archid = str2archid(pool->pool, f->match); + Pool* p = pakfire_pool_get_solv_pool(pool); + Id archid = str2archid(p, f->match); if (archid == 0) return PAKFIRE_E_ARCH; @@ -172,7 +173,7 @@ static int filter_arch2queue(PakfirePool pool, const PakfireFilter f, Queue* que assert((queue->elements[i] & SOLVER_SELECTMASK) == SOLVER_SOLVABLE_NAME); Id dep = queue->elements[i + 1]; - queue->elements[i + 1] = pool_rel2id(pool->pool, dep, archid, REL_ARCH, 1); + queue->elements[i + 1] = pool_rel2id(p, dep, archid, REL_ARCH, 1); queue->elements[i] |= SOLVER_SETARCH; } @@ -185,13 +186,14 @@ static int filter_evr2queue(PakfirePool pool, const PakfireFilter f, Queue* queu assert(f->cmp_type == PAKFIRE_EQ); - Id evr = pool_str2id(pool->pool, f->match, 1); + Pool* p = pakfire_pool_get_solv_pool(pool); + Id evr = pool_str2id(p, f->match, 1); for (int i = 0; i < queue->count; i += 2) { assert((queue->elements[i] & SOLVER_SELECTMASK) == SOLVER_SOLVABLE_NAME); Id dep = queue->elements[i + 1]; - queue->elements[i + 1] = pool_rel2id(pool->pool, dep, evr, REL_EQ, 1); + queue->elements[i + 1] = pool_rel2id(p, dep, evr, REL_EQ, 1); queue->elements[i] |= PAKFIRE_PKG_VERSION ? SOLVER_SETEV : SOLVER_SETEVR; } @@ -202,19 +204,20 @@ static int filter_name2queue(PakfirePool pool, const PakfireFilter f, Queue* que if (f == NULL) return 0; + Pool* p = pakfire_pool_get_solv_pool(pool); const char* name = f->match; Id id; Dataiterator di; switch (f->cmp_type) { case PAKFIRE_EQ: - id = pool_str2id(pool->pool, name, 0); + id = pool_str2id(p, name, 0); if (id) queue_push2(queue, SOLVER_SOLVABLE_NAME, id); break; case PAKFIRE_GLOB: - dataiterator_init(&di, pool->pool, 0, 0, SOLVABLE_NAME, name, SEARCH_GLOB); + dataiterator_init(&di, p, 0, 0, SOLVABLE_NAME, name, SEARCH_GLOB); while (dataiterator_step(&di)) { assert(di.idp); @@ -241,11 +244,12 @@ static int filter_provides2queue(PakfirePool pool, const PakfireFilter f, Queue* if (f == NULL) return 0; + Pool* p = pakfire_pool_get_solv_pool(pool); Id id; switch (f->cmp_type) { case PAKFIRE_EQ: - id = pool_str2id(pool->pool, f->match, 0); + id = pool_str2id(p, f->match, 0); if (id) queue_push2(queue, SOLVER_SOLVABLE_PROVIDES, id); break; @@ -271,7 +275,7 @@ PAKFIRE_EXPORT int pakfire_selector2queue(const PakfireSelector selector, Queue* goto finish; } - pakfire_pool_make_provides_ready(pool); + pakfire_pool_apply_changes(pool); ret = filter_name2queue(pool, selector->f_name, &queue_selector); if (ret)