Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
last conversion from uthash to pkghash
Baptiste Daroussin committed 4 years ago
commit 486a5b7c6885bbd69781e766415dab356dc7ead7
parent 282b83b
6 files changed +89 -57
modified libpkg/pkg_cudf.c
@@ -183,16 +183,21 @@ static int
cudf_emit_request_packages(const char *op, struct pkg_jobs *j, FILE *f)
{
	struct pkg_job_request *req, *tmp;
-
	int column = 0;
+
	int column = 0, cnt = 0, max;
	bool printed = false;
+
	pkghash_it it;

+
	max = pkghash_count(j->request_add);
	if (fprintf(f, "%s: ", op) < 0)
		return (EPKG_FATAL);
-
	HASH_ITER(hh, j->request_add, req, tmp) {
+
	it = pkghash_iterator(j->request_add);
+
	while (pkghash_next(&it)) {
+
		req = it.value;
+
		cnt++;
		if (req->skip)
			continue;
		if (cudf_print_element(f, req->item->pkg->uid,
-
		    (req->hh.next != NULL), &column) < 0) {
+
		    (max > cnt), &column) < 0) {
			return (EPKG_FATAL);
		}
		printed = true;
@@ -206,11 +211,15 @@ cudf_emit_request_packages(const char *op, struct pkg_jobs *j, FILE *f)
	printed = false;
	if (fprintf(f, "remove: ") < 0)
		return (EPKG_FATAL);
-
	HASH_ITER(hh, j->request_delete, req, tmp) {
+
	max = pkghash_count(j->request_delete);
+
	it = pkghash_iterator(j->request_delete);
+
	while (pkghash_next(&it)) {
+
		req = it.value;
+
		cnt++;
		if (req->skip)
			continue;
		if (cudf_print_element(f, req->item->pkg->uid,
-
		    (req->hh.next != NULL), &column) < 0) {
+
		    (max > cnt), &column) < 0) {
			return (EPKG_FATAL);
		}
		printed = true;
modified libpkg/pkg_jobs.c
@@ -168,19 +168,22 @@ pkg_jobs_request_free(struct pkg_job_request *req)
void
pkg_jobs_free(struct pkg_jobs *j)
{
-
	struct pkg_job_request *req, *tmp;
+
	pkghash_it it;

	if (j == NULL)
		return;

-
	HASH_ITER(hh, j->request_add, req, tmp) {
-
		HASH_DEL(j->request_add, req);
-
		pkg_jobs_request_free(req);
-
	}
-
	HASH_ITER(hh, j->request_delete, req, tmp) {
-
		HASH_DEL(j->request_delete, req);
-
		pkg_jobs_request_free(req);
-
	}
+
	it = pkghash_iterator(j->request_add);
+
	while (pkghash_next(&it))
+
		pkg_jobs_request_free(it.value);
+
	pkghash_destroy(j->request_add);
+
	j->request_add = NULL;
+

+
	it = pkghash_iterator(j->request_delete);
+
	while (pkghash_next(&it))
+
		pkg_jobs_request_free(it.value);
+
	pkghash_destroy(j->request_delete);
+
	j->request_delete = NULL;

	pkg_jobs_universe_free(j->universe);
	LL_FREE(j->jobs, free);
@@ -294,8 +297,8 @@ pkg_jobs_iter(struct pkg_jobs *jobs, void **iter,
}

static struct pkg_job_request_item*
-
pkg_jobs_add_req_from_universe(struct pkg_job_request **head,
-
	struct pkg_job_universe_item *un, bool local, bool automatic)
+
pkg_jobs_add_req_from_universe(pkghash **head, struct pkg_job_universe_item *un,
+
    bool local, bool automatic)
{
	struct pkg_job_request *req;
	struct pkg_job_request_item *nit;
@@ -303,7 +306,7 @@ pkg_jobs_add_req_from_universe(struct pkg_job_request **head,
	bool new_req = false;

	assert(un != NULL);
-
	HASH_FIND_STR(*head, un->pkg->uid, req);
+
	req = pkghash_get_value(*head, un->pkg->uid);

	if (req == NULL) {
		req = xcalloc(1, sizeof(*req));
@@ -330,7 +333,7 @@ pkg_jobs_add_req_from_universe(struct pkg_job_request **head,

	if (new_req) {
		if (req->item != NULL) {
-
			HASH_ADD_KEYPTR(hh, *head, un->pkg->uid, strlen(un->pkg->uid), req);
+
			pkghash_safe_add(*head, un->pkg->uid, req, NULL);
		}
		else {
			free(req);
@@ -344,7 +347,8 @@ pkg_jobs_add_req_from_universe(struct pkg_job_request **head,
static struct pkg_job_request_item*
pkg_jobs_add_req(struct pkg_jobs *j, struct pkg *pkg)
{
-
	struct pkg_job_request *req, **head;
+
	pkghash **head;
+
	struct pkg_job_request *req;
	struct pkg_job_request_item *nit;
	struct pkg_job_universe_item *un;
	int rc;
@@ -370,7 +374,7 @@ pkg_jobs_add_req(struct pkg_jobs *j, struct pkg *pkg)
		 * digest. In turn, that means that two upgrade candidates are equal,
		 * we thus won't do anything with this item, as it is definitely useless
		 */
-
		HASH_FIND_STR(*head, pkg->uid, req);
+
		req = pkghash_get_value(*head, pkg->uid);
		if (req != NULL) {
			DL_FOREACH(req->item, nit) {
				if (nit->unit == un)
@@ -398,7 +402,7 @@ pkg_jobs_add_req(struct pkg_jobs *j, struct pkg *pkg)
		return (NULL);
	}

-
	HASH_FIND_STR(*head, pkg->uid, req);
+
	req = pkghash_get_value(*head, pkg->uid);

	nit = xcalloc(1, sizeof(*nit));
	nit->pkg = pkg;
@@ -407,7 +411,7 @@ pkg_jobs_add_req(struct pkg_jobs *j, struct pkg *pkg)
	if (req == NULL) {
		/* Allocate new unique request item */
		req = xcalloc(1, sizeof(*req));
-
		HASH_ADD_KEYPTR(hh, *head, pkg->uid, strlen(pkg->uid), req);
+
		pkghash_safe_add(*head, pkg->uid, req, NULL);
	}

	/* Append candidate to the list of candidates */
@@ -428,19 +432,22 @@ pkg_jobs_process_add_request(struct pkg_jobs *j)
	bool force = j->flags & PKG_FLAG_FORCE,
		 reverse = j->flags & PKG_FLAG_RECURSIVE,
		 upgrade = j->type == PKG_JOBS_UPGRADE;
-
	struct pkg_job_request *req, *tmp, *found;
+
	struct pkg_job_request *req;
	struct pkg_job_request_item *it;
	struct pkg_job_universe_item *un, *cur;
	struct pkg_dep *d;
	struct pkg *lp;
	int (*deps_func)(const struct pkg *pkg, struct pkg_dep **d);
	kvec_t(struct pkg_job_universe_item *) to_process;
+
	pkghash_it hit;

	if (!upgrade && !reverse)
		return;

	kv_init(to_process);
-
	HASH_ITER(hh, j->request_add, req, tmp) {
+
	hit = pkghash_iterator(j->request_add);
+
	while (pkghash_next(&hit)) {
+
		req = hit.value;
		it = req->item;

		if (reverse)
@@ -459,8 +466,7 @@ pkg_jobs_process_add_request(struct pkg_jobs *j)
			/*
			 * Do not add duplicated upgrade candidates
			 */
-
			HASH_FIND_STR(j->request_add, d->uid, found);
-
			if (found != NULL)
+
			if (pkghash_get(j->request_add, d->uid))
				continue;

			pkg_debug(4, "adding dependency %s to request", d->uid);
@@ -505,11 +511,12 @@ static int
pkg_jobs_process_delete_request(struct pkg_jobs *j)
{
	bool force = j->flags & PKG_FLAG_FORCE;
-
	struct pkg_job_request *req, *tmp, *found;
+
	struct pkg_job_request *req;
	struct pkg_dep *d = NULL;
	struct pkg *lp;
	int rc = EPKG_OK;
	kvec_t(struct pkg *) to_process;
+
	pkghash_it it;

	if (force)
		return (EPKG_OK);
@@ -518,11 +525,12 @@ pkg_jobs_process_delete_request(struct pkg_jobs *j)
	/*
	 * Need to add also all reverse deps here
	 */
-
	HASH_ITER(hh, j->request_delete, req, tmp) {
+
	it = pkghash_iterator(j->request_delete);
+
	while (pkghash_next(&it)) {
+
		req = it.value;
		d = NULL;
		while (pkg_rdeps(req->item->pkg, &d) == EPKG_OK) {
-
			HASH_FIND_STR(j->request_delete, d->uid, found);
-
			if (found)
+
			if (pkghash_get(j->request_delete, d->uid))
				continue;

			lp = pkg_jobs_universe_get_local(j->universe, d->uid, 0);
@@ -1067,7 +1075,7 @@ pkg_jobs_find_remote_pattern(struct pkg_jobs *j, struct job_pattern *jp)
			pkg->type = PKG_FILE;
			pkg_jobs_add_req(j, pkg);

-
			HASH_FIND_STR(j->request_add, pkg->uid, req);
+
			req = pkghash_get_value(j->request_add, pkg->uid);
			if (req != NULL)
				req->item->jp = jp;
		}
@@ -1321,7 +1329,7 @@ pkg_jobs_propagate_automatic(struct pkg_jobs *j)
			 * For packages that are alone in the installation list
			 * we search them in the corresponding request
			 */
-
			HASH_FIND_STR(j->request_add, unit->pkg->uid, req);
+
			req = pkghash_get_value(j->request_add, unit->pkg->uid);
			if ((req == NULL || req->automatic) &&
			    unit->pkg->type != PKG_INSTALLED) {
				automatic = true;
@@ -1366,7 +1374,7 @@ pkg_jobs_propagate_automatic(struct pkg_jobs *j)
				 *
				 * See #1374
				 */
-
				HASH_FIND_STR(j->request_add, unit->pkg->uid, req);
+
				req = pkghash_get_value(j->request_add, unit->pkg->uid);
				if ((req == NULL || req->automatic)) {
					automatic = true;
					pkg_debug(2, "set automatic flag for %s", unit->pkg->uid);
@@ -1394,7 +1402,7 @@ pkg_jobs_find_deinstall_request(struct pkg_job_universe_item *item,
		return (NULL);
	}

-
	HASH_FIND_STR(j->request_delete, pkg->uid, found);
+
	found = pkghash_get_value(j->request_delete, pkg->uid);
	if (found == NULL) {
		while (pkg_deps(pkg, &d) == EPKG_OK) {
			dep_item = pkg_jobs_universe_find(j->universe, d->uid);
@@ -1590,8 +1598,9 @@ jobs_solve_full_upgrade(struct pkg_jobs *j)
	size_t elt_num = 0;
	char sqlbuf[256];
	struct pkg_jobs_install_candidate *candidates, *c;
-
	struct pkg_job_request *req, *rtmp;
+
	struct pkg_job_request *req;
	struct pkgdb_it *it;
+
	pkghash_it hit;
	unsigned flags = PKG_LOAD_BASIC|PKG_LOAD_OPTIONS|PKG_LOAD_DEPS|PKG_LOAD_REQUIRES|
			PKG_LOAD_SHLIBS_REQUIRED|PKG_LOAD_ANNOTATIONS|PKG_LOAD_CONFLICTS;

@@ -1622,7 +1631,9 @@ jobs_solve_full_upgrade(struct pkg_jobs *j)
			jcount);
	elt_num = 0;

-
	HASH_ITER(hh, j->request_add, req, rtmp) {
+
	hit = pkghash_iterator(j->request_add);
+
	while (pkghash_next(&hit)) {
+
		req = hit.value;
		pkg_emit_progress_tick(++elt_num, jcount);
		pkg_jobs_universe_process(j->universe, req->item->pkg);
	}
@@ -1637,9 +1648,10 @@ static int
jobs_solve_partial_upgrade(struct pkg_jobs *j)
{
	struct job_pattern *jp;
-
	struct pkg_job_request *req, *rtmp;
+
	struct pkg_job_request *req;
	bool error_found = false;
	int retcode;
+
	pkghash_it it;

	LL_FOREACH(j->patterns, jp) {
		retcode = pkg_jobs_find_remote_pattern(j, jp);
@@ -1669,7 +1681,10 @@ jobs_solve_partial_upgrade(struct pkg_jobs *j)
	/*
	 * Need to iterate request one more time to recurse depends
	 */
-
	HASH_ITER(hh, j->request_add, req, rtmp) {
+

+
	it = pkghash_iterator(j->request_add);
+
	while (pkghash_next(&it)) {
+
		req = it.value;
		pkg_jobs_universe_process(j->universe, req->item->pkg);
	}
	return (EPKG_OK);
@@ -1678,8 +1693,9 @@ jobs_solve_partial_upgrade(struct pkg_jobs *j)
static int
jobs_solve_install_upgrade(struct pkg_jobs *j)
{
-
	struct pkg_job_request *req, *rtmp;
+
	struct pkg_job_request *req;
	int retcode = 0;
+
	pkghash_it it;

	/* Check for new pkg. Skip for 'upgrade -F'. */
	if (((j->flags & PKG_FLAG_SKIP_INSTALL) == 0 &&
@@ -1714,7 +1730,9 @@ jobs_solve_install_upgrade(struct pkg_jobs *j)
		 * If we have tried to solve request, then we just want to re-add all
		 * request packages to the universe to find out any potential conflicts
		 */
-
		HASH_ITER(hh, j->request_add, req, rtmp) {
+
		it = pkghash_iterator(j->request_add);
+
		while (pkghash_next(&it)) {
+
			req = it.value;
			pkg_jobs_universe_process(j->universe, req->item->pkg);
		}
	}
@@ -1743,7 +1761,8 @@ jobs_solve_fetch(struct pkg_jobs *j)
	struct job_pattern *jp;
	struct pkg *pkg = NULL;
	struct pkgdb_it *it;
-
	struct pkg_job_request *req, *rtmp;
+
	struct pkg_job_request *req;
+
	pkghash_it hit;

	if ((j->flags & PKG_FLAG_UPGRADES_FOR_INSTALLED) == PKG_FLAG_UPGRADES_FOR_INSTALLED) {
		if ((it = pkgdb_query(j->db, NULL, MATCH_ALL)) == NULL)
@@ -1767,8 +1786,11 @@ jobs_solve_fetch(struct pkg_jobs *j)
				pkg_emit_error("No packages matching '%s' have been found in the "
						"repositories", jp->pattern);
		}
-
		HASH_ITER(hh, j->request_add, req, rtmp)
+
		hit = pkghash_iterator(j->request_add);
+
		while (pkghash_next(&hit)) {
+
			req = hit.value;
			pkg_jobs_universe_process(j->universe, req->item->pkg);
+
		}
	}

	j->solved ++;
@@ -2035,7 +2057,7 @@ pkg_jobs_handle_install(struct pkg_solved *ps, struct pkg_jobs *j,
	old = ps->items[1] ? ps->items[1]->pkg : NULL;
	new = ps->items[0]->pkg;

-
	HASH_FIND_STR(j->request_add, new->uid, req);
+
	req = pkghash_get_value(j->request_add, new->uid);
	if (req != NULL && req->item->jp != NULL &&
			(req->item->jp->flags & PKG_PATTERN_FLAG_FILE)) {
		/*
modified libpkg/pkg_jobs_conflicts.c
@@ -125,12 +125,15 @@ pkg_conflicts_request_add_chain(struct pkg_conflict_chain **chain, struct pkg_jo
int
pkg_conflicts_request_resolve(struct pkg_jobs *j)
{
-
	struct pkg_job_request *req, *rtmp, *found;
+
	struct pkg_job_request *req, *found;
	struct pkg_conflict *c;
	struct pkg_conflict_chain *chain;
	struct pkg_job_universe_item *unit;
+
	pkghash_it it;

-
	HASH_ITER(hh, j->request_add, req, rtmp) {
+
	it = pkghash_iterator(j->request_add);
+
	while (pkghash_next(&it)) {
+
		req = it.value;
		chain = NULL;
		if (req->skip)
			continue;
@@ -138,8 +141,8 @@ pkg_conflicts_request_resolve(struct pkg_jobs *j)
		LL_FOREACH(req->item->pkg->conflicts, c) {
			unit = pkg_jobs_universe_find(j->universe, c->uid);
			if (unit != NULL) {
-
				HASH_FIND_STR(j->request_add, unit->pkg->uid, found);
-
				if (found && !found->skip) {
+
				found = pkghash_get_value(j->request_add, unit->pkg->uid);
+
				if (found != NULL && !found->skip) {
					pkg_conflicts_request_add_chain(&chain, found);
				}
			}
modified libpkg/pkg_jobs_universe.c
@@ -1115,7 +1115,7 @@ pkg_jobs_universe_process_upgrade_chains(struct pkg_jobs *j)
		unsigned vercnt = 0;
		unit = (struct pkg_job_universe_item *)it.value;

-
		HASH_FIND_STR(j->request_add, unit->pkg->uid, req);
+
		req = pkghash_get_value(j->request_add, unit->pkg->uid);
		if (req == NULL) {
			/* Not obviously requested */
			continue;
@@ -1131,7 +1131,7 @@ pkg_jobs_universe_process_upgrade_chains(struct pkg_jobs *j)
		if (local != NULL && local->pkg->locked) {
			pkg_debug(1, "removing %s from the request as it is locked",
				cur->pkg->uid);
-
			HASH_DEL(j->request_add, req);
+
			pkghash_del(j->request_add, req->item->pkg->uid);
			pkg_jobs_request_free(req);
			continue;
		}
@@ -1156,7 +1156,7 @@ pkg_jobs_universe_process_upgrade_chains(struct pkg_jobs *j)
			 * candidates
			 */
			assert(selected != NULL);
-
			HASH_DEL(j->request_add, req);
+
			pkghash_del(j->request_add, req->item->pkg->uid);

			/*
			 * We also check if the selected package has different digest,
@@ -1188,8 +1188,7 @@ pkg_jobs_universe_process_upgrade_chains(struct pkg_jobs *j)
				rit->unit = selected;
				DL_APPEND(req->item, rit);
			}
-
			HASH_ADD_KEYPTR(hh, j->request_add, selected->pkg->uid,
-
				strlen (selected->pkg->uid), req);
+
			pkghash_safe_add(j->request_add, selected->pkg->uid, req, NULL);
		}
	}
}
modified libpkg/pkg_solve.c
@@ -756,10 +756,10 @@ pkg_solve_process_universe_variable(struct pkg_solve_problem *problem,

		/* Request */
		if (!(cur_var->flags & PKG_VAR_TOP)) {
-
			HASH_FIND_STR(j->request_add, cur_var->uid, jreq);
+
			jreq = pkghash_get_value(j->request_add, cur_var->uid);
			if (jreq != NULL)
				pkg_solve_add_request_rule(problem, cur_var, jreq, 1);
-
			HASH_FIND_STR(j->request_delete, cur_var->uid, jreq);
+
			jreq = pkghash_get_value(j->request_delete, cur_var->uid);
			if (jreq != NULL)
				pkg_solve_add_request_rule(problem, cur_var, jreq, -1);
		}
modified libpkg/private/pkg_jobs.h
@@ -58,7 +58,6 @@ struct pkg_job_request {
	struct pkg_job_request_item *item;
	bool skip;
	bool automatic;
-
	UT_hash_handle hh;
};

struct pkg_solved {
@@ -98,8 +97,8 @@ struct pkg_jobs_conflict_item {

struct pkg_jobs {
	struct pkg_jobs_universe *universe;
-
	struct pkg_job_request	*request_add;
-
	struct pkg_job_request	*request_delete;
+
	pkghash	*request_add;
+
	pkghash	*request_delete;
	struct pkg_solved *jobs;
	struct pkgdb	*db;
	pkg_jobs_t	 type;