Author: mlschroe Date: Mon Nov 19 11:33:09 2007 New Revision: 7863 URL: http://svn.opensuse.org/viewcvs/zypp?rev=7863&view=rev Log: - add FOR_REPO_SOLVABLES repo iterator macro - extend ruby bindings a bit Modified: trunk/sat-solver/bindings/satsolver.i trunk/sat-solver/src/repo.h trunk/sat-solver/src/solver.c Modified: trunk/sat-solver/bindings/satsolver.i URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/satsolver.i?rev=7863&r1=7862&r2=7863&view=diff ============================================================================== --- trunk/sat-solver/bindings/satsolver.i (original) +++ trunk/sat-solver/bindings/satsolver.i Mon Nov 19 11:33:09 2007 @@ -67,6 +67,23 @@ rb_yield(SWIG_NewPointerObj((void*) $self->repos[i], SWIGTYPE_p__Repo, 0)); } + Solvable *id2solvable(Id p) + { + return pool_id2solvable($self, p); + } + + void each_solvable() + { + Solvable *s; + Id p; + for (p = 1, s = $self->solvables + p; p < $self->nsolvables; p++, s++) + { + if (!s->name) + continue; + rb_yield(SWIG_NewPointerObj((void*) s, SWIGTYPE_p__Solvable, 0)); + } + } + Solvable * select_solvable(Repo *repo, char *name) { @@ -152,10 +169,17 @@ %newobject queue_init; %delobject queue_free; + %include "solvable.h" %extend Solvable { + Id id() { + if (!$self->repo) + return 0; + return $self - $self->repo->pool->solvables; + } + //%typemap(ruby,in) Id { // $1 = id2str($self->pool, $input); //} @@ -186,6 +210,7 @@ } + %include "solver.h" %extend Solver { @@ -209,7 +234,7 @@ for (int i = 0; i < $self->decisionq.count; i++) { p = $self->decisionq.elements[i]; - if (p < 0) + if (p <= 0) continue; /* conflicting package, ignore */ if (p == SYSTEMSOLVABLE) continue; /* system resolvable, always installed */ @@ -231,16 +256,10 @@ if (!$self->installed) return; /* solvables to be erased */ - for (int i = $self->installed->start; i < $self->installed->end; i++) + FOR_REPO_SOLVABLES($self->installed, p, s) { - if ($self->decisionmap[i] >= 0) + if ($self->decisionmap[p] >= 0) continue; /* we keep this package */ - - // getting repo - s = $self->pool->solvables + i; - Repo *repo = s->repo; - if (repo != $self->installed) - continue; rb_yield(SWIG_NewPointerObj((void*) s, SWIGTYPE_p__Solvable, 0)); } } @@ -256,20 +275,19 @@ void each_solvable() { - int i, endof; + Id p; Solvable *s; - i = $self ? $self->start : 1; - endof = $self ? $self->end : $self->pool->nsolvables; - for (; i < endof; i++) + FOR_REPO_SOLVABLES($self, p, s) { - s = $self->pool->solvables + i; - if (s->repo != $self) - continue; - //rb_yield(SWIG_NewPointerObj((void*) s, $descriptor(Solvable), 0)); rb_yield(SWIG_NewPointerObj((void*) s, SWIGTYPE_p__Solvable, 0)); } } + Solvable *add_solvable() + { + return pool_id2solvable($self->pool, repo_add_solvable($self)); + } + void add_solv(FILE *fp) { repo_add_solv($self, fp); Modified: trunk/sat-solver/src/repo.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/src/repo.h?rev=7863&r1=7862&r2=7863&view=diff ============================================================================== --- trunk/sat-solver/src/repo.h (original) +++ trunk/sat-solver/src/repo.h Mon Nov 19 11:33:09 2007 @@ -106,4 +106,8 @@ pool_free_solvable_block(repo->pool, start, count, reuseids); } +#define FOR_REPO_SOLVABLES(r, p, s) \ + for (p = (r)->start, s = (r)->pool->solvables + p; p < (r)->end; p++, s++) \ + if (s->repo == (r)) + #endif /* REPO_H */ Modified: trunk/sat-solver/src/solver.c URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/src/solver.c?rev=7863&r1=7862&r2=7863&view=diff ============================================================================== --- trunk/sat-solver/src/solver.c (original) +++ trunk/sat-solver/src/solver.c Mon Nov 19 11:33:09 2007 @@ -2714,14 +2714,11 @@ if (installed) { - for (i = installed->start; i < installed->end; i++) + FOR_REPO_SOLVABLES(installed, p, s) { - s = pool->solvables + i; - if (s->repo != installed) - continue; - if (solv->decisionmap[i] >= 0) + if (solv->decisionmap[p] >= 0) continue; - if (obsoletesmap[i]) + if (obsoletesmap[p]) continue; printf("erase %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch)); } @@ -2747,7 +2744,8 @@ } else { - printf("update %s-%s.%s (obsoletes", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch)); + printf("update %s-%s.%s", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch)); + printf(" (obsoletes"); for (j = installed->start; j < installed->end; j++) { if (obsoletesmap[j] != p) @@ -3200,17 +3198,15 @@ oldnrules = solv->nrules; if (pool->verbose > 3) printf ("*** create rpm rules for installed solvables ***\n"); - for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++) - if (s->repo == installed) - addrpmrulesforsolvable(solv, s, &addedmap); + FOR_REPO_SOLVABLES(installed, p, s) + addrpmrulesforsolvable(solv, s, &addedmap); if (pool->verbose) printf("added %d rpm rules for installed solvables\n", solv->nrules - oldnrules); if (pool->verbose > 3) printf ("*** create rpm rules for updaters of installed solvables ***\n"); oldnrules = solv->nrules; - for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++) - if (s->repo == installed) - addrpmrulesforupdaters(solv, s, &addedmap, 1); + FOR_REPO_SOLVABLES(installed, p, s) + addrpmrulesforupdaters(solv, s, &addedmap, 1); if (pool->verbose) printf("added %d rpm rules for updaters of installed solvables\n", solv->nrules - oldnrules); } @@ -3404,13 +3400,12 @@ if (installed && installed->nsolvables) { solv->weaksystemrules = xcalloc(installed->end - installed->start, sizeof(Id)); - for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++) - if (s->repo == installed) - { - policy_findupdatepackages(solv, s, &q, 1); - if (q.count) - solv->weaksystemrules[i - installed->start] = pool_queuetowhatprovides(pool, &q); - } + FOR_REPO_SOLVABLES(installed, p, s) + { + policy_findupdatepackages(solv, s, &q, 1); + if (q.count) + solv->weaksystemrules[p - installed->start] = pool_queuetowhatprovides(pool, &q); + } } /* free unneeded memory */ @@ -3422,16 +3417,15 @@ /* try real hard to keep packages installed */ if (0) { - for (i = installed->start, s = pool->solvables + i; i < installed->end; i++, s++) - if (s->repo == installed) - { - /* FIXME: can't work with refine_suggestion! */ - /* need to always add the rule but disable it */ - if (MAPTST(&solv->noupdate, i - installed->start)) - continue; - d = solv->weaksystemrules[i - installed->start]; - addrule(solv, i, d); - } + FOR_REPO_SOLVABLES(installed, p, s) + { + /* FIXME: can't work with refine_suggestion! */ + /* need to always add the rule but disable it */ + if (MAPTST(&solv->noupdate, p - installed->start)) + continue; + d = solv->weaksystemrules[p - installed->start]; + addrule(solv, p, d); + } } /* all new rules are learnt after this point */ -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org