Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Use pkghash_get_value
Baptiste Daroussin committed 4 years ago
commit ff7a2076753b2fd4fa6c18927594e1154878265f
parent 486a5b7
9 files changed +48 -142
modified libpkg/elfhints.c
@@ -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);
}

modified libpkg/pkg.c
@@ -1618,22 +1618,18 @@ 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);
}
@@ -1641,19 +1637,13 @@ pkg_is_config_file(struct pkg *p, const char *path,
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
modified libpkg/pkg_add.c
@@ -568,12 +568,7 @@ retry:

	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"));
modified libpkg/pkg_jobs_conflicts.c
@@ -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;
@@ -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;
@@ -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
modified libpkg/pkg_jobs_universe.c
@@ -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))
@@ -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 {
@@ -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|
@@ -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;
@@ -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);

@@ -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;

@@ -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);
@@ -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) {
@@ -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);
@@ -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,
@@ -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;
@@ -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;
@@ -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) {
@@ -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
@@ -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 */
@@ -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
@@ -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
@@ -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);
modified libpkg/pkg_ports.c
@@ -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);
modified libpkg/pkg_repo.c
@@ -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) {
@@ -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) {
@@ -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;
modified libpkg/pkg_solve.c
@@ -284,7 +284,6 @@ pkg_solve_handle_provide (struct pkg_solve_problem *problem,
	struct pkg_job_universe_item *un;
	struct pkg *pkg;
	bool libfound, providefound;
-
	pkghash_entry *e;

	/* Find the first package in the universe list */
	un = pr->un;
@@ -294,11 +293,7 @@ pkg_solve_handle_provide (struct pkg_solve_problem *problem,

	/* Find the corresponding variables chain */

-
	var = NULL;
-
	e = pkghash_get(problem->variables_by_uid, un->pkg->uid);
-
	if (e != NULL)
-
		var = (struct pkg_solve_variable *)e->value;
-

+
	var = pkghash_get_value(problem->variables_by_uid, un->pkg->uid);
	LL_FOREACH(var, curvar) {
		/*
		 * For each provide we need to check whether this package
@@ -378,9 +373,7 @@ pkg_solve_add_depend_rule(struct pkg_solve_problem *problem,
	LL_FOREACH2(dep, cur, alt_next) {
		uid = cur->uid;
		depvar = NULL;
-
		pkghash_entry *e = pkghash_get(problem->variables_by_uid, uid);
-
		if (e != NULL)
-
			depvar = (struct pkg_solve_variable *)e->value;
+
		depvar = pkghash_get_value(problem->variables_by_uid, uid);
		if (depvar == NULL) {
			pkg_debug(2, "cannot find variable dependency %s", uid);
			continue;
@@ -431,10 +424,7 @@ pkg_solve_add_conflict_rule(struct pkg_solve_problem *problem,
	struct pkg *other;

	uid = conflict->uid;
-
	confvar = NULL;
-
	pkghash_entry *e = pkghash_get(problem->variables_by_uid, uid);
-
	if (e != NULL)
-
		confvar = (struct pkg_solve_variable *)e->value;
+
	confvar = pkghash_get_value(problem->variables_by_uid, uid);
	if (confvar == NULL) {
		pkg_debug(2, "cannot find conflict %s", uid);
		return (EPKG_END);
@@ -510,12 +500,10 @@ pkg_solve_add_require_rule(struct pkg_solve_problem *problem,
	struct pkg_job_provide *pr, *prhead;
	struct pkg *pkg;
	int cnt;
-
	pkghash_entry *e;

	pkg = var->unit->pkg;

-
	e = pkghash_get(problem->j->universe->provides, requirement);
-
	prhead = e != NULL ? (struct pkg_job_provide *)e->value : NULL;
+
	prhead = pkghash_get_value(problem->j->universe->provides, requirement);
	if (prhead != NULL) {
		pkg_debug(4, "solver: Add require rule: %s-%s(%c) wants %s",
			pkg->name, pkg->version, pkg->type == PKG_INSTALLED ? 'l' : 'r',
@@ -598,10 +586,7 @@ pkg_solve_add_request_rule(struct pkg_solve_problem *problem,
	/*
	 * Get the suggested item
	 */
-
	var = NULL;
-
	pkghash_entry *e = pkghash_get(problem->variables_by_uid, req->item->pkg->uid);
-
	if (e != NULL)
-
		var = (struct pkg_solve_variable *)e->value;
+
	var = pkghash_get_value(problem->variables_by_uid, req->item->pkg->uid);
	var = pkg_solve_find_var_in_chain(var, req->item->unit);
	assert(var != NULL);
	/* Assume the most significant variable */
@@ -884,9 +869,7 @@ pkg_solve_jobs_to_sat(struct pkg_jobs *j)
	while (pkghash_next(&it)) {
		un = (struct pkg_job_universe_item *)it.value;
		struct pkg_solve_variable *var = NULL;
-
		pkghash_entry *e = pkghash_get(problem->variables_by_uid, un->pkg->uid);
-
		if (e != NULL)
-
			var = (struct pkg_solve_variable *)e->value;
+
		var = pkghash_get_value(problem->variables_by_uid, un->pkg->uid);
		if (var == NULL) {
			pkg_emit_error("internal solver error: variable %s is not found",
			    un->pkg->uid);
modified src/version.c
@@ -639,7 +639,6 @@ validate_origin(const char *portsdir, const char *origin)
	struct category	*cat;
	char		*category, *buf;
	char		 categorypath[MAXPATHLEN];
-
	pkghash_entry	*e;

	/* If the origin does not contain a / ignore it like for
	 * "base"
@@ -654,12 +653,9 @@ validate_origin(const char *portsdir, const char *origin)
	category = strrchr(categorypath, '/');
	category++;

-
	e = pkghash_get(categories, category);
-
	if (e == NULL)
+
	cat = pkghash_get_value(categories, category);
+
	if (cat == NULL)
		cat = category_new(categorypath, category);
-
	else
-
		cat = (struct category *)e->value;
-

	if (cat == NULL)
		return (false);