On Sat, 2015-06-06 at 16:18 -0700, Bruce Korb wrote:

> In that log, I find:
> 
> > Compiling '[ -~]' with bits 0x1 <<<=== compiled as extended RE
> > CASE no match: `c' MATCH_FULL vs. `[ -~]'
> I think there is a RE library problem.  The code is as follows:
> >     /*
> >      *  On the first call for this macro, compile the expression
> >      */
> >     if (cur_macro->md_pvt == NULL) {
> >         void *    mat = VOIDP(pattern);
> >         regex_t * re  = AGALOC(sizeof(*re), "select match full re");
> >
> >         if (OPT_VALUE_TRACE > TRACE_EXPRESSIONS) {
> >             fprintf(trace_fp, TRACE_SEL_MATCH_FULL,
> >                      pattern, cur_macro->md_res);
> This function returns FAILURE, and that is incorrect.
> This code has not changed in many years (16).
> Last January, I changed the casting of 'pattern' to coerce it into a "void *"
> without any const attributes, but functionally no changes for 16 years.
> The following program should replicate the same test that fails in AutoGen.
> If this succeeds, then the question is, "what is different in the execution 
> env?"
> If this fails, on the other hand, then you need to look to the regcomp 
> library.

I've compiled and run the attached version of that program and it
succeeds (no valgrind warnings either). 

The differences in the environment during build are the following three
variables.
+MAKEFLAGS=
+MAKELEVEL=1
+MFLAGS=

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <regex.h>

#define VOIDP(_p)  ((void *)(unsigned long)(_p))

static void
compile_re(regex_t * re, char const * pat, int flags)
{
     int rerr = regcomp(re, VOIDP(pat), flags);
     if (rerr != 0) {
         char erbf[ 1024 ];
         regerror(rerr, re, erbf, sizeof(erbf));
         fprintf(stderr, "error\n");
         abort();
     }
}

static int
check_full_match(char const * sample, char const * pattern)
{
     regmatch_t m[2];
     regex_t * md_pvt;

     /*
      *  On the first call for this macro, compile the expression
      */
         void *    mat = VOIDP(pattern);
         regex_t * re  = malloc(sizeof(*re));

         compile_re(re, mat, 1);
         md_pvt = re;

     // In this function, the RE must match the entire string.
     //
     if (regexec(re, sample, (size_t)2, m, 0)
         != 0)
         return 0;

     if (  (m[0].rm_eo != (int)strlen( sample ))
        || (m[0].rm_so != 0))
         return 0;
     return 1;
}

int main(int argc, char ** argv) {
     if (! check_full_match("c", "[ -~]"))
         printf("FAILED\n");
     return 0;
}

Reply via email to