RPM Community Forums

Mailing List Message of <rpm-cvs>

[CVS] RPM: rpm/ CHANGES rpm/lib/ rpmps.c rpmps.h verify.c rpm/python/ ...

From: Jeff Johnson <jbj@rpm5.org>
Date: Sat 20 Oct 2007 - 06:55:44 CEST
Message-Id: <20071020045544.445E9348464@rpm5.org>
  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  jbj@rpm5.org
  Module: rpm                              Date:   20-Oct-2007 06:55:44
  Branch: HEAD                             Handle: 2007102005554301

  Modified files:
    rpm                     CHANGES system.h
    rpm/lib                 rpmps.c rpmps.h verify.c
    rpm/python              rpmps-py.c rpmps-py.h rpmts-py.c

  Log:
    - rpm.org: rpmpsi iterator.

  Summary:
    Revision    Changes     Path
    1.1738      +1  -0      rpm/CHANGES
    2.14        +55 -6      rpm/lib/rpmps.c
    2.12        +44 -0      rpm/lib/rpmps.h
    2.173       +23 -14     rpm/lib/verify.c
    1.10        +48 -21     rpm/python/rpmps-py.c
    1.5         +2  -2      rpm/python/rpmps-py.h
    1.73        +16 -12     rpm/python/rpmts-py.c
    2.92        +0  -2      rpm/system.h
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
  ============================================================================
  $ cvs diff -u -r1.1737 -r1.1738 CHANGES
  --- rpm/CHANGES	20 Oct 2007 01:47:17 -0000	1.1737
  +++ rpm/CHANGES	20 Oct 2007 04:55:43 -0000	1.1738
  @@ -1,4 +1,5 @@
   4.5 -> 5.0:
  +    - rpm.org: rpmpsi iterator.
       - jbj: mark myTagName() and myTagValue() linear lookup for destruction.
       - jbj: create rpmdb/rpmtag.h, split from lib/rpmlib.h.
       - jbj: make the --info field colons align correctly, more (#323221).
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/lib/rpmps.c
  ============================================================================
  $ cvs diff -u -r2.13 -r2.14 rpmps.c
  --- rpm/lib/rpmps.c	30 Sep 2007 20:38:25 -0000	2.13
  +++ rpm/lib/rpmps.c	20 Oct 2007 04:55:43 -0000	2.14
  @@ -53,6 +53,50 @@
       return numProblems;
   }
   
  +rpmpsi rpmpsInitIterator(rpmps ps)
  +{
  +    rpmpsi psi = NULL;
  +    if (ps != NULL) {
  +	psi = xcalloc(1, sizeof(*psi));
  +	psi->ps = rpmpsLink(ps, "iter ref");
  +	psi->ix = -1;
  +    }
  +    return psi;
  +}
  +
  +rpmpsi rpmpsFreeIterator(rpmpsi psi)
  +{
  +    if (psi != NULL) {
  +	rpmpsUnlink(psi->ps, "iter unref");
  +	free(psi);
  +	psi = NULL;
  +    }
  +    return psi;
  +}
  +
  +int rpmpsNextIterator(rpmpsi psi)
  +{
  +    int i = -1;
  +
  +    if (psi != NULL && ++psi->ix >= 0) {
  +	if (psi->ix < rpmpsNumProblems(psi->ps)) {
  +	    i = psi->ix;
  +	} else {
  +	    psi->ix = -1;
  +	}	     
  +    }
  +    return i;
  +}
  +
  +rpmProblem rpmpsProblem(rpmpsi psi)
  +{
  +    rpmProblem p = NULL;
  +    if (psi != NULL && psi->ix >= 0 && psi->ix < rpmpsNumProblems(psi->ps)) {
  +	p = psi->ps->probs + psi->ix;
  +    } 
  +    return p;
  +}
  +
   rpmps rpmpsCreate(void)
   {
       rpmps ps = xcalloc(1, sizeof(*ps));
  @@ -306,6 +350,7 @@
   void rpmpsPrint(FILE *fp, rpmps ps)
   {
       const char * msg;
  +    rpmpsi psi;
       int i;
   
       if (ps == NULL || ps->probs == NULL || ps->numProblems <= 0)
  @@ -314,20 +359,23 @@
       if (fp == NULL)
   	fp = stderr;
   
  -    for (i = 0; i < ps->numProblems; i++) {
  -	rpmProblem p;
  +    psi = rpmpsInitIterator(ps);
  +    while ((i = rpmpsNextIterator(psi)) >= 0) {
  +	rpmProblem p = rpmpsProblem(psi);
  +	rpmpsi psif;
   	int j;
   
  -	p = ps->probs + i;
  -
   	if (p->ignoreProblem)
   	    continue;
   
   	/* Filter already displayed problems. */
  -	for (j = 0; j < i; j++) {
  -	    if (!sameProblem(p, ps->probs + j))
  +	psif = rpmpsInitIterator(ps);
  +	while ((j = rpmpsNextIterator(psif)) < i) {
  +	    if (!sameProblem(p, rpmpsProblem(psif)))
   		/*@innerbreak@*/ break;
   	}
  +	psif = rpmpsFreeIterator(psif);
  +
   	if (j < i)
   	    continue;
   
  @@ -336,6 +384,7 @@
   	msg = _free(msg);
   
       }
  +    psi = rpmpsFreeIterator(psi);
   }
   
   rpmProblem rpmpsGetProblem(rpmps ps, int num)
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/lib/rpmps.h
  ============================================================================
  $ cvs diff -u -r2.11 -r2.12 rpmps.h
  --- rpm/lib/rpmps.h	30 Sep 2007 20:38:25 -0000	2.11
  +++ rpm/lib/rpmps.h	20 Oct 2007 04:55:43 -0000	2.12
  @@ -22,6 +22,10 @@
   typedef /*@abstract@*/ /*@refcounted@*/ struct rpmps_s * rpmps;
   
   /**
  +*/
  +typedef /*@abstract@*/ struct rpmpsi_s * rpmpsi;
  +
  +/**
    * Enumerate transaction set problem types.
    */
   typedef enum rpmProblemType_e {
  @@ -68,6 +72,14 @@
   /*@refs@*/
       int nrefs;			/*!< Reference count. */
   };
  +
  +/**
  + */
  +struct rpmpsi_s {
  +    size_t ix;
  +    rpmps ps;
  +};
  +
   #endif
   
   #ifdef __cplusplus
  @@ -131,6 +143,38 @@
   	/*@*/;
   
   /**
  + * Initialize problem set iterator.
  + * @param ps		problem set
  + * @return		problem set iterator
  + */
  +rpmpsi rpmpsInitIterator(rpmps ps)
  +	/*@*/;
  +
  +/**
  + * Destroy problem set iterator.
  + * @param psi		problem set iterator
  + * @return		problem set iterator (NULL)
  + */
  +rpmpsi rpmpsFreeIterator(rpmpsi psi)
  +	/*@*/;
  +
  +/**
  + * Return next problem set iterator index
  + * @param psi		problem set iterator
  + * @return		iterator index, -1 on termination
  + */
  +int rpmpsNextIterator(rpmpsi psi)
  +	/*@*/;
  +
  +/**
  + * Return current problem from problem set
  + * @param psi		problem set iterator
  + * @return		current rpmProblem 
  + */
  +rpmProblem rpmpsProblem(rpmpsi psi)
  +	/*@*/;
  +
  +/**
    * Create a problem set.
    * @return		new problem set
    */
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/lib/verify.c
  ============================================================================
  $ cvs diff -u -r2.172 -r2.173 verify.c
  --- rpm/lib/verify.c	16 Oct 2007 15:59:08 -0000	2.172
  +++ rpm/lib/verify.c	20 Oct 2007 04:55:43 -0000	2.173
  @@ -19,8 +19,6 @@
   #include "ugid.h"
   #include "debug.h"
   
  -/*@access rpmps @*/
  -/*@access rpmProblem @*/
   /*@access rpmpsm @*/	/* XXX for %verifyscript through rpmpsmStage() */
   
   #define S_ISDEV(m) (S_ISBLK((m)) || S_ISCHR((m)))
  @@ -374,7 +372,7 @@
    * @param qva		parsed query/verify options
    * @param ts		transaction set
    * @param h		header
  - * @return		0 no problems, 1 problems found
  + * @return		number of problems found (0 for no problems)
    */
   static int verifyDependencies(/*@unused@*/ QVA_t qva, rpmts ts,
   		Header h)
  @@ -385,7 +383,6 @@
       int instance = headerGetInstance(h);
   #endif
       rpmps ps;
  -    int numProblems;
       int rc = 0;		/* assume no problems */
       int xx;
       int i;
  @@ -401,36 +398,49 @@
       xx = rpmtsCheck(ts);
       ps = rpmtsProblems(ts);
   
  -    numProblems = rpmpsNumProblems(ps);
  -    if (ps != NULL && numProblems > 0) {
  -	const char * pkgNEVR, * altNEVR;
  +    if (rpmpsNumProblems(ps) > 0) {
  +	const char * altNEVR;
  +	const char * pkgNEVR = NULL;
  +	rpmpsi psi;
   	rpmProblem p;
   	char * t, * te;
   	int nb = 512;
   
  -	for (i = 0; i < numProblems; i++) {
  -	    p = ps->probs + i;
  -	    altNEVR = (p->altNEVR ? p->altNEVR : "? ?altNEVR?");
  +	psi = rpmpsInitIterator(ps);
  +	while (rpmpsNextIterator(psi) >= 0) {
  +	    p = rpmpsProblem(psi);
  +	    if (pkgNEVR == NULL)
  +		pkgNEVR = rpmProblemGetPkgNEVR(p);
  +
  +	    altNEVR = rpmProblemGetAltNEVR(p);
   	    if (altNEVR[0] == 'R' && altNEVR[1] == ' ')
   		nb += sizeof("\tRequires: ")-1;
   	    if (altNEVR[0] == 'C' && altNEVR[1] == ' ')
   		nb += sizeof("\tConflicts: ")-1;
   	    nb += strlen(altNEVR+2) + sizeof("\n") - 1;
  +
   	}
  +	psi = rpmpsFreeIterator(psi);
  +
   	te = t = alloca(nb);
   	*te = '\0';
  -	pkgNEVR = (ps->probs->pkgNEVR ? ps->probs->pkgNEVR : "?pkgNEVR?");
   	sprintf(te, _("Unsatisfied dependencies for %s:\n"), pkgNEVR);
   	te += strlen(te);
  -	for (i = 0; i < numProblems; i++) {
  -	    p = ps->probs + i;
  +
  +	psi = rpmpsInitIterator(ps);
  +	while (rpmpsNextIterator(psi) >= 0) {
  +	    p = rpmpsProblem(psi);
  +
   	    altNEVR = (p->altNEVR ? p->altNEVR : "? ?altNEVR?");
   	    if (altNEVR[0] == 'R' && altNEVR[1] == ' ')
   		te = stpcpy(te, "\tRequires: ");
   	    if (altNEVR[0] == 'C' && altNEVR[1] == ' ')
   		te = stpcpy(te, "\tConflicts: ");
   	    te = stpcpy( stpcpy(te, altNEVR+2), "\n");
  +
  +	    rc++;
   	}
  +	psi = rpmpsFreeIterator(psi);
   
   	if (te > t) {
   	    *te++ = '\n';
  @@ -439,7 +449,6 @@
   	    te = t;
   	    *t = '\0';
   	}
  -	rc = 1;
       }
   
       ps = rpmpsFree(ps);
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/python/rpmps-py.c
  ============================================================================
  $ cvs diff -u -r1.9 -r1.10 rpmps-py.c
  --- rpm/python/rpmps-py.c	20 Jul 2007 22:47:34 -0000	1.9
  +++ rpm/python/rpmps-py.c	20 Oct 2007 04:55:44 -0000	1.10
  @@ -25,7 +25,7 @@
   {
   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;
   }
  @@ -36,24 +36,19 @@
   	/*@modifies 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));
  -    } else {
  -	s->active = 0;
  -    }
  +    if (rpmpsNextIterator(s->psi) >= 0)
  +	result = Py_BuildValue("s", rpmProblemString(rpmpsProblem(s->psi)));
  +    else
  +	s->psi = rpmpsFreeIterator(s->psi);
   
       return result;
   }
  @@ -79,6 +74,27 @@
       Py_INCREF(Py_None);
       return Py_None;
   }
  +
  +static int
  +rpmps_Append(rpmpsObject * s, PyObject * value)
  +{
  +    char *pkgNEVR, *altNEVR, *str1;
  +    unsigned long ulong1;
  +    int ignoreProblem;
  +    rpmProblemType type;
  +    fnpyKey key;
  +
  +    if (!PyArg_ParseTuple(value, "ssOiisN:rpmps value tuple",
  +			&pkgNEVR, &altNEVR, &key,
  +			&type, &ignoreProblem, &str1,
  +			&ulong1))
  +    {
  +    	return -1;
  +    }
  +    rpmpsAppend(s->ps, type, pkgNEVR, key, str1, NULL, altNEVR, ulong1);
  +    return 0;
  +}
  +
   /*@}*/
   
   /*@-fullinitblock@*/
  @@ -86,6 +102,8 @@
   static struct PyMethodDef rpmps_methods[] = {
    {"Debug",	(PyCFunction)rpmps_Debug,	METH_VARARGS|METH_KEYWORDS,
   	NULL},
  + {"Append",	(PyCFunction)rpmps_Append,	METH_VARARGS|METH_KEYWORDS,
  +	NULL},
    {NULL,		NULL}		/* sentinel */
   };
   /*@=fullinitblock@*/
  @@ -149,8 +167,9 @@
   	/*@*/
   {
       PyObject * result = NULL;
  -    rpmps ps;
  +    rpmpsi psi;
       int ix;
  +    int i;
   
       if (!PyInt_Check(key)) {
   if (_rpmps_debug < 0)
  @@ -161,16 +180,23 @@
   
       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)
  +	    continue;
  +	result = Py_BuildValue("s", rpmProblemString(rpmpsPrpblem(psi)));
   if (_rpmps_debug < 0)
   fprintf(stderr, "*** rpmps_subscript(%p,%p) %s\n", s, key, PyString_AsString(result));
  +	break;
       }
  +    psi = rpmpsFreeIterator(psi);
   
       return result;
   }
   
  +#define	PERMIT_RPMPS_SUBSCRIPT	/* XXX likely buggy */
  +#if defined(PERMIT_RPMPS_SUBSCRIPT)
   static int
   rpmps_ass_sub(rpmpsObject * s, PyObject * key, PyObject * value)
   	/*@modifies s @*/
  @@ -241,11 +267,14 @@
   
       return 0;
   }
  +#endif
   
   static PyMappingMethods rpmps_as_mapping = {
           (inquiry) rpmps_length,		/* mp_length */
           (binaryfunc) rpmps_subscript,	/* mp_subscript */
  +#if defined(PERMIT_RPMPS_SUBSCRIPT)
           (objobjargproc) rpmps_ass_sub,	/* mp_ass_subscript */
  +#endif
   };
   
   /** \ingroup py_c
  @@ -262,8 +291,7 @@
   	return -1;
   
       s->ps = rpmpsCreate();
  -    s->active = 0;
  -    s->ix = -1;
  +    s->psi = NULL;
   
       return 0;
   }
  @@ -382,8 +410,7 @@
       if (s == NULL)
   	return NULL;
       s->ps = ps;
  -    s->active = 0;
  -    s->ix = -1;
  +    s->psi = NULL;
       return s;
   }
   /*@=modunconnomods =evalorderuncon @*/
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/python/rpmps-py.h
  ============================================================================
  $ cvs diff -u -r1.4 -r1.5 rpmps-py.h
  --- rpm/python/rpmps-py.h	25 May 2007 17:36:31 -0000	1.4
  +++ rpm/python/rpmps-py.h	20 Oct 2007 04:55:44 -0000	1.5
  @@ -15,10 +15,10 @@
   typedef struct rpmpsObject_s {
       PyObject_HEAD
       PyObject *md_dict;		/*!< to look like PyModuleObject */
  -    int		active;
  -    int		ix;
   /*@relnull@*/
       rpmps	ps;
  +/*@relnull@*/
  +    rpmpsi	psi;
   } rpmpsObject;
   
   /** \ingroup py_c
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/python/rpmts-py.c
  ============================================================================
  $ cvs diff -u -r1.72 -r1.73 rpmts-py.c
  --- rpm/python/rpmts-py.c	12 Oct 2007 17:09:40 -0000	1.72
  +++ rpm/python/rpmts-py.c	20 Oct 2007 04:55:44 -0000	1.73
  @@ -6,7 +6,7 @@
   
   #include <rpmio_internal.h>	/* XXX for fdSetOpen */
   
  -#define	_RPMPS_INTERNAL	/* XXX rpmps needs iterator */
  +#define	_RPMPS_INTERNAL	/* XXX almost (but not quite) opaque. */
   #include <rpmcli.h>
   #include <rpmpgp.h>
   #include <rpmdb.h>
  @@ -532,9 +532,9 @@
   
       if (ps != NULL) {
   	list = PyList_New(0);
  +	rpmpsi psi = rpmpsInitIterator(ps);
   
  -	/* XXX TODO: rpmlib >= 4.0.3 can return multiple suggested keys. */
  -	for (i = 0; i < ps->numProblems; i++) {
  +	while ((i = rpmpsNextIterator(psi)) >= 0) {
   #ifdef	DYING
   	    cf = Py_BuildValue("((sss)(ss)iOi)", conflicts[i].byName,
   			       conflicts[i].byVersion, conflicts[i].byRelease,
  @@ -552,13 +552,13 @@
   	    int needsFlags, sense;
   	    fnpyKey key;
   
  -	    p = ps->probs + i;
  +	    p = rpmpsProblem(psi);
   
               /* XXX autorelocated i386 on ia64, fix system-config-packages! */
  -	    if (p->type == RPMPROB_BADRELOCATE)
  +	    if (rpmProblemGetType(p) == RPMPROB_BADRELOCATE)
   		continue;
   
  -	    byName = p->pkgNEVR;
  +	    byName = rpmProblemGetPkgNEVR(p);
   	    if ((byArch= strrchr(byName, '.')) != NULL)
   		*byArch++ = '\0';
   	    if ((byRelease = strrchr(byName, '-')) != NULL)
  @@ -566,9 +566,9 @@
   	    if ((byVersion = strrchr(byName, '-')) != NULL)
   		*byVersion++ = '\0';
   
  -	    key = p->key;
  +	    key = rpmProblemKey(p);
   
  -	    needsName = p->altNEVR;
  +	    needsName = rpmProblemGetAltNEVR(p);
   	    if (needsName[1] == ' ') {
   		sense = (needsName[0] == 'C')
   			? RPMDEP_SENSE_CONFLICTS : RPMDEP_SENSE_REQUIRES;
  @@ -596,6 +596,7 @@
   	    Py_DECREF(cf);
   	}
   
  +	psi = rpmpsFreeIterator(psi);
   	ps = rpmpsFree(ps);
   
   	return list;
  @@ -1197,9 +1198,10 @@
   	/*@globals rpmGlobalMacroContext, _Py_NoneStruct @*/
   	/*@modifies s, rpmGlobalMacroContext, _Py_NoneStruct @*/
   {
  -    int rc, i;
  +    int rc;
       PyObject * list;
       rpmps ps;
  +    rpmpsi psi;
       struct rpmtsCallbackType_s cbInfo;
       char * kwlist[] = {"callback", "data", NULL};
   
  @@ -1255,16 +1257,18 @@
       }
   
       list = PyList_New(0);
  -    for (i = 0; i < ps->numProblems; i++) {
  -	rpmProblem p = ps->probs + i;
  +    psi = rpmpsInitIterator(ps);
  +    while (rpmpsNextIterator(psi) >= 0) {
  +	rpmProblem p = rpmpsProblem(psi);
   	unsigned long ulong1 = p->ulong1;
   	PyObject * prob = Py_BuildValue("s(isN)", rpmProblemString(p),
  -			     p->type,
  +			     rpmProblemGetType(p),
   			     p->str1,
   			     PyLong_FromLongLong(ulong1));
   	PyList_Append(list, prob);
   	Py_DECREF(prob);
       }
  +    psi = rpmpsFreeIterator(psi);
   
       ps = rpmpsFree(ps);
   
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/system.h
  ============================================================================
  $ cvs diff -u -r2.91 -r2.92 system.h
  --- rpm/system.h	20 Oct 2007 01:47:17 -0000	2.91
  +++ rpm/system.h	20 Oct 2007 04:55:43 -0000	2.92
  @@ -734,9 +734,7 @@
   
   #define	SUPPORT_RPMLEAD		0	/* XXX default is add lead. */
   
  -#if 0
   #define SUPPORT_LINEAR_TAGTABLE_LOOKUP	0
  -#endif
   
   /**
    * Turn off pgp/pgp5 signing (hasn't been looked at seriously for years).
  @@ .
Received on Sat Oct 20 06:55:44 2007
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.