From e200688a5b7565101764a0ba09b431c412952167 Mon Sep 17 00:00:00 2001 From: Michael Schroeder Date: Wed, 14 May 2008 08:34:06 +0000 Subject: [PATCH] - change some comments - add solver_printtrivial debug function, use it in yps and deptestomatic - remove some assertions, return SOLVER_PROBLEM_RPM_RULE instead (we do not want to crash libzypp if we forgot to handle some case) --- src/solver.c | 98 +++++++++++++++++++++++++++++++------------------------ src/solver.h | 3 +- src/solverdebug.c | 68 +++++++++++++++++++++++++++++++------- src/solverdebug.h | 1 + 4 files changed, 115 insertions(+), 55 deletions(-) diff --git a/src/solver.c b/src/solver.c index 4b52b8e..f858db8 100644 --- a/src/solver.c +++ b/src/solver.c @@ -1546,6 +1546,7 @@ addwatches_rule(Solver *solv, Rule *r) */ #define DECISIONMAP_TRUE(p) ((p) > 0 ? (decisionmap[p] > 0) : (decisionmap[-p] < 0)) #define DECISIONMAP_FALSE(p) ((p) > 0 ? (decisionmap[p] < 0) : (decisionmap[-p] > 0)) +#define DECISIONMAP_UNDEF(p) (decisionmap[(p) > 0 ? (p) : -(p)] == 0) /*------------------------------------------------------------------- * @@ -1632,37 +1633,36 @@ propagate(Solver *solv, int level) continue; /* - * The other literal is false or undecided + * The other literal is FALSE or UNDEF */ if (r->d) { - /* not a binary clause, check if we need to move our watch. - * - * search for a literal that is not other_watch and not false - * (true is also ok, in that case the rule is fulfilled) + /* not a binary clause, try to move our watch. + * search for a literal that is not other_watch and not FALSE + * (TRUE is also ok, in that case the rule is fulfilled) */ if (r->p /* we have a 'p' */ - && r->p != other_watch /* which is not what we just checked */ - && !DECISIONMAP_TRUE(-r->p)) /* and its not already decided 'negative' */ + && r->p != other_watch /* which is watched */ + && !DECISIONMAP_FALSE(r->p)) /* and not FALSE */ { - p = r->p; /* we must get this to 'true' */ + p = r->p; } else /* go find a 'd' to make 'true' */ { /* foreach 'd' */ - /* FIXME: should be a policy */ for (dp = pool->whatprovidesdata + r->d; (p = *dp++) != 0;) - if (p != other_watch /* which is not what we just checked */ - && !DECISIONMAP_TRUE(-p)) /* and its not already decided 'negative' */ + if (p != other_watch /* which is not watched */ + && !DECISIONMAP_FALSE(p)) /* and not FALSE */ break; } - /* - * if p is free to watch, move watch to p - */ if (p) { + /* + * if we found some p that is UNDEF or TRUE, move + * watch to it + */ IF_POOLDEBUG (SAT_DEBUG_PROPAGATE) { if (p > 0) @@ -1687,8 +1687,7 @@ propagate(Solver *solv, int level) watches[p] = r - solv->rules; continue; } - - /* !p */ + /* search failed, thus all unwatched literals are FALSE */ } /* not binary */ @@ -1696,7 +1695,7 @@ propagate(Solver *solv, int level) * unit clause found, set literal other_watch to TRUE */ - if (DECISIONMAP_TRUE(-other_watch)) /* check if literal is FALSE */ + if (DECISIONMAP_FALSE(other_watch)) /* check if literal is FALSE */ return r; /* eek, a conflict! */ IF_POOLDEBUG (SAT_DEBUG_PROPAGATE) @@ -3220,17 +3219,20 @@ solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, return SOLVER_PROBLEM_NOTHING_PROVIDES_DEP; } } - assert(!solv->allowselfconflicts); - assert(s->conflicts); - conp = s->repo->idarraydata + s->conflicts; - while ((con = *conp++) != 0) - FOR_PROVIDES(p, pp, con) - if (p == -r->p) - { - *depp = con; - return SOLVER_PROBLEM_SELF_CONFLICT; - } - assert(0); + if (!solv->allowselfconflicts && s->conflicts) + { + conp = s->repo->idarraydata + s->conflicts; + while ((con = *conp++) != 0) + FOR_PROVIDES(p, pp, con) + if (p == -r->p) + { + *depp = con; + return SOLVER_PROBLEM_SELF_CONFLICT; + } + } + /* should never happen */ + *depp = 0; + return SOLVER_PROBLEM_RPM_RULE; } s = pool->solvables - r->p; if (installed && !solv->fixsystem && s->repo == installed) @@ -3359,29 +3361,41 @@ solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, } } /* all cases checked, can't happen */ - assert(0); + *depp = 0; + *sourcep = -r->p; + *targetp = 0; + return SOLVER_PROBLEM_RPM_RULE; } /* simple requires */ - assert(s->requires); - reqp = s->repo->idarraydata + s->requires; - while ((req = *reqp++) != 0) + if (s->requires) { - if (req == SOLVABLE_PREREQMARKER) - continue; - dp = pool_whatprovides(pool, req); - if (d == 0) + reqp = s->repo->idarraydata + s->requires; + while ((req = *reqp++) != 0) { - if (*dp == r->w2 && dp[1] == 0) + if (req == SOLVABLE_PREREQMARKER) + continue; + dp = pool_whatprovides(pool, req); + if (d == 0) + { + if (*dp == r->w2 && dp[1] == 0) + break; + } + else if (dp - pool->whatprovidesdata == d) break; } - else if (dp - pool->whatprovidesdata == d) - break; + if (req) + { + *depp = req; + *sourcep = -r->p; + *targetp = 0; + return SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE; + } } - assert(req); - *depp = req; + /* all cases checked, can't happen */ + *depp = 0; *sourcep = -r->p; *targetp = 0; - return SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE; + return SOLVER_PROBLEM_RPM_RULE; } diff --git a/src/solver.h b/src/solver.h index eb6d306..e3b5ace 100644 --- a/src/solver.h +++ b/src/solver.h @@ -236,7 +236,8 @@ typedef enum { SOLVER_PROBLEM_PACKAGE_CONFLICT, SOLVER_PROBLEM_PACKAGE_OBSOLETES, SOLVER_PROBLEM_DEP_PROVIDERS_NOT_INSTALLABLE, - SOLVER_PROBLEM_SELF_CONFLICT + SOLVER_PROBLEM_SELF_CONFLICT, + SOLVER_PROBLEM_RPM_RULE } SolverProbleminfo; diff --git a/src/solverdebug.c b/src/solverdebug.c index b086f76..84166de 100644 --- a/src/solverdebug.c +++ b/src/solverdebug.c @@ -263,6 +263,9 @@ solver_printdecisions(Solver *solv) POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions end -----\n"); } + POOL_DEBUG(SAT_DEBUG_RESULT, "\n"); + POOL_DEBUG(SAT_DEBUG_RESULT, "transaction:\n"); + /* print solvables to be erased */ if (installed) @@ -273,7 +276,7 @@ solver_printdecisions(Solver *solv) continue; if (obsoletesmap[p]) continue; - POOL_DEBUG(SAT_DEBUG_RESULT, "erase %s\n", solvable2str(pool, s)); + POOL_DEBUG(SAT_DEBUG_RESULT, " erase %s\n", solvable2str(pool, s)); } } @@ -293,7 +296,7 @@ solver_printdecisions(Solver *solv) if (!obsoletesmap[p]) { - POOL_DEBUG(SAT_DEBUG_RESULT, "install %s", solvable2str(pool, s)); + POOL_DEBUG(SAT_DEBUG_RESULT, " install %s", solvable2str(pool, s)); } else { @@ -307,9 +310,9 @@ solver_printdecisions(Solver *solv) break; } if (xp) - POOL_DEBUG(SAT_DEBUG_RESULT, "downgrade %s", solvable2str(pool, s)); + POOL_DEBUG(SAT_DEBUG_RESULT, " downgrade %s", solvable2str(pool, s)); else - POOL_DEBUG(SAT_DEBUG_RESULT, "upgrade %s", solvable2str(pool, s)); + POOL_DEBUG(SAT_DEBUG_RESULT, " upgrade %s", solvable2str(pool, s)); POOL_DEBUG(SAT_DEBUG_RESULT, " (obsoletes"); for (j = installed->start; j < installed->end; j++) if (obsoletesmap[j] == p) @@ -318,43 +321,46 @@ solver_printdecisions(Solver *solv) } POOL_DEBUG(SAT_DEBUG_RESULT, "\n"); } + POOL_DEBUG(SAT_DEBUG_RESULT, "\n"); sat_free(obsoletesmap); if (solv->recommendations.count) { - POOL_DEBUG(SAT_DEBUG_RESULT, "\nrecommended packages:\n"); + POOL_DEBUG(SAT_DEBUG_RESULT, "recommended packages:\n"); for (i = 0; i < solv->recommendations.count; i++) { s = pool->solvables + solv->recommendations.elements[i]; if (solv->decisionmap[solv->recommendations.elements[i]] > 0) { if (installed && s->repo == installed) - POOL_DEBUG(SAT_DEBUG_RESULT, "- %s (installed)\n", solvable2str(pool, s)); + POOL_DEBUG(SAT_DEBUG_RESULT, " %s (installed)\n", solvable2str(pool, s)); else - POOL_DEBUG(SAT_DEBUG_RESULT, "- %s (selected)\n", solvable2str(pool, s)); + POOL_DEBUG(SAT_DEBUG_RESULT, " %s (selected)\n", solvable2str(pool, s)); } else - POOL_DEBUG(SAT_DEBUG_RESULT, "- %s\n", solvable2str(pool, s)); + POOL_DEBUG(SAT_DEBUG_RESULT, " %s\n", solvable2str(pool, s)); } + POOL_DEBUG(SAT_DEBUG_RESULT, "\n"); } if (solv->suggestions.count) { - POOL_DEBUG(SAT_DEBUG_RESULT, "\nsuggested packages:\n"); + POOL_DEBUG(SAT_DEBUG_RESULT, "suggested packages:\n"); for (i = 0; i < solv->suggestions.count; i++) { s = pool->solvables + solv->suggestions.elements[i]; if (solv->decisionmap[solv->suggestions.elements[i]] > 0) { if (installed && s->repo == installed) - POOL_DEBUG(SAT_DEBUG_RESULT, "- %s (installed)\n", solvable2str(pool, s)); + POOL_DEBUG(SAT_DEBUG_RESULT, " %s (installed)\n", solvable2str(pool, s)); else - POOL_DEBUG(SAT_DEBUG_RESULT, "- %s (selected)\n", solvable2str(pool, s)); + POOL_DEBUG(SAT_DEBUG_RESULT, " %s (selected)\n", solvable2str(pool, s)); } else - POOL_DEBUG(SAT_DEBUG_RESULT, "- %s\n", solvable2str(pool, s)); + POOL_DEBUG(SAT_DEBUG_RESULT, " %s\n", solvable2str(pool, s)); } + POOL_DEBUG(SAT_DEBUG_RESULT, "\n"); } } @@ -376,6 +382,9 @@ solver_printprobleminfo(Solver *solv, Queue *job, Id problem) case SOLVER_PROBLEM_JOB_RULE: POOL_DEBUG(SAT_DEBUG_RESULT, "conflicting requests\n"); return; + case SOLVER_PROBLEM_RPM_RULE: + POOL_DEBUG(SAT_DEBUG_RESULT, "some dependency problem\n"); + return; case SOLVER_PROBLEM_JOB_NOTHING_PROVIDES_DEP: POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides requested %s\n", dep2str(pool, dep)); return; @@ -520,3 +529,38 @@ solver_printsolutions(Solver *solv, Queue *job) } } +void +solver_printtrivial(Solver *solv) +{ + Pool *pool = solv->pool; + Queue in, out; + Map installedmap; + Id p; + const char *n; + Solvable *s; + int i; + + queue_init(&in); + for (p = 1, s = pool->solvables + p; p < solv->pool->nsolvables; p++, s++) + { + n = id2str(pool, s->name); + if (strncmp(n, "patch:", 6) != 0 && strncmp(n, "pattern:", 8) != 0) + continue; + queue_push(&in, p); + } + if (!in.count) + { + queue_free(&in); + return; + } + solver_create_state_maps(solv, &installedmap, 0); + queue_init(&out); + pool_trivial_installable(pool, solv->installed, &installedmap, &in, &out); + POOL_DEBUG(SAT_DEBUG_RESULT, "trivial installable status:\n"); + for (i = 0; i < in.count; i++) + POOL_DEBUG(SAT_DEBUG_RESULT, " %s: %d\n", solvable2str(pool, pool->solvables + in.elements[i]), out.elements[i]); + POOL_DEBUG(SAT_DEBUG_RESULT, "\n"); + map_free(&installedmap); + queue_free(&in); + queue_free(&out); +} diff --git a/src/solverdebug.h b/src/solverdebug.h index ebf39f9..cb90fdb 100644 --- a/src/solverdebug.h +++ b/src/solverdebug.h @@ -26,6 +26,7 @@ extern void solver_printwatches(Solver *solv, int type); extern void solver_printdecisions(Solver *solv); extern void solver_printprobleminfo(Solver *solv, Queue *job, Id problem); extern void solver_printsolutions(Solver *solv, Queue *job); +extern void solver_printtrivial(Solver *solv); #endif /* SATSOLVER_SOLVERDEBUG_H */ -- 2.7.4