RPM Community Forums

Mailing List Message of <rpm-devel>

Generalizing EVR comparison precedence, proof-of-concept

From: Jeff Johnson <n3npq@mac.com>
Date: Fri 02 Jan 2009 - 06:52:58 CET
Message-id: <CA24A78C-D5B2-4071-BE0E-5774C1E73161@mac.com>
Well, that was fun ...

I think that most of the basics to handle EVRD parsing
and precedence permutations (like DEVR instead of EVRD) is now in place.

The new <-> old rpmEVRparse have an assert to catch any flaws. Flipping
new <-> old will happen later this week if/when someone is convinced  
that
the new is as reliable as the old.

There's a few things left to do:

1) rpmdsCompare() in lib/rpmds.c
	This routine needs to be refactored to use methods
	in rpmdb/rpmevr.c. The only reason it was not done
	back in May 2007 is because of another bug, fixed in June iirc.
	The code is a bit tweaky too, because of N.A compounds, negated
	dependencies, and macro expanded EVR strings (where the bug was fwiw).

2) rpmVersionCompare() in rpmdb/rpmevr.c
	This routine needs to DIE! DIE! DIE!. Its the perl bindings
	that prevent unplugging life support:

	[jbj@wellfleet wdj]$ grep rpmVersionCompare */*.c
	lib/rpminstall.c:		if (rpmVersionCompare(oldH, h) < 0)
	perl/RPM_Header.c:	RETVAL = rpmVersionCompare(h1, h2);
	perl/RPM_Header.c:	RETVAL = rpmVersionCompare(h1, h2);
	python/header-py.c:    return rpmVersionCompare(a->h, b->h);
	rpmdb/rpmevr.c:int rpmVersionCompare(Header first, Header second)

3) clown code in rpmdb/hdrfmt.c and python/header-py.c
	The EVR_t is almost, but not quite, opaque. The issue is
	deciding on the representation of missing values. Should
	NULL or "" be used for strings. And missing Epoch: == "0".

4) wire up %evr_tuple_select
	This will be needed before radical changes to the {E,V,R,D}
	4-tuple through syntax can be handled.

Enjoy!

73 de Jeff

	
On Jan 2, 2009, at 12:33 AM, Jeff Johnson wrote:

>  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:   02-Jan-2009 06:33:29
>  Branch: HEAD                             Handle: 2009010205332900
>
>  Modified files:
>    rpm                     CHANGES
>    rpm/rpmdb               rpmevr.c
>
>  Log:
>    - jbj: EVRtuple: blueprint new <-> old parsers with an assert.
>    - jbj: EVRtuple: parse EVRD using RPMMIRE_REGEX & evr_tuple_match.
>
>  Summary:
>    Revision    Changes     Path
>    1.2722      +2  -0      rpm/CHANGES
>    1.23        +32 -5      rpm/rpmdb/rpmevr.c
>   
> ____________________________________________________________________________
>
>  patch -p0 <<'@@ .'
>  Index: rpm/CHANGES
>   
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
>  $ cvs diff -u -r1.2721 -r1.2722 CHANGES
>  --- rpm/CHANGES	1 Jan 2009 21:30:25 -0000	1.2721
>  +++ rpm/CHANGES	2 Jan 2009 05:33:29 -0000	1.2722
>  @@ -1,5 +1,7 @@
>
>   5.2a2 -> 5.2a3:
>  +    - jbj: EVRtuple: blueprint new <-> old parsers with an assert.
>  +    - jbj: EVRtuple: parse EVRD using RPMMIRE_REGEX &  
> evr_tuple_match.
>       - jbj: EVRtuple: wire up evr_tuple_match RE pattern match.
>       - jbj: EVRtuple: wire up evr_tuple_order precedence permutation.
>       - jbj: EVRtuple: use array for tuple storage.
>  @@ .
>  patch -p0 <<'@@ .'
>  Index: rpm/rpmdb/rpmevr.c
>   
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
>  $ cvs diff -u -r1.22 -r1.23 rpmevr.c
>  --- rpm/rpmdb/rpmevr.c	1 Jan 2009 21:30:25 -0000	1.22
>  +++ rpm/rpmdb/rpmevr.c	2 Jan 2009 05:33:29 -0000	1.23
>  @@ -5,6 +5,7 @@
>
>   #include <rpmiotypes.h>
>   #include <rpmmacro.h>
>  +#define	_MIRE_INTERNAL
>   #include <mire.h>
>
>   #include <rpmtag.h>
>  @@ -109,7 +110,7 @@
>   }
>
>   /*@unchecked@*/ /*@observer@*/ /*@null@*/
>  -static const char * _evr_tuple_match = "i^(?:([^:-]+):)?([^:-]+) 
> (?:-([^:-]+))?(?::([^:-]+))?$";
>  +static const char * _evr_tuple_match = "^(?:([^:-]+):)?([^:-]+)(?:- 
> ([^:-]+))?(?::([^:-]+))?$";
>   /*@unchecked@*/ /*@null@*/
>   static const char * evr_tuple_match = NULL;
>   /*@unchecked@*/ /*@null@*/
>  @@ -125,8 +126,16 @@
>   	evr_tuple_match = rpmExpand("%{?evr_tuple_match}", NULL);
>   	if (evr_tuple_match == NULL || evr_tuple_match[0] == '\0')
>   	    evr_tuple_match = xstrdup(_evr_tuple_match);
>  +
>  +#ifdef	NOTYET	/* XXX avoid need for evr_tuple_nmire */
>  +	evr_tuple_mire = mireNew(RPMMIRE_REGEX, 0);
>  +	xx = mireSetCOptions(evr_tuple_mire, RPMMIRE_REGEX, 0, 0, NULL);
>  +	xx = mireRegcomp(evr_tuple_mire, evr_tuple_match);
>  +#else
>   	xx = mireAppend(RPMMIRE_REGEX, 0, evr_tuple_match, NULL,
>   		&evr_tuple_mire, &evr_tuple_nmire);
>  +#endif
>  +
>       }
>   assert(evr_tuple_match != NULL && evr_tuple_mire != NULL);
>       return evr_tuple_mire;
>  @@ -181,14 +190,32 @@
>       }
>
>       {	miRE mire = rpmEVRmire();
>  -	int noffsets = 4 * 3;
>  -	int offsets[4 * 3];
>  +	int noffsets = 10 * 3;
>  +	int offsets[10 * 3];
>   	int xx;
>  +	int i;
>
>  -	memset(offsets, 0, sizeof(offsets));
>  +	memset(offsets, -1, sizeof(offsets));
>   	xx = mireSetEOptions(mire, offsets, noffsets);
>
>  -	xx = mireRegexec(mire, evr->str, strlen(evr->str));
>  +	xx = mireRegexec(mire, evrstr, strlen(evrstr));
>  +
>  +	for (i = 0; i < noffsets; i += 2) {
>  +	    size_t nb;
>  +	    int ix;
>  +
>  +	    if (offsets[i] < 0) continue;
>  +	    nb = (size_t)(offsets[i+1] - offsets[i]);
>  +	    switch (i/2) {
>  +	    default:
>  +	    case 0:	continue;	/*@notreached@*/ break;
>  +	    case 1:	ix = RPMEVR_E;	break;
>  +	    case 2:	ix = RPMEVR_V;	break;
>  +	    case 3:	ix = RPMEVR_R;	break;
>  +	    case 4:	ix = RPMEVR_D;	break;
>  +	    }
>  +assert(!strncmp(evr->F[ix], evrstr+offsets[i], nb));
>  +	}
>
>   	xx = mireSetEOptions(mire, NULL, 0);
>       }
>  @@ .
> ______________________________________________________________________
> RPM Package Manager                                    http://rpm5.org
> CVS Sources Repository                                rpm-cvs@rpm5.org



  • application/pkcs7-signature attachment: smime.p7s
Received on Fri Jan 2 06:53:05 2009
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.