Skip to content

Commit

Permalink
Use pkghash_get_value
Browse files Browse the repository at this point in the history
  • Loading branch information
bapt committed Aug 23, 2021
1 parent 486a5b7 commit ff7a207
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 142 deletions.
15 changes: 5 additions & 10 deletions libpkg/elfhints.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,15 @@ const char *
shlib_list_find_by_name(const char *shlib_file)
{
struct shlib *sl;
pkghash_entry *e;

e = pkghash_get(rpath, shlib_file);
if (e != NULL) {
sl = (struct shlib *)e->value;
sl = pkghash_get_value(rpath, shlib_file);
if (sl != NULL)
return (sl->path);
}

e = pkghash_get(shlibs, shlib_file);
if (e != NULL) {
sl = (struct shlib *)e->value;
sl = pkghash_get_value(shlibs, shlib_file);
if (sl != NULL)
return (sl->path);
}


return (NULL);
}

Expand Down
22 changes: 6 additions & 16 deletions libpkg/pkg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1618,42 +1618,32 @@ pkg_is_config_file(struct pkg *p, const char *path,
{
*file = NULL;
*cfile = NULL;
pkghash_entry *e;

if (pkghash_count(p->config_files_hash) == 0)
return (false);

e = pkghash_get(p->filehash, path);
if (e == NULL)
*file = pkghash_get_value(p->filehash, path);
if (*file == NULL)
return (false);
*file = (struct pkg_file *)e->value;

e = pkghash_get(p->config_files_hash, path);
if (e == NULL) {
*cfile = pkghash_get_value(p->config_files_hash, path);
if (*cfile == NULL) {
*file = NULL;
return (false);
}
*cfile = (struct pkg_config_file *)e->value;

return (true);
}

struct pkg_dir *
pkg_get_dir(struct pkg *p, const char *path)
{
pkghash_entry *e = pkghash_get(p->dirhash, path);
if (e == NULL)
return (NULL);
return ((struct pkg_dir *)e->value);
return (pkghash_get_value(p->dirhash, path));
}

struct pkg_file *
pkg_get_file(struct pkg *p, const char *path)
{
pkghash_entry *e = pkghash_get(p->filehash, path);
if (e == NULL)
return (NULL);
return ((struct pkg_file *)e->value);
return (pkghash_get_value(p->filehash, path));
}

bool
Expand Down
7 changes: 1 addition & 6 deletions libpkg/pkg_add.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,12 +568,7 @@ create_regfile(struct pkg *pkg, struct pkg_file *f, struct archive *a,

if (fromfd == -1) {
/* check if this is a config file */
pkghash_entry *e;
e = pkghash_get(pkg->config_files_hash, f->path);
if (e == NULL)
f->config = NULL;
else
f->config = (struct pkg_config_file *)e->value;
f->config = pkghash_get_value(pkg->config_files_hash, f->path);
if (f->config) {
const char *cfdata;
bool merge = pkg_object_bool(pkg_config_get("AUTOMERGE"));
Expand Down
18 changes: 4 additions & 14 deletions libpkg/pkg_jobs_conflicts.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,9 @@ pkg_conflicts_register_unsafe(struct pkg *p1, struct pkg *p2,
bool use_digest)
{
struct pkg_conflict *c1, *c2;
pkghash_entry *e;

c1 = c2 = NULL;
e = pkghash_get(p1->conflictshash, p2->uid);
if (e != NULL)
c1 = (struct pkg_conflict *)e->value;
e = pkghash_get(p2->conflictshash, p1->uid);
if (e != NULL)
c2 = (struct pkg_conflict *)e->value;

c1 = pkghash_get_value(p1->conflictshash, p2->uid);
c2 = pkghash_get_value(p2->conflictshash, p1->uid);
if (c1 == NULL) {
c1 = xcalloc(1, sizeof(*c1));
c1->type = type;
Expand Down Expand Up @@ -413,7 +407,6 @@ pkg_conflicts_check_all_paths(struct pkg_jobs *j, const char *path,
struct pkg_jobs_conflict_item *cit, test;
struct pkg_conflict *c;
uint64_t hv;
pkghash_entry *e;

hv = siphash24(path, strlen(path), k);
test.hash = hv;
Expand All @@ -440,10 +433,7 @@ pkg_conflicts_check_all_paths(struct pkg_jobs *j, const char *path,
}

/* Here we can have either collision or a real conflict */
c = NULL;
e = pkghash_get(it->pkg->conflictshash, uid2);
if (e != NULL)
c = (struct pkg_conflict *)e->value;
c = pkghash_get_value(it->pkg->conflictshash, uid2);
if (c != NULL || !pkg_conflicts_register_chain(j, it, cit->item, path)) {
/*
* Collision found, change the key following the
Expand Down
72 changes: 19 additions & 53 deletions libpkg/pkg_jobs_universe.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ pkg_jobs_universe_get_local(struct pkg_jobs_universe *universe,
struct pkg *pkg = NULL;
struct pkgdb_it *it;
struct pkg_job_universe_item *unit, *cur, *found;
pkghash_entry *e;

if (flag == 0) {
if (!IS_DELETE(universe->j))
Expand All @@ -68,10 +67,9 @@ pkg_jobs_universe_get_local(struct pkg_jobs_universe *universe,
flag = PKG_LOAD_BASIC|PKG_LOAD_RDEPS|PKG_LOAD_DEPS|PKG_LOAD_ANNOTATIONS;
}

e = pkghash_get(universe->items, uid);
if (e != NULL) {
unit = pkghash_get_value(universe->items, uid);
if (unit != NULL) {
/* Search local in a universe chain */
unit = (struct pkg_job_universe_item *)e->value;
cur = unit;
found = NULL;
do {
Expand Down Expand Up @@ -107,7 +105,6 @@ pkg_jobs_universe_get_remote(struct pkg_jobs_universe *universe,
pkg_chain_t *result = NULL;
struct pkgdb_it *it;
struct pkg_job_universe_item *unit, *cur, *found;
pkghash_entry *e;

if (flag == 0) {
flag = PKG_LOAD_BASIC|PKG_LOAD_DEPS|PKG_LOAD_OPTIONS|
Expand All @@ -116,10 +113,7 @@ pkg_jobs_universe_get_remote(struct pkg_jobs_universe *universe,
PKG_LOAD_ANNOTATIONS|PKG_LOAD_CONFLICTS;
}

unit = NULL;
e = pkghash_get(universe->items, uid);
if (e != NULL)
unit = (struct pkg_job_universe_item *)e->value;
unit = pkghash_get_value(universe->items, uid);
if (unit != NULL && unit->pkg->type != PKG_INSTALLED) {
/* Search local in a universe chain */
cur = unit;
Expand Down Expand Up @@ -163,7 +157,6 @@ pkg_jobs_universe_add_pkg(struct pkg_jobs_universe *universe, struct pkg *pkg,
bool force __unused, struct pkg_job_universe_item **found)
{
struct pkg_job_universe_item *item, *seen, *tmp = NULL;
pkghash_entry *e;

pkg_validate(pkg, universe->j->db);

Expand All @@ -176,10 +169,7 @@ pkg_jobs_universe_add_pkg(struct pkg_jobs_universe *universe, struct pkg *pkg,
}
}

seen = NULL;
e = pkghash_get(universe->seen, pkg->digest);
if (e != NULL)
seen = (struct pkg_job_universe_item *)e->value;
seen = pkghash_get_value(universe->seen, pkg->digest);
if (seen) {
bool same_package = false;

Expand Down Expand Up @@ -218,12 +208,10 @@ pkg_jobs_universe_add_pkg(struct pkg_jobs_universe *universe, struct pkg *pkg,
item = xcalloc(1, sizeof (struct pkg_job_universe_item));
item->pkg = pkg;

e = pkghash_get(universe->items, pkg->uid);
if (e == NULL) {
tmp = pkghash_get_value(universe->items, pkg->uid);
if (tmp == NULL) {
pkghash_safe_add(universe->items, pkg->uid, item, NULL);
item->inhash = true;
} else {
tmp = (struct pkg_job_universe_item *)e->value;
}

DL_APPEND(tmp, item);
Expand Down Expand Up @@ -401,17 +389,13 @@ pkg_jobs_universe_handle_provide(struct pkg_jobs_universe *universe,
PKG_LOAD_REQUIRES|PKG_LOAD_PROVIDES|
PKG_LOAD_SHLIBS_REQUIRED|PKG_LOAD_SHLIBS_PROVIDED|
PKG_LOAD_ANNOTATIONS|PKG_LOAD_CONFLICTS;
pkghash_entry *e;

rpkg = NULL;

e = pkghash_get(universe->provides, name);
prhead = e != NULL ? e->value : NULL;
prhead = pkghash_get_value(universe->provides, name);
while (pkgdb_it_next(it, &rpkg, flags) == EPKG_OK) {
/* Check for local packages */
unit = NULL;
if ((e = pkghash_get(universe->items, rpkg->uid)) != NULL) {
unit = (struct pkg_job_universe_item *)e->value;
if ((unit = pkghash_get_value(universe->items, rpkg->uid)) != NULL) {
/* Remote provide is newer, so we can add it */
if (pkg_jobs_universe_process_item(universe, rpkg,
&unit) != EPKG_OK) {
Expand Down Expand Up @@ -671,7 +655,6 @@ pkg_jobs_update_universe_item_priority(struct pkg_jobs_universe *universe,
struct pkg_conflict *c = NULL;
struct pkg_job_universe_item *found, *cur, *it;
const char *is_local;
pkghash_entry *e;
int maxpri;

int (*deps_func)(const struct pkg *pkg, struct pkg_dep **d);
Expand Down Expand Up @@ -722,10 +705,9 @@ pkg_jobs_update_universe_item_priority(struct pkg_jobs_universe *universe,
}

while (deps_func(it->pkg, &d) == EPKG_OK) {
e = pkghash_get(universe->items, d->uid);
if (e == NULL)
found = pkghash_get_value(universe->items, d->uid);
if (found == NULL)
continue;
found = (struct pkg_job_universe_item *)e->value;
LL_FOREACH(found, cur) {
if (cur->priority < priority + 1)
pkg_jobs_update_universe_item_priority(universe, cur,
Expand All @@ -736,10 +718,9 @@ pkg_jobs_update_universe_item_priority(struct pkg_jobs_universe *universe,
d = NULL;
maxpri = priority;
while (rdeps_func(it->pkg, &d) == EPKG_OK) {
e = pkghash_get(universe->items, d->uid);
if (e == NULL)
found = pkghash_get_value(universe->items, d->uid);
if (found == NULL)
continue;
found = (struct pkg_job_universe_item *)e->value;
LL_FOREACH(found, cur) {
if (cur->priority >= maxpri) {
maxpri = cur->priority + 1;
Expand All @@ -755,10 +736,7 @@ pkg_jobs_update_universe_item_priority(struct pkg_jobs_universe *universe,
continue;

while (pkg_conflicts(it->pkg, &c) == EPKG_OK) {
e = pkghash_get(universe->items, c->uid);
if (e == NULL)
continue;
found = (struct pkg_job_universe_item *)e->value;
found = pkghash_get_value(universe->items, c->uid);
LL_FOREACH(found, cur) {
if (cur->pkg->type != PKG_INSTALLED)
continue;
Expand All @@ -780,13 +758,11 @@ pkg_jobs_update_conflict_priority(struct pkg_jobs_universe *universe,
struct pkg_conflict *c = NULL;
struct pkg *lp = req->items[1]->pkg;
struct pkg_job_universe_item *found, *cur, *rit = NULL;
pkghash_entry *e;

while (pkg_conflicts(lp, &c) == EPKG_OK) {
rit = NULL;
e = pkghash_get(universe->items, c->uid);
assert(e != NULL);
found = (struct pkg_job_universe_item *)e->value;
found = pkghash_get_value(universe->items, c->uid);
assert(found != NULL);

LL_FOREACH(found, cur) {
if (cur->pkg->type != PKG_INSTALLED) {
Expand Down Expand Up @@ -872,12 +848,7 @@ pkg_jobs_universe_new(struct pkg_jobs *j)
struct pkg_job_universe_item *
pkg_jobs_universe_find(struct pkg_jobs_universe *universe, const char *uid)
{
pkghash_entry *e;

e = pkghash_get(universe->items, uid);
if (e == NULL)
return (NULL);
return ((struct pkg_job_universe_item *)e->value);
return (pkghash_get_value(universe->items, uid));
}

void
Expand All @@ -890,7 +861,6 @@ pkg_jobs_universe_change_uid(struct pkg_jobs_universe *universe,

struct pkg *lp;
struct pkg_job_replace *replacement;
pkghash_entry *e;

if (update_rdeps) {
/* For all rdeps update deps accordingly */
Expand Down Expand Up @@ -925,8 +895,7 @@ pkg_jobs_universe_change_uid(struct pkg_jobs_universe *universe,
free(unit->pkg->uid);
unit->pkg->uid = xstrdup(new_uid);

e = pkghash_get(universe->items, new_uid);
found = e != NULL ? (struct pkg_job_universe_item *)e->value : NULL;
found = pkghash_get_value(universe->items, new_uid);
if (found != NULL)
DL_APPEND(found, unit);
else
Expand Down Expand Up @@ -1205,10 +1174,8 @@ pkg_jobs_universe_get_upgrade_candidates(struct pkg_jobs_universe *universe,
PKG_LOAD_SHLIBS_REQUIRED|PKG_LOAD_SHLIBS_PROVIDED|
PKG_LOAD_ANNOTATIONS|PKG_LOAD_CONFLICTS;
kvec_t(struct pkg *) candidates;
pkghash_entry *e;

e = pkghash_get(universe->items, uid);
unit = e != NULL ? (struct pkg_job_universe_item *)e->value : NULL;
unit = pkghash_get_value(universe->items, uid);
if (unit != NULL) {
/*
* If a unit has been found, we have already found the potential
Expand Down Expand Up @@ -1275,8 +1242,7 @@ pkg_jobs_universe_get_upgrade_candidates(struct pkg_jobs_universe *universe,
return (NULL);
}

e = pkghash_get(universe->items, uid);
unit = e != NULL ? (struct pkg_job_universe_item *)e->value : NULL;
unit = pkghash_get_value(universe->items, uid);
kv_destroy(candidates);

return (unit);
Expand Down
5 changes: 1 addition & 4 deletions libpkg/pkg_ports.c
Original file line number Diff line number Diff line change
Expand Up @@ -887,15 +887,12 @@ parse_keywords(struct plist *plist, char *keyword,
struct keyword *k = NULL;
struct action *a;
int ret = EPKG_FATAL;
pkghash_entry *e;

/* if keyword is empty consider it as a file */
if (*keyword == '\0')
return (file(plist, line, attr));

e = pkghash_get(plist->keywords, keyword);
if (e != NULL)
k = (struct keyword *)e->value;
k = pkghash_get_value(plist->keywords, keyword);
if (k != NULL) {
LL_FOREACH(k->actions, a) {
ret = a->perform(plist, line, attr);
Expand Down
14 changes: 4 additions & 10 deletions libpkg/pkg_repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,7 @@ pkg_repo_check_fingerprint(struct pkg_repo *repo, pkghash *sc, bool fatal)
* We may want to check meta
*/
if (repo->meta != NULL && repo->meta->keys != NULL) {
mk = NULL;
pkghash_entry *e = pkghash_get(repo->meta->keys, s->name);
if (e != NULL)
mk = (struct pkg_repo_meta_key *)e->value;
mk = pkghash_get_value(repo->meta->keys, s->name);
}

if (mk != NULL && mk->pubkey != NULL) {
Expand Down Expand Up @@ -420,7 +417,6 @@ pkg_repo_parse_sigkeys(const char *in, int inlen, pkghash **sc)
int len = 0, tlen;
struct sig_cert *s = NULL;
bool new = false;
pkghash_entry *e;

while (p < end) {
switch (state) {
Expand Down Expand Up @@ -460,17 +456,15 @@ pkg_repo_parse_sigkeys(const char *in, int inlen, pkghash **sc)
return (EPKG_FATAL);
}
char *k = xstrndup(p, len);
e = pkghash_get(*sc, k);
s = pkghash_get_value(*sc, k);
free(k);
if ( e == NULL) {
if ( s == NULL) {
s = xcalloc(1, sizeof(struct sig_cert));
tlen = MIN(len, sizeof(s->name) - 1);
memcpy(s->name, p, tlen);
s->name[tlen] = '\0';
new = true;
}
else {
s = (struct sig_cert *)e->value;
} else {
new = false;
}
state = fp_parse_siglen;
Expand Down
Loading

0 comments on commit ff7a207

Please sign in to comment.