Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Simplify free macros.
Vsevolod Stakhov committed 12 years ago
commit e1f8a53a4f425d4cd7deebbdfc11474606c3abab
parent 892362b
9 files changed +74 -67
modified libpkg/pkg.c
@@ -1131,47 +1131,47 @@ void
pkg_list_free(struct pkg *pkg, pkg_list list)  {
	switch (list) {
	case PKG_DEPS:
-
		HASH_FREE(pkg->deps, pkg_dep, pkg_dep_free);
+
		HASH_FREE(pkg->deps, pkg_dep_free);
		pkg->flags &= ~PKG_LOAD_DEPS;
		break;
	case PKG_RDEPS:
-
		HASH_FREE(pkg->rdeps, pkg_dep, pkg_dep_free);
+
		HASH_FREE(pkg->rdeps, pkg_dep_free);
		pkg->flags &= ~PKG_LOAD_RDEPS;
		break;
	case PKG_LICENSES:
-
		HASH_FREE(pkg->licenses, pkg_license, pkg_license_free);
+
		HASH_FREE(pkg->licenses, pkg_license_free);
		pkg->flags &= ~PKG_LOAD_LICENSES;
		break;
	case PKG_OPTIONS:
-
		HASH_FREE(pkg->options, pkg_option, pkg_option_free);
+
		HASH_FREE(pkg->options, pkg_option_free);
		pkg->flags &= ~PKG_LOAD_OPTIONS;
		break;
	case PKG_CATEGORIES:
-
		HASH_FREE(pkg->categories, pkg_category, free);
+
		HASH_FREE(pkg->categories, free);
		pkg->flags &= ~PKG_LOAD_CATEGORIES;
		break;
	case PKG_FILES:
-
		HASH_FREE(pkg->files, pkg_file, pkg_file_free);
+
		HASH_FREE(pkg->files, pkg_file_free);
		pkg->flags &= ~PKG_LOAD_FILES;
		break;
	case PKG_DIRS:
-
		HASH_FREE(pkg->dirs, pkg_dir, pkg_dir_free);
+
		HASH_FREE(pkg->dirs, pkg_dir_free);
		pkg->flags &= ~PKG_LOAD_DIRS;
		break;
	case PKG_USERS:
-
		HASH_FREE(pkg->users, pkg_user, pkg_user_free);
+
		HASH_FREE(pkg->users, pkg_user_free);
		pkg->flags &= ~PKG_LOAD_USERS;
		break;
	case PKG_GROUPS:
-
		HASH_FREE(pkg->groups, pkg_group, pkg_group_free);
+
		HASH_FREE(pkg->groups, pkg_group_free);
		pkg->flags &= ~PKG_LOAD_GROUPS;
		break;
	case PKG_SHLIBS_REQUIRED:
-
		HASH_FREE(pkg->shlibs_required, pkg_shlib, pkg_shlib_free);
+
		HASH_FREE(pkg->shlibs_required, pkg_shlib_free);
		pkg->flags &= ~PKG_LOAD_SHLIBS_REQUIRED;
		break;
	case PKG_SHLIBS_PROVIDED:
-
		HASH_FREE(pkg->shlibs_provided, pkg_shlib, pkg_shlib_free);
+
		HASH_FREE(pkg->shlibs_provided, pkg_shlib_free);
		pkg->flags &= ~PKG_LOAD_SHLIBS_PROVIDED;
		break;
	case PKG_ANNOTATIONS:
@@ -1182,11 +1182,11 @@ pkg_list_free(struct pkg *pkg, pkg_list list) {
		pkg->flags &= ~PKG_LOAD_ANNOTATIONS;
		break;
	case PKG_CONFLICTS:
-
		HASH_FREE(pkg->conflicts, pkg_conflict, pkg_conflict_free);
+
		HASH_FREE(pkg->conflicts, pkg_conflict_free);
		pkg->flags &= ~PKG_LOAD_CONFLICTS;
		break;
	case PKG_PROVIDES:
-
		HASH_FREE(pkg->provides, pkg_provide, pkg_provide_free);
+
		HASH_FREE(pkg->provides, pkg_provide_free);
		pkg->flags &= ~PKG_LOAD_PROVIDES;
		break;
	}
modified libpkg/pkg_config.c
@@ -878,7 +878,7 @@ pkg_shutdown(void)
	}

	ucl_object_unref(config);
-
	HASH_FREE(repos, pkg_repo, pkg_repo_free);
+
	HASH_FREE(repos, pkg_repo_free);

	parsed = false;

modified libpkg/pkg_conflicts.c
@@ -134,10 +134,10 @@ pkg_conflicts_request_resolve(struct pkg_jobs *j)
			pkg_conflicts_request_add_chain(&chain, req);

			if (pkg_conflicts_request_resolve_chain(req->item->pkg, chain) != EPKG_OK) {
-
				LL_FREE(chain, pkg_conflict_chain, free);
+
				LL_FREE(chain, free);
				return (EPKG_FATAL);
			}
-
			LL_FREE(chain, pkg_conflict_chain, free);
+
			LL_FREE(chain, free);
		}
	}

modified libpkg/pkg_jobs.c
@@ -127,9 +127,9 @@ pkg_jobs_free(struct pkg_jobs *j)
			free(cur);
		}
	}
-
	HASH_FREE(j->seen, pkg_job_seen, free);
-
	HASH_FREE(j->patterns, job_pattern, pkg_jobs_pattern_free);
-
	LL_FREE(j->jobs, pkg_solved, free);
+
	HASH_FREE(j->seen, free);
+
	HASH_FREE(j->patterns, pkg_jobs_pattern_free);
+
	LL_FREE(j->jobs, free);

	free(j);
}
@@ -1916,7 +1916,7 @@ pkg_jobs_apply(struct pkg_jobs *j)
					rc = pkg_jobs_check_conflicts(j);
					if (rc == EPKG_CONFLICT) {
						/* Cleanup results */
-
						LL_FREE(j->jobs, pkg_solved, free);
+
						LL_FREE(j->jobs, free);
						j->jobs = NULL;
						j->count = 0;
						has_conflicts = true;
modified libpkg/pkg_manifest.c
@@ -164,7 +164,7 @@ pkg_manifest_keys_new(struct pkg_manifest_key **key)

static void
pmk_free(struct pkg_manifest_key *key) {
-
	HASH_FREE(key->parser, dataparser, free);
+
	HASH_FREE(key->parser, free);

	free(key);
}
@@ -175,7 +175,7 @@ pkg_manifest_keys_free(struct pkg_manifest_key *key)
	if (key == NULL)
		return;

-
	HASH_FREE(key, pkg_manifest_key, pmk_free);
+
	HASH_FREE(key, pmk_free);
}

static int
modified libpkg/pkg_ports.c
@@ -642,7 +642,7 @@ populate_keywords(struct plist *p)
static void
keyword_free(struct keyword *k)
{
-
	LL_FREE(k->actions, action, free);
+
	LL_FREE(k->actions, free);

	free(k);
}
@@ -1016,9 +1016,9 @@ ports_parse_plist(struct pkg *pkg, const char *plist, const char *stage)
	flush_script_buffer(pplist.post_upgrade_buf, pkg,
	    PKG_SCRIPT_POST_UPGRADE);

-
	HASH_FREE(pplist.hardlinks, hardlinks, free);
+
	HASH_FREE(pplist.hardlinks, free);

-
	HASH_FREE(pplist.keywords, keyword, keyword_free);
+
	HASH_FREE(pplist.keywords, keyword_free);

	if (pplist.pkgdep != NULL)
		free(pplist.pkgdep);
modified libpkg/pkg_solve.c
@@ -35,6 +35,7 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>
+
#include <math.h>

#include "pkg.h"
#include "private/event.h"
@@ -254,34 +255,32 @@ pkg_solve_propagate_pure(struct pkg_solve_problem *problem)
 * @return true if guess is accepted
 */
bool
-
pkg_solve_test_guess(struct pkg_solve_problem *problem)
+
pkg_solve_test_guess(struct pkg_solve_problem *problem, struct pkg_solve_variable *var)
{
	bool test = false;
-
	struct pkg_solve_variable *var, *tvar;
	struct _pkg_solve_var_rule *rul;
	struct pkg_solve_item *it, *cur;

-
	HASH_ITER(hd, problem->variables_by_digest, var, tvar) {
-
		LL_FOREACH(var->rules, rul) {
-
			it = rul->rule;
-
			if (it->nitems != it->nresolved) {
-
				/* Check guess */
-
				test = false;
-
				LL_FOREACH(it, cur) {
-
					if (cur->var->resolved)
-
						test |= cur->var->to_install ^ cur->inverse;
-
					else
-
						test |= cur->var->guess ^ cur->inverse;
-
				}
-
				if (!test) {
-
					pkg_debug(2, "solver: guess test failed at variable %s", var->origin);
-
					pkg_debug_print_rule(it);
-
					return (false);
-
				}
+
	LL_FOREACH(var->rules, rul) {
+
		it = rul->rule;
+
		if (it->nitems != it->nresolved) {
+
			/* Check guess */
+
			test = false;
+
			LL_FOREACH(it, cur) {
+
				if (cur->var->resolved)
+
					test |= cur->var->to_install ^ cur->inverse;
+
				else
+
					test |= cur->var->guess ^ cur->inverse;
+
			}
+
			if (!test) {
+
				pkg_debug(2, "solver: guess test failed at variable %s", var->origin);
+
				pkg_debug_print_rule(it);
+
				return (false);
			}
		}
	}

+

	return (true);
}

@@ -295,9 +294,16 @@ pkg_solve_test_guess(struct pkg_solve_problem *problem)
bool
pkg_solve_sat_problem(struct pkg_solve_problem *problem)
{
-
	int propagated, iters = 0;
+
	int propagated;
	bool guessed = false;
	struct pkg_solve_variable *var, *tvar;
+
	int64_t unresolved = 0, iters = 0;
+

+
	struct _solver_tree_elt {
+
		struct pkg_solve_variable *var;
+
		struct _solver_tree_elt *prev, *next;
+
	} *solver_tree = NULL, *elt;
+


	/* Obvious case */
	if (problem->rules_count == 0)
@@ -315,24 +321,23 @@ pkg_solve_sat_problem(struct pkg_solve_problem *problem)
		if (!var->resolved) {
			/* Guess true for installed packages and false otherwise */
			var->guess = (var->unit->pkg->type == PKG_INSTALLED) ? true : false;
-
		}
-
	}
-

-
	while (!guessed) {
-
		HASH_ITER(hd, problem->variables_by_digest, var, tvar) {
-
			if (pkg_solve_test_guess(problem)) {
-
				guessed = true;
-
				break;
-
			}
-
			else {
+
			unresolved ++;
+
			if (!pkg_solve_test_guess(problem, var)) {
				var->guess = !var->guess;
-
				if (pkg_solve_test_guess(problem)) {
-
					guessed = true;
-
					break;
+
				if (!pkg_solve_test_guess(problem, var)) {
+
					/* Need to backtrack */
+
					iters ++;
				}
			}
+
			/* Add new element to the backtracking queue */
+
			elt = malloc (sizeof (*elt));
+
			if (elt == NULL) {
+
				pkg_emit_errno("malloc", "_solver_tree_elt");
+
				return (false);
+
			}
+
			elt->var = var;
+
			DL_APPEND(solver_tree, elt);
		}
-
		iters ++;
	}

	pkg_debug(1, "solved SAT problem in %d guesses", iters);
@@ -344,6 +349,8 @@ pkg_solve_sat_problem(struct pkg_solve_problem *problem)
		}
	}

+
	LL_FREE(solver_tree, free);
+

	return (true);
}

@@ -860,7 +867,7 @@ pkg_solve_dimacs_export(struct pkg_solve_problem *problem, FILE *f)
		fprintf(f, "0\n");
	}

-
	HASH_FREE(ordered_variables, pkg_solve_ordered_variable, free);
+
	HASH_FREE(ordered_variables, free);

	return (EPKG_OK);
}
@@ -1019,7 +1026,7 @@ pkg_solve_parse_sat_output(FILE *f, struct pkg_solve_problem *problem, struct pk
		ret = EPKG_FATAL;
	}

-
	HASH_FREE(ordered_variables, pkg_solve_ordered_variable, free);
+
	HASH_FREE(ordered_variables, free);
	if (line != NULL)
		free(line);
	return (ret);
modified libpkg/plugins.c
@@ -78,7 +78,7 @@ pkg_plugin_hook_free(struct pkg_plugin *p)
{
	assert(p != NULL);

-
	HASH_FREE(p->hooks, plugin_hook, free);
+
	HASH_FREE(p->hooks, free);

	return (EPKG_OK);
}
@@ -98,7 +98,7 @@ plug_free(struct pkg_plugin *p)
static int
pkg_plugin_free(void)
{
-
	LL_FREE(plugins, pkg_plugin, plug_free);
+
	LL_FREE(plugins, plug_free);

	return (EPKG_OK);
}
modified libpkg/private/pkg.h
@@ -62,8 +62,8 @@
		ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_ACL | \
		ARCHIVE_EXTRACT_FFLAGS|ARCHIVE_EXTRACT_XATTR)

-
#define HASH_FREE(data, type, free_func) do {      \
-
	struct type *hf1, *hf2;                    \
+
#define HASH_FREE(data, free_func) do {      \
+
	__typeof(data) hf1, hf2;                    \
	HASH_ITER(hh, data, hf1, hf2) {            \
		HASH_DEL(data, hf1);               \
		free_func(hf1);                    \
@@ -71,8 +71,8 @@
	data = NULL;                               \
} while (0)

-
#define LL_FREE(head, type, free_func) do {   \
-
	struct type *l1, *l2;                 \
+
#define LL_FREE(head, free_func) do {   \
+
	__typeof(head) l1, l2;                 \
	LL_FOREACH_SAFE(head, l1, l2) {       \
		LL_DELETE(head, l1);          \
		free_func(l1);                \