From 76fb56c0d4b829859fefa6a744c0183b4c3db00f Mon Sep 17 00:00:00 2001 From: Michael Schroeder Date: Mon, 6 Jun 2011 17:17:29 +0200 Subject: [PATCH] [backend] more introspection: solver_ruleliterals, solver_rule2jobidx, solver_rule2job --- src/libsolv.ver | 3 +++ src/problems.c | 4 ++-- src/rules.c | 42 +++++++++++++++++++++++++++++++++++++++++- src/rules.h | 40 ++++++++++++++++++++++------------------ src/solver.c | 4 ++-- 5 files changed, 70 insertions(+), 23 deletions(-) diff --git a/src/libsolv.ver b/src/libsolv.ver index f674226..474877f 100644 --- a/src/libsolv.ver +++ b/src/libsolv.ver @@ -275,7 +275,10 @@ SOLV_1.0 { solver_printwatches; solver_problem_count; solver_problemruleinfo2str; + solver_rule2job; + solver_rule2jobidx; solver_ruleinfo; + solver_ruleliterals; solver_samerule; solver_select2str; solver_solution_count; diff --git a/src/problems.c b/src/problems.c index 565ed9a..14e64b9 100644 --- a/src/problems.c +++ b/src/problems.c @@ -207,7 +207,7 @@ refine_suggestion(Solver *solv, Id *problem, Id sug, Queue *refined, int essenti solver_enableproblem(solv, problem[i]); if (sug < 0) - solver_reenablepolicyrules(solv, -(sug + 1)); + solver_reenablepolicyrules(solv, -sug); else if (sug >= solv->updaterules && sug < solv->updaterules_end) { /* enable feature rule */ @@ -292,7 +292,7 @@ refine_suggestion(Solver *solv, Id *problem, Id sug, Queue *refined, int essenti solver_enablerule(solv, r); /* enable corresponding feature rule */ } if (v < 0) - solver_reenablepolicyrules(solv, -(v + 1)); + solver_reenablepolicyrules(solv, -v); } else { diff --git a/src/rules.c b/src/rules.c index af8ca3c..cb75b70 100644 --- a/src/rules.c +++ b/src/rules.c @@ -1610,7 +1610,7 @@ solver_reenablepolicyrules(Solver *solv, int jobidx) queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf)); queue_init_buffer(&allq, allqbuf, sizeof(allqbuf)/sizeof(*allqbuf)); - jobtodisablelist(solv, job->elements[jobidx], job->elements[jobidx + 1], &q); + jobtodisablelist(solv, job->elements[jobidx - 1], job->elements[jobidx], &q); if (!q.count) return; for (i = solv->jobrules; i < solv->jobrules_end; i++) @@ -1922,6 +1922,46 @@ solver_ruleinfo(Solver *solv, Id rid, Id *fromp, Id *top, Id *depp) } void +solver_ruleliterals(Solver *solv, Id rid, Queue *q) +{ + Pool *pool = solv->pool; + Id p, *pp; + Rule *r; + + queue_empty(q); + r = solv->rules + rid; + FOR_RULELITERALS(p, pp, r) + if (p != -SYSTEMSOLVABLE) + queue_push(q, p); + if (!q->count) + queue_push(q, -SYSTEMSOLVABLE); /* hmm, better to return an empty result? */ +} + +int +solver_rule2jobidx(Solver *solv, Id rid) +{ + if (rid < solv->jobrules || rid >= solv->jobrules_end) + return 0; + return solv->ruletojob.elements[rid - solv->jobrules] + 1; +} + +Id +solver_rule2job(Solver *solv, Id rid, Id *whatp) +{ + int idx; + if (rid < solv->jobrules || rid >= solv->jobrules_end) + { + if (whatp) + *whatp = 0; + return 0; + } + idx = solv->ruletojob.elements[rid - solv->jobrules]; + if (whatp) + *whatp = solv->job.elements[idx + 1]; + return solv->job.elements[idx]; +} + +void solver_addchoicerules(Solver *solv) { Pool *pool = solv->pool; diff --git a/src/rules.h b/src/rules.h index 0117722..d954a95 100644 --- a/src/rules.h +++ b/src/rules.h @@ -94,37 +94,41 @@ solver_enablerule(struct _Solver *solv, Rule *r) r->d = -r->d - 1; } -Rule *solver_addrule(struct _Solver *solv, Id p, Id d); -void solver_unifyrules(struct _Solver *solv); -int solver_samerule(struct _Solver *solv, Rule *r1, Rule *r2); +extern Rule *solver_addrule(struct _Solver *solv, Id p, Id d); +extern void solver_unifyrules(struct _Solver *solv); +extern int solver_samerule(struct _Solver *solv, Rule *r1, Rule *r2); /* rpm rules */ -void solver_addrpmrulesforsolvable(struct _Solver *solv, Solvable *s, Map *m); -void solver_addrpmrulesforweak(struct _Solver *solv, Map *m); -void solver_addrpmrulesforupdaters(struct _Solver *solv, Solvable *s, Map *m, int allow_all); +extern void solver_addrpmrulesforsolvable(struct _Solver *solv, Solvable *s, Map *m); +extern void solver_addrpmrulesforweak(struct _Solver *solv, Map *m); +extern void solver_addrpmrulesforupdaters(struct _Solver *solv, Solvable *s, Map *m, int allow_all); /* update/feature rules */ -void solver_addupdaterule(struct _Solver *solv, Solvable *s, int allow_all); +extern void solver_addupdaterule(struct _Solver *solv, Solvable *s, int allow_all); /* infarch rules */ -void solver_addinfarchrules(struct _Solver *solv, Map *addedmap); +extern void solver_addinfarchrules(struct _Solver *solv, Map *addedmap); /* dup rules */ -void solver_createdupmaps(struct _Solver *solv); -void solver_freedupmaps(struct _Solver *solv); -void solver_addduprules(struct _Solver *solv, Map *addedmap); +extern void solver_createdupmaps(struct _Solver *solv); +extern void solver_freedupmaps(struct _Solver *solv); +extern void solver_addduprules(struct _Solver *solv, Map *addedmap); + +/* choice rules */ +extern void solver_addchoicerules(struct _Solver *solv); +extern void solver_disablechoicerules(struct _Solver *solv, Rule *r); /* policy rule disabling/reenabling */ -void solver_disablepolicyrules(struct _Solver *solv); -void solver_reenablepolicyrules(struct _Solver *solv, int jobidx); +extern void solver_disablepolicyrules(struct _Solver *solv); +extern void solver_reenablepolicyrules(struct _Solver *solv, int jobidx); /* rule info */ -int solver_allruleinfos(struct _Solver *solv, Id rid, Queue *rq); -SolverRuleinfo solver_ruleinfo(struct _Solver *solv, Id rid, Id *fromp, Id *top, Id *depp); +extern int solver_allruleinfos(struct _Solver *solv, Id rid, Queue *rq); +extern SolverRuleinfo solver_ruleinfo(struct _Solver *solv, Id rid, Id *fromp, Id *top, Id *depp); +extern void solver_ruleliterals(struct _Solver *solv, Id rid, Queue *q); +extern int solver_rule2jobidx(struct _Solver *solv, Id rid); +extern Id solver_rule2job(struct _Solver *solv, Id rid, Id *whatp); -/* misc functions */ -void solver_addchoicerules(struct _Solver *solv); -void solver_disablechoicerules(struct _Solver *solv, Rule *r); #ifdef __cplusplus } diff --git a/src/solver.c b/src/solver.c index 7a2c2f8..53db3c7 100644 --- a/src/solver.c +++ b/src/solver.c @@ -356,7 +356,7 @@ makeruledecisions(Solver *solv) v = ri; solver_disableproblem(solv, v); if (v < 0) - solver_reenablepolicyrules(solv, -(v + 1)); + solver_reenablepolicyrules(solv, -v); } } @@ -1019,7 +1019,7 @@ analyze_unsolvable(Solver *solv, Rule *cr, int disablerules) solver_disablechoicerules(solv, solv->rules + lastweak); solver_disableproblem(solv, v); if (v < 0) - solver_reenablepolicyrules(solv, -(v + 1)); + solver_reenablepolicyrules(solv, -v); solver_reset(solv); return 1; } -- 2.7.4