This change introduces a change an incompatibility in mireRegexec()
return codes.
Before, mireRegexec() returned
0 on match
1 on nomatch
otherwise an error
In order to accomodate parsing with RE's (using PCRE initially), I
have changed mireRegexec() returns to
>= 0 on match(s)
-1 on nomatch
otherwise an error
I'm almost certain to have screwed something, will repair as soon as
the construction dust clears.
Further incompatible API changes can be expected while
I refactor code out of rpmgrep nee pcregrep into mire.[ch].
The end result will likely include tracking patterns as an array
of pointers to refcounted storage, rather than a C array as well.
I don't believe anything is using the mire API at the moment.
If there are any existing cases using the mire API, now would be a very
convenient time to say something, and I'll try to accomodate API
compatibility.
73 de Jeff
On Feb 26, 2008, at 3:42 PM, 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: 26-Feb-2008 21:42:01
> Branch: HEAD Handle: 2008022620415901
>
> Modified files:
> rpm CHANGES
> rpm/lib rpminstall.c rpmrc.c tgi.c
> rpm/rpmdb rpmdb.c
> rpm/rpmio macro.c mire.c mire.h rpmgrep.c tfts.c
> tmire.c
>
> Log:
> - jbj: handle mireRegexec return change internal to rpm code.
> - jbj: mire: change mireRegexec() return: >=0 match, -1 nomatch,
> else error.
>
> Summary:
> Revision Changes Path
> 1.2204 +2 -0 rpm/CHANGES
> 1.204 +1 -1 rpm/lib/rpminstall.c
> 2.229 +1 -1 rpm/lib/rpmrc.c
> 2.19 +1 -1 rpm/lib/tgi.c
> 1.239 +7 -7 rpm/rpmdb/rpmdb.c
> 2.188 +1 -1 rpm/rpmio/macro.c
> 1.33 +28 -10 rpm/rpmio/mire.c
> 1.25 +1 -1 rpm/rpmio/mire.h
> 1.67 +2 -4 rpm/rpmio/rpmgrep.c
> 2.24 +1 -1 rpm/rpmio/tfts.c
> 1.6 +1 -1 rpm/rpmio/tmire.c
>
> ____________________________________________________________________________
>
> patch -p0 <<'@@ .'
> Index: rpm/CHANGES
>
> =
> =
> =
> =
> =
> =
> ======================================================================
> $ cvs diff -u -r1.2203 -r1.2204 CHANGES
> --- rpm/CHANGES 26 Feb 2008 14:24:51 -0000 1.2203
> +++ rpm/CHANGES 26 Feb 2008 20:41:59 -0000 1.2204
> @@ -1,4 +1,6 @@
> 5.0.0 -> 5.1a1:
> + - jbj: handle mireRegexec return change internal to rpm code.
> + - jbj: mire: change mireRegexec() return: >=0 match, -1
> nomatch, else error.
> - jbj: rpmgrep: start untwisting PCRE from rpmgrep (broken w/o
> PCRE atm).
> - jbj: rpmgrep: add --stats benchmark insturmentatian
> (patterns soonishly).
> - jbj: rpmdigest: add --stats benchmark insturmentation.
> @@ .
> patch -p0 <<'@@ .'
> Index: rpm/lib/rpminstall.c
>
> =
> =
> =
> =
> =
> =
> ======================================================================
> $ cvs diff -u -r1.203 -r1.204 rpminstall.c
> --- rpm/lib/rpminstall.c 19 Feb 2008 23:23:15 -0000 1.203
> +++ rpm/lib/rpminstall.c 26 Feb 2008 20:42:00 -0000 1.204
> @@ -366,7 +366,7 @@
> continue;
> /*@notreached@*/ /*@switchbreak@*/ break;
> case FTS_F: /* regular file */
> - if (mireRegexec(mire, fts->fts_accpath, 0))
> + if (mireRegexec(mire, fts->fts_accpath, 0) < 0)
> continue;
> /*@switchbreak@*/ break;
> /* Error conditions. */
> @@ .
> patch -p0 <<'@@ .'
> Index: rpm/lib/rpmrc.c
>
> =
> =
> =
> =
> =
> =
> ======================================================================
> $ cvs diff -u -r2.228 -r2.229 rpmrc.c
> --- rpm/lib/rpmrc.c 26 Feb 2008 18:36:54 -0000 2.228
> +++ rpm/lib/rpmrc.c 26 Feb 2008 20:42:00 -0000 2.229
> @@ -480,7 +480,7 @@
>
> if ((mire = mi_re) != NULL)
> for (i = 0; i < mi_nre; i++) {
> - if (!mireRegexec(mire + i, platform, 0))
> + if (mireRegexec(mire + i, platform, 0) >= 0)
> return (i + 1);
> }
> return 0;
> @@ .
> patch -p0 <<'@@ .'
> Index: rpm/lib/tgi.c
>
> =
> =
> =
> =
> =
> =
> ======================================================================
> $ cvs diff -u -r2.18 -r2.19 tgi.c
> --- rpm/lib/tgi.c 10 Feb 2008 18:32:32 -0000 2.18
> +++ rpm/lib/tgi.c 26 Feb 2008 20:42:00 -0000 2.19
> @@ -89,7 +89,7 @@
>
> /* Filter out glibc <-> glibc-common confusions. */
> for (i = 0; i < ac; i++) {
> - if (mireRegexec(mire, av[i], 0))
> + if (mireRegexec(mire, av[i], 0) < 0)
> continue;
> fn = xstrdup(av[0]);
> break;
> @@ .
> patch -p0 <<'@@ .'
> Index: rpm/rpmdb/rpmdb.c
>
> =
> =
> =
> =
> =
> =
> ======================================================================
> $ cvs diff -u -r1.238 -r1.239 rpmdb.c
> --- rpm/rpmdb/rpmdb.c 20 Feb 2008 00:39:14 -0000 1.238
> +++ rpm/rpmdb/rpmdb.c 26 Feb 2008 20:42:00 -0000 1.239
> @@ -2202,7 +2202,7 @@
> for (j = 0; j < (unsigned) he->c; j++) {
> sprintf(numbuf, "%u", (unsigned) he->p.ui8p[j]);
> rc = mireRegexec(mire, numbuf, 0);
> - if ((!rc && !mire->notmatch) || (rc && mire->notmatch))
> + if ((rc >= 0 && !mire->notmatch) || (rc < 0 && mire-
> >notmatch))
> anymatch++;
> }
> /*@switchbreak@*/ break;
> @@ -2210,7 +2210,7 @@
> for (j = 0; j < (unsigned) he->c; j++) {
> sprintf(numbuf, "%u", (unsigned) he->p.ui16p[j]);
> rc = mireRegexec(mire, numbuf, 0);
> - if ((!rc && !mire->notmatch) || (rc && mire->notmatch))
> + if ((rc >= 0 && !mire->notmatch) || (rc < 0 && mire-
> >notmatch))
> anymatch++;
> }
> /*@switchbreak@*/ break;
> @@ -2218,7 +2218,7 @@
> for (j = 0; j < (unsigned) he->c; j++) {
> sprintf(numbuf, "%u", (unsigned) he->p.ui32p[j]);
> rc = mireRegexec(mire, numbuf, 0);
> - if ((!rc && !mire->notmatch) || (rc && mire->notmatch))
> + if ((rc >= 0 && !mire->notmatch) || (rc < 0 && mire-
> >notmatch))
> anymatch++;
> }
> /*@switchbreak@*/ break;
> @@ -2227,20 +2227,20 @@
> for (j = 0; j < (unsigned) he->c; j++) {
> sprintf(numbuf, "%llu", (unsigned long long)he->p.ui64p[j]);
> rc = mireRegexec(mire, numbuf, 0);
> - if ((!rc && !mire->notmatch) || (rc && mire->notmatch))
> + if ((rc >= 0 && !mire->notmatch) || (rc < 0 && mire-
> >notmatch))
> anymatch++;
> }
> /*@=duplicatequals@*/
> /*@switchbreak@*/ break;
> case RPM_STRING_TYPE:
> rc = mireRegexec(mire, he->p.str, 0);
> - if ((!rc && !mire->notmatch) || (rc && mire->notmatch))
> + if ((rc >= 0 && !mire->notmatch) || (rc < 0 && mire->notmatch))
> anymatch++;
> /*@switchbreak@*/ break;
> case RPM_STRING_ARRAY_TYPE:
> for (j = 0; j < (unsigned) he->c; j++) {
> rc = mireRegexec(mire, he->p.argv[j], 0);
> - if ((!rc && !mire->notmatch) || (rc && mire->notmatch)) {
> + if ((rc >= 0 && !mire->notmatch) || (rc < 0 && mire-
> >notmatch)) {
> anymatch++;
> /*@innerbreak@*/ break;
> }
> @@ -2249,7 +2249,7 @@
> case RPM_BIN_TYPE:
> { const char * s = bin2hex(he->p.ptr, he->c);
> rc = mireRegexec(mire, s, 0);
> - if ((!rc && !mire->notmatch) || (rc && mire->notmatch))
> + if ((rc >= 0 && !mire->notmatch) || (rc < 0 && mire->notmatch))
> anymatch++;
> s = _free(s);
> } /*@switchbreak@*/ break;
> @@ .
> patch -p0 <<'@@ .'
> Index: rpm/rpmio/macro.c
>
> =
> =
> =
> =
> =
> =
> ======================================================================
> $ cvs diff -u -r2.187 -r2.188 macro.c
> --- rpm/rpmio/macro.c 17 Feb 2008 17:44:18 -0000 2.187
> +++ rpm/rpmio/macro.c 26 Feb 2008 20:42:00 -0000 2.188
> @@ -298,7 +298,7 @@
> if (used == 0 && me->used != 0)
> continue;
> #if !defined(DEBUG_MACROS) /* XXX preserve standalone build */
> - if (mire != NULL && mireRegexec(mire, me->name, 0))
> + if (mire != NULL && mireRegexec(mire, me->name, 0) < 0)
> continue;
> #endif
> av[ac++] = dupMacroEntry(me);
> @@ .
> patch -p0 <<'@@ .'
> Index: rpm/rpmio/mire.c
>
> =
> =
> =
> =
> =
> =
> ======================================================================
> $ cvs diff -u -r1.32 -r1.33 mire.c
> --- rpm/rpmio/mire.c 26 Feb 2008 19:20:19 -0000 1.32
> +++ rpm/rpmio/mire.c 26 Feb 2008 20:42:00 -0000 1.33
> @@ -327,20 +327,25 @@
> case RPMMIRE_STRCMP:
> /* XXX strcasecmp? strncmp? */
> rc = strcmp(mire->pattern, val);
> - if (rc) rc = 1;
> + if (rc) rc = -1;
> break;
> case RPMMIRE_DEFAULT:
> case RPMMIRE_REGEX:
> /*@-nullpass@*/
> rc = regexec(mire->preg, val, 0, NULL, mire->eflags);
> /*@=nullpass@*/
> - if (rc && rc != REG_NOMATCH) {
> - char msg[256];
> + switch (rc) {
> + case 0: rc = 0; /*@innerbreak@*/ break;
> + case REG_NOMATCH: rc = -1;/*@innerbreak@*/ break;
> + default:
> + { char msg[256];
> (void) regerror(rc, mire->preg, msg, sizeof(msg)-1);
> msg[sizeof(msg)-1] = '\0';
> - rpmlog(RPMLOG_ERR, _("%s: regexec failed: %s\n"),
> - mire->pattern, msg);
> - rc = -1;
> + rpmlog(RPMLOG_ERR, _("%s: regexec failed: %s(%d)\n"),
> + mire->pattern, msg, rc);
> + if (rc < 0) rc -= 1; /* XXX ensure -1 is nomatch. */
> + if (rc > 0) rc = -(rc+1); /* XXX ensure errors are negative. */
> + } /*@innerbreak@*/ break;
> }
> break;
> case RPMMIRE_PCRE:
> @@ -349,8 +354,13 @@
> vallen = strlen(val);
> rc = pcre_exec(mire->pcre, mire->hints, val, (int)vallen, mire-
> >startoff,
> mire->eoptions, mire->offsets, mire->noffsets);
> - if (_mire_debug && rc < 0 && rc != PCRE_ERROR_NOMATCH) {
> - rpmlog(RPMLOG_ERR, _("pcre_exec failed: return %d\n"), rc);
> + switch (rc) {
> + case 0: rc = 0; /*@innerbreak@*/ break;
> + case PCRE_ERROR_NOMATCH: rc = -1;/*@innerbreak@*/ break;
> + default:
> + if (_mire_debug && rc < 0)
> + rpmlog(RPMLOG_ERR, _("pcre_exec failed: return %d\n"), rc);
> + /*@innerbreak@*/ break;
> }
> #else
> rc = -99;
> @@ -358,8 +368,16 @@
> break;
> case RPMMIRE_GLOB:
> rc = fnmatch(mire->pattern, val, mire->fnflags);
> - if (rc && rc != FNM_NOMATCH)
> - rc = -1;
> + switch (rc) {
> + case 0: rc = 0; /*@innerbreak@*/ break;
> + case FNM_NOMATCH: rc = -1;/*@innerbreak@*/ break;
> + default:
> + if (_mire_debug)
> + rpmlog(RPMLOG_ERR, _("fnmatch failed: return %d\n"), rc);
> + if (rc < 0) rc -= 1; /* XXX ensure -1 is nomatch. */
> + if (rc > 0) rc = -(rc+1); /* XXX ensure errors are negative. */
> + /*@innerbreak@*/ break;
> + }
> break;
> default:
> rc = -1;
> @@ .
> patch -p0 <<'@@ .'
> Index: rpm/rpmio/mire.h
>
> =
> =
> =
> =
> =
> =
> ======================================================================
> $ cvs diff -u -r1.24 -r1.25 mire.h
> --- rpm/rpmio/mire.h 26 Feb 2008 19:20:19 -0000 1.24
> +++ rpm/rpmio/mire.h 26 Feb 2008 20:42:00 -0000 1.25
> @@ -223,7 +223,7 @@
> * @param mire pattern container
> * @param val value to match
> * @param vallen length of value string (0 will use strlen)
> - * @return 0 if pattern matches, >0 on nomatch, <0 on error
> + * @return >=0 if pattern matches, -1 on nomatch, else error
> */
> int mireRegexec(miRE mire, const char * val, size_t vallen)
> /*@modifies mire @*/;
> @@ .
> patch -p0 <<'@@ .'
> Index: rpm/rpmio/rpmgrep.c
>
> =
> =
> =
> =
> =
> =
> ======================================================================
> $ cvs diff -u -r1.66 -r1.67 rpmgrep.c
> --- rpm/rpmio/rpmgrep.c 26 Feb 2008 19:20:19 -0000 1.66
> +++ rpm/rpmio/rpmgrep.c 26 Feb 2008 20:42:00 -0000 1.67
> @@ -596,13 +596,12 @@
> /* Set sub-string offset array. */
> xx = mireSetEOptions(mire, offsets, 99);
>
> -#if defined(WITH_PCRE) /* XXX HACK: broken functionality without
> PCRE. */
> /*@-onlytrans@*/
> /* XXX WATCHOUT: mireRegexec w length=0 does
> strlen(matchptr)! */
> - mrc = (length > 0 ? mireRegexec(mire, matchptr, length) :
> PCRE_ERROR_NOMATCH);
> + mrc = (length > 0 ? mireRegexec(mire, matchptr, length) : -1);
> /*@=onlytrans@*/
> if (mrc >= 0) { match = TRUE; /*@innerbreak@*/ break; }
> - if (mrc != PCRE_ERROR_NOMATCH) {
> + if (mrc < -1) { /* XXX -1 == NOMATCH, otherwise error. */
> fprintf(stderr, _("%s: pcre_exec() error %d while matching "),
> __progname, mrc);
> if (pattern_count > 1) fprintf(stderr, _("pattern number %d to
> "), i+1);
> fprintf(stderr, _("this line:\n"));
> @@ -630,7 +629,6 @@
> match = invert; /* No more matching; don't show the line
> again */
> /*@innerbreak@*/ break;
> }
> -#endif /* WITH_PCRE broken! */
> }
>
> /* If it's a match or a not-match (as required), do what's
> wanted. */
> @@ .
> patch -p0 <<'@@ .'
> Index: rpm/rpmio/tfts.c
>
> =
> =
> =
> =
> =
> =
> ======================================================================
> $ cvs diff -u -r2.23 -r2.24 tfts.c
> --- rpm/rpmio/tfts.c 24 Feb 2008 06:50:23 -0000 2.23
> +++ rpm/rpmio/tfts.c 26 Feb 2008 20:42:00 -0000 2.24
> @@ -80,7 +80,7 @@
> if (mire) {
> mireNExecs++;
> xx = mireRegexec(mire, fts->fts_path, 0);
> - if (xx == 0) {
> + if (xx >= 0) {
> fprintf(stdout, " mire: %s\n", fts->fts_path);
> mireNMatches++;
> } else {
> @@ .
> patch -p0 <<'@@ .'
> Index: rpm/rpmio/tmire.c
>
> =
> =
> =
> =
> =
> =
> ======================================================================
> $ cvs diff -u -r1.5 -r1.6 tmire.c
> --- rpm/rpmio/tmire.c 10 Feb 2008 18:32:33 -0000 1.5
> +++ rpm/rpmio/tmire.c 26 Feb 2008 20:42:00 -0000 1.6
> @@ -63,7 +63,7 @@
> if (av && *av)
> for (i = 0; i < ac; i++) {
> xx = mireRegexec(mire, av[i], 0);
> - if (xx == 0) {
> + if (xx >= 0) {
> fprintf(stdout, "%s\n", av[i]);
> rc = 0;
> }
> @@ .
> ______________________________________________________________________
> RPM Package Manager http://rpm5.org
> CVS Sources Repository rpm-cvs@rpm5.org
Received on Tue Feb 26 21:56:50 2008