diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2007-10-19 12:36:11 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2007-10-19 12:36:11 +0300 |
commit | b882a428bde280957844faebfc7bb90b0a847753 (patch) | |
tree | 422c025b072715c2c0463e83bf7ab7dfaec82c72 /python/rpmps-py.c | |
parent | 36f1ac2c7b3a9030e3dfd59510fe285eac3dce88 (diff) | |
download | rpm-b882a428bde280957844faebfc7bb90b0a847753.tar.gz rpm-b882a428bde280957844faebfc7bb90b0a847753.tar.bz2 rpm-b882a428bde280957844faebfc7bb90b0a847753.zip |
Implement python rpmps iteration with rpmlib level iterator
Diffstat (limited to 'python/rpmps-py.c')
-rw-r--r-- | python/rpmps-py.c | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/python/rpmps-py.c b/python/rpmps-py.c index 2cbe10b95..f686ac98e 100644 --- a/python/rpmps-py.c +++ b/python/rpmps-py.c @@ -30,7 +30,7 @@ rpmps_iter(rpmpsObject * s) { if (_rpmps_debug < 0) fprintf(stderr, "*** rpmps_iter(%p)\n", s); - s->ix = -1; + s->psi = rpmpsInitIterator(s->ps); Py_INCREF(s); return (PyObject *)s; } @@ -39,23 +39,20 @@ static PyObject * rpmps_iternext(rpmpsObject * s) { PyObject * result = NULL; - rpmps ps = s->ps; if (_rpmps_debug < 0) -fprintf(stderr, "*** rpmps_iternext(%p) ps %p ix %d active %d\n", s, s->ps, s->ix, s->active); +fprintf(stderr, "*** rpmps_iternext(%p) ps %p psi %p\n", s, s->ps, s->psi); /* Reset loop indices on 1st entry. */ - if (!s->active) { - s->ix = -1; - s->active = 1; + if (s->psi == NULL) { + s->psi = rpmpsInitIterator(s->ps); } /* If more to do, return a problem set string. */ - s->ix++; - if (s->ix < ps->numProblems) { - result = Py_BuildValue("s", rpmProblemString(ps->probs+s->ix)); + if (rpmpsNextIterator(s->psi) >= 0) { + result = Py_BuildValue("s", rpmProblemString(rpmpsProblem(s->psi))); } else { - s->active = 0; + s->psi = rpmpsFreeIterator(s->psi); } return result; @@ -118,8 +115,8 @@ static PyObject * rpmps_subscript(rpmpsObject * s, PyObject * key) { PyObject * result = NULL; - rpmps ps; - int ix; + rpmpsi psi; + int ix, i; if (!PyInt_Check(key)) { if (_rpmps_debug < 0) @@ -130,12 +127,18 @@ fprintf(stderr, "*** rpmps_subscript(%p[%s],%p[%s])\n", s, lbl(s), key, lbl(key) ix = (int) PyInt_AsLong(key); /* XXX range check */ - ps = s->ps; - if (ix < ps->numProblems) { - result = Py_BuildValue("s", rpmProblemString(ps->probs + ix)); + + psi = rpmpsInitIterator(s->ps); + while ((i = rpmpsNextIterator(psi)) >= 0) { + if (i == ix) { + result = Py_BuildValue("s", rpmProblemString(rpmpsProblem(psi))); + break; + } + } + psi = rpmpsFreeIterator(psi); + if (_rpmps_debug < 0) fprintf(stderr, "*** rpmps_subscript(%p,%p) %s\n", s, key, PyString_AsString(result)); - } return result; } @@ -226,8 +229,7 @@ fprintf(stderr, "*** rpmps_init(%p,%p,%p)\n", s, args, kwds); return -1; s->ps = rpmpsCreate(); - s->active = 0; - s->ix = -1; + s->psi = NULL; return 0; } @@ -339,7 +341,6 @@ rpmps_Wrap(rpmps ps) if (s == NULL) return NULL; s->ps = ps; - s->active = 0; - s->ix = -1; + s->psi = NULL; return s; } |