/[pcre]/code/trunk/pcre_exec.c
ViewVC logotype

Diff of /code/trunk/pcre_exec.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 893 by ph10, Thu Jan 19 17:15:11 2012 UTC revision 940 by ph10, Tue Feb 28 10:30:51 2012 UTC
# Line 140  Arguments: Line 140  Arguments:
140    md          points to match data block    md          points to match data block
141    caseless    TRUE if caseless    caseless    TRUE if caseless
142    
143  Returns:      < 0 if not matched, otherwise the number of subject bytes matched  Returns:      >= 0 the number of subject bytes matched
144                  -1 no match
145                  -2 partial match; always given if at end subject
146  */  */
147    
148  static int  static int
# Line 163  pchars(p, length, FALSE, md); Line 165  pchars(p, length, FALSE, md);
165  printf("\n");  printf("\n");
166  #endif  #endif
167    
168  /* Always fail if reference not set (and not JavaScript compatible). */  /* Always fail if reference not set (and not JavaScript compatible - in that
169    case the length is passed as zero). */
170    
171  if (length < 0) return -1;  if (length < 0) return -1;
172    
# Line 189  if (caseless) Line 192  if (caseless)
192      while (p < endptr)      while (p < endptr)
193        {        {
194        int c, d;        int c, d;
195        if (eptr >= md->end_subject) return -1;        if (eptr >= md->end_subject) return -2;   /* Partial match */
196        GETCHARINC(c, eptr);        GETCHARINC(c, eptr);
197        GETCHARINC(d, p);        GETCHARINC(d, p);
198        if (c != d && c != UCD_OTHERCASE(d)) return -1;        if (c != d && c != UCD_OTHERCASE(d)) return -1;
# Line 202  if (caseless) Line 205  if (caseless)
205    /* The same code works when not in UTF-8 mode and in UTF-8 mode when there    /* The same code works when not in UTF-8 mode and in UTF-8 mode when there
206    is no UCP support. */    is no UCP support. */
207      {      {
     if (eptr + length > md->end_subject) return -1;  
208      while (length-- > 0)      while (length-- > 0)
209        {        {
210          if (eptr >= md->end_subject) return -2;   /* Partial match */
211        if (TABLE_GET(*p, md->lcc, *p) != TABLE_GET(*eptr, md->lcc, *eptr)) return -1;        if (TABLE_GET(*p, md->lcc, *p) != TABLE_GET(*eptr, md->lcc, *eptr)) return -1;
212        p++;        p++;
213        eptr++;        eptr++;
# Line 217  are in UTF-8 mode. */ Line 220  are in UTF-8 mode. */
220    
221  else  else
222    {    {
223    if (eptr + length > md->end_subject) return -1;    while (length-- > 0)
224    while (length-- > 0) if (*p++ != *eptr++) return -1;      {
225        if (eptr >= md->end_subject) return -2;   /* Partial match */
226        if (*p++ != *eptr++) return -1;
227        }
228    }    }
229    
230  return (int)(eptr - eptr_start);  return (int)(eptr - eptr_start);
# Line 311  argument of match(), which never changes Line 317  argument of match(), which never changes
317    
318  #define RMATCH(ra,rb,rc,rd,re,rw)\  #define RMATCH(ra,rb,rc,rd,re,rw)\
319    {\    {\
320    heapframe *newframe = (heapframe *)(PUBL(stack_malloc))(sizeof(heapframe));\    heapframe *newframe = frame->Xnextframe;\
321    if (newframe == NULL) RRETURN(PCRE_ERROR_NOMEMORY);\    if (newframe == NULL)\
322    frame->Xwhere = rw; \      {\
323        newframe = (heapframe *)(PUBL(stack_malloc))(sizeof(heapframe));\
324        if (newframe == NULL) RRETURN(PCRE_ERROR_NOMEMORY);\
325        newframe->Xnextframe = NULL;\
326        frame->Xnextframe = newframe;\
327        }\
328      frame->Xwhere = rw;\
329    newframe->Xeptr = ra;\    newframe->Xeptr = ra;\
330    newframe->Xecode = rb;\    newframe->Xecode = rb;\
331    newframe->Xmstart = mstart;\    newframe->Xmstart = mstart;\
# Line 332  argument of match(), which never changes Line 344  argument of match(), which never changes
344    {\    {\
345    heapframe *oldframe = frame;\    heapframe *oldframe = frame;\
346    frame = oldframe->Xprevframe;\    frame = oldframe->Xprevframe;\
   if (oldframe != &frame_zero) (PUBL(stack_free))(oldframe);\  
347    if (frame != NULL)\    if (frame != NULL)\
348      {\      {\
349      rrc = ra;\      rrc = ra;\
# Line 346  argument of match(), which never changes Line 357  argument of match(), which never changes
357    
358  typedef struct heapframe {  typedef struct heapframe {
359    struct heapframe *Xprevframe;    struct heapframe *Xprevframe;
360      struct heapframe *Xnextframe;
361    
362    /* Function arguments that may change */    /* Function arguments that may change */
363    
# Line 487  int condcode; Line 499  int condcode;
499  /* When recursion is not being used, all "local" variables that have to be  /* When recursion is not being used, all "local" variables that have to be
500  preserved over calls to RMATCH() are part of a "frame". We set up the top-level  preserved over calls to RMATCH() are part of a "frame". We set up the top-level
501  frame on the stack here; subsequent instantiations are obtained from the heap  frame on the stack here; subsequent instantiations are obtained from the heap
502  whenever RMATCH() does a "recursion". See the macro definitions above. Putting  whenever RMATCH() does a "recursion". See the macro definitions above. Putting
503  the top-level on the stack rather than malloc-ing them all gives a performance  the top-level on the stack rather than malloc-ing them all gives a performance
504  boost in many cases where there is not much "recursion". */  boost in many cases where there is not much "recursion". */
505    
506  #ifdef NO_RECURSE  #ifdef NO_RECURSE
507  heapframe frame_zero;  heapframe *frame = (heapframe *)md->match_frames_base;
 heapframe *frame = &frame_zero;  
 frame->Xprevframe = NULL;            /* Marks the top level */  
508    
509  /* Copy in the original argument variables */  /* Copy in the original argument variables */
510    
# Line 616  int stacksave[REC_STACK_SAVE_MAX]; Line 626  int stacksave[REC_STACK_SAVE_MAX];
626    
627  eptrblock newptrb;  eptrblock newptrb;
628    
629  /* There is a special fudge for calling match() in a way that causes it to  /* There is a special fudge for calling match() in a way that causes it to
630  measure the size of its basic stack frame when the stack is being used for  measure the size of its basic stack frame when the stack is being used for
631  recursion. The first argument (eptr) points to a pointer that is used  recursion. The second argument (ecode) being NULL triggers this behaviour. It
632  "statically" for doing the calculation. The second argument (ecode) being NULL  cannot normally ever be NULL. The return is the negated value of the frame
633  triggers this behaviour. It cannot normally every be NULL. The return is the  size. */
 negated value of the frame size. */  
634    
635  if (ecode == NULL)  if (ecode == NULL)
636    {    {
   char **aptr = (char **)eptr;  
637    if (rdepth == 0)    if (rdepth == 0)
638      {      return match((PCRE_PUCHAR)&rdepth, NULL, NULL, 0, NULL, NULL, 1);
     *aptr = (char *)&rdepth;  
     return match(eptr, NULL, NULL, 0, NULL, NULL, 1);  
     }  
639    else    else
640      {      {
641      int len = (char *)&rdepth - *aptr;      int len = (char *)&rdepth - (char *)eptr;
642      return (len > 0)? -len : len;      return (len > 0)? -len : len;
643      }      }
644    }    }
645  #endif     /* NO_RECURSE */  #endif     /* NO_RECURSE */
646    
647  /* To save space on the stack and in the heap frame, I have doubled up on some  /* To save space on the stack and in the heap frame, I have doubled up on some
# Line 843  for (;;) Line 848  for (;;)
848      case OP_ONCE_NC:      case OP_ONCE_NC:
849      prev = ecode;      prev = ecode;
850      saved_eptr = eptr;      saved_eptr = eptr;
851      save_mark = md->mark;      save_mark = md->mark;
852      do      do
853        {        {
854        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM64);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM64);
# Line 862  for (;;) Line 867  for (;;)
867    
868        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
869        ecode += GET(ecode,1);        ecode += GET(ecode,1);
870        md->mark = save_mark;        md->mark = save_mark;
871        }        }
872      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
873    
# Line 942  for (;;) Line 947  for (;;)
947        save_offset2 = md->offset_vector[offset+1];        save_offset2 = md->offset_vector[offset+1];
948        save_offset3 = md->offset_vector[md->offset_end - number];        save_offset3 = md->offset_vector[md->offset_end - number];
949        save_capture_last = md->capture_last;        save_capture_last = md->capture_last;
950        save_mark = md->mark;        save_mark = md->mark;
951    
952        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
953        md->offset_vector[md->offset_end - number] =        md->offset_vector[md->offset_end - number] =
# Line 1048  for (;;) Line 1053  for (;;)
1053        save_mark = md->mark;        save_mark = md->mark;
1054        RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md, eptrb,        RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md, eptrb,
1055          RM2);          RM2);
1056    
1057        /* See comment in the code for capturing groups above about handling        /* See comment in the code for capturing groups above about handling
1058        THEN. */        THEN. */
1059    
# Line 1075  for (;;) Line 1080  for (;;)
1080          RRETURN(rrc);          RRETURN(rrc);
1081          }          }
1082        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1083        md->mark = save_mark;        md->mark = save_mark;
1084        if (*ecode != OP_ALT) break;        if (*ecode != OP_ALT) break;
1085        }        }
1086    
# Line 1554  for (;;) Line 1559  for (;;)
1559    
1560      case OP_ASSERT:      case OP_ASSERT:
1561      case OP_ASSERTBACK:      case OP_ASSERTBACK:
1562      save_mark = md->mark;      save_mark = md->mark;
1563      if (md->match_function_type == MATCH_CONDASSERT)      if (md->match_function_type == MATCH_CONDASSERT)
1564        {        {
1565        condassert = TRUE;        condassert = TRUE;
# Line 1570  for (;;) Line 1575  for (;;)
1575          mstart = md->start_match_ptr;   /* In case \K reset it */          mstart = md->start_match_ptr;   /* In case \K reset it */
1576          break;          break;
1577          }          }
1578          md->mark = save_mark;
1579    
1580        /* PCRE does not allow THEN to escape beyond an assertion; it is treated        /* A COMMIT failure must fail the entire assertion, without trying any
1581        as NOMATCH. */        subsequent branches. */
1582    
1583          if (rrc == MATCH_COMMIT) RRETURN(MATCH_NOMATCH);
1584    
1585          /* PCRE does not allow THEN to escape beyond an assertion; it
1586          is treated as NOMATCH. */
1587    
1588        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1589        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
       md->mark = save_mark;  
1590        }        }
1591      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
1592    
# Line 1600  for (;;) Line 1610  for (;;)
1610    
1611      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1612      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
1613      save_mark = md->mark;      save_mark = md->mark;
1614      if (md->match_function_type == MATCH_CONDASSERT)      if (md->match_function_type == MATCH_CONDASSERT)
1615        {        {
1616        condassert = TRUE;        condassert = TRUE;
# Line 1611  for (;;) Line 1621  for (;;)
1621      do      do
1622        {        {
1623        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM5);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM5);
1624        md->mark = save_mark;        md->mark = save_mark;
1625        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) RRETURN(MATCH_NOMATCH);
1626        if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)        if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)
1627          {          {
# Line 1784  for (;;) Line 1794  for (;;)
1794            goto RECURSION_MATCHED;        /* Exit loop; end processing */            goto RECURSION_MATCHED;        /* Exit loop; end processing */
1795            }            }
1796    
1797          /* PCRE does not allow THEN to escape beyond a recursion; it is treated          /* PCRE does not allow THEN or COMMIT to escape beyond a recursion; it
1798          as NOMATCH. */          is treated as NOMATCH. */
1799    
1800          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN &&
1801                     rrc != MATCH_COMMIT)
1802            {            {
1803            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1804            if (new_recursive.offset_save != stacksave)            if (new_recursive.offset_save != stacksave)
# Line 2064  for (;;) Line 2075  for (;;)
2075    
2076      case OP_DOLLM:      case OP_DOLLM:
2077      if (eptr < md->end_subject)      if (eptr < md->end_subject)
2078        { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); }        {
2079          if (!IS_NEWLINE(eptr))
2080            {
2081            if (md->partial != 0 &&
2082                eptr + 1 >= md->end_subject &&
2083                NLBLOCK->nltype == NLTYPE_FIXED &&
2084                NLBLOCK->nllen == 2 &&
2085                *eptr == NLBLOCK->nl[0])
2086              {
2087              md->hitend = TRUE;
2088              if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
2089              }
2090            RRETURN(MATCH_NOMATCH);
2091            }
2092          }
2093      else      else
2094        {        {
2095        if (md->noteol) RRETURN(MATCH_NOMATCH);        if (md->noteol) RRETURN(MATCH_NOMATCH);
# Line 2096  for (;;) Line 2121  for (;;)
2121      ASSERT_NL_OR_EOS:      ASSERT_NL_OR_EOS:
2122      if (eptr < md->end_subject &&      if (eptr < md->end_subject &&
2123          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
2124          {
2125          if (md->partial != 0 &&
2126              eptr + 1 >= md->end_subject &&
2127              NLBLOCK->nltype == NLTYPE_FIXED &&
2128              NLBLOCK->nllen == 2 &&
2129              *eptr == NLBLOCK->nl[0])
2130            {
2131            md->hitend = TRUE;
2132            if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
2133            }
2134        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2135          }
2136    
2137      /* Either at end of string or \n before end. */      /* Either at end of string or \n before end. */
2138    
# Line 2224  for (;;) Line 2260  for (;;)
2260        }        }
2261      break;      break;
2262    
2263      /* Match a single character type; inline for speed */      /* Match any single character type except newline; have to take care with
2264        CRLF newlines and partial matching. */
2265    
2266      case OP_ANY:      case OP_ANY:
2267      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
2268        if (md->partial != 0 &&
2269            eptr + 1 >= md->end_subject &&
2270            NLBLOCK->nltype == NLTYPE_FIXED &&
2271            NLBLOCK->nllen == 2 &&
2272            *eptr == NLBLOCK->nl[0])
2273          {
2274          md->hitend = TRUE;
2275          if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
2276          }
2277    
2278      /* Fall through */      /* Fall through */
2279    
2280        /* Match any single character whatsoever. */
2281    
2282      case OP_ALLANY:      case OP_ALLANY:
2283      if (eptr >= md->end_subject)   /* DO NOT merge the eptr++ here; it must */      if (eptr >= md->end_subject)   /* DO NOT merge the eptr++ here; it must */
2284        {                            /* not be updated before SCHECK_PARTIAL. */        {                            /* not be updated before SCHECK_PARTIAL. */
# Line 2370  for (;;) Line 2419  for (;;)
2419        default: RRETURN(MATCH_NOMATCH);        default: RRETURN(MATCH_NOMATCH);
2420    
2421        case 0x000d:        case 0x000d:
2422        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;        if (eptr >= md->end_subject)
2423            {
2424            SCHECK_PARTIAL();
2425            }
2426          else if (*eptr == 0x0a) eptr++;
2427        break;        break;
2428    
2429        case 0x000a:        case 0x000a:
# Line 2600  for (;;) Line 2653  for (;;)
2653        if (UCD_CATEGORY(c) != ucp_M) break;        if (UCD_CATEGORY(c) != ucp_M) break;
2654        eptr += len;        eptr += len;
2655        }        }
2656        CHECK_PARTIAL();
2657      ecode++;      ecode++;
2658      break;      break;
2659  #endif  #endif
# Line 2665  for (;;) Line 2719  for (;;)
2719        default:               /* No repeat follows */        default:               /* No repeat follows */
2720        if ((length = match_ref(offset, eptr, length, md, caseless)) < 0)        if ((length = match_ref(offset, eptr, length, md, caseless)) < 0)
2721          {          {
2722            if (length == -2) eptr = md->end_subject;   /* Partial match */
2723          CHECK_PARTIAL();          CHECK_PARTIAL();
2724          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2725          }          }
# Line 2690  for (;;) Line 2745  for (;;)
2745        int slength;        int slength;
2746        if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)        if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2747          {          {
2748            if (slength == -2) eptr = md->end_subject;   /* Partial match */
2749          CHECK_PARTIAL();          CHECK_PARTIAL();
2750          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2751          }          }
# Line 2713  for (;;) Line 2769  for (;;)
2769          if (fi >= max) RRETURN(MATCH_NOMATCH);          if (fi >= max) RRETURN(MATCH_NOMATCH);
2770          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2771            {            {
2772              if (slength == -2) eptr = md->end_subject;   /* Partial match */
2773            CHECK_PARTIAL();            CHECK_PARTIAL();
2774            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
2775            }            }
# Line 2731  for (;;) Line 2788  for (;;)
2788          int slength;          int slength;
2789          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2790            {            {
2791            CHECK_PARTIAL();            /* Can't use CHECK_PARTIAL because we don't want to update eptr in
2792              the soft partial matching case. */
2793    
2794              if (slength == -2 && md->partial != 0 &&
2795                  md->end_subject > md->start_used_ptr)
2796                {
2797                md->hitend = TRUE;
2798                if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
2799                }
2800            break;            break;
2801            }            }
2802          eptr += slength;          eptr += slength;
2803          }          }
2804    
2805        while (eptr >= pp)        while (eptr >= pp)
2806          {          {
2807          RMATCH(eptr, ecode, offset_top, md, eptrb, RM15);          RMATCH(eptr, ecode, offset_top, md, eptrb, RM15);
# Line 3509  for (;;) Line 3575  for (;;)
3575        SCHECK_PARTIAL();        SCHECK_PARTIAL();
3576        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
3577        }        }
     ecode++;  
     GETCHARINCTEST(c, eptr);  
     if (op == OP_NOTI)         /* The caseless case */  
       {  
       register int ch, och;  
       ch = *ecode++;  
 #ifdef COMPILE_PCRE8  
       /* ch must be < 128 if UTF is enabled. */  
       och = md->fcc[ch];  
 #else  
3578  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3579        if (utf)
3580          {
3581          register unsigned int ch, och;
3582    
3583          ecode++;
3584          GETCHARINC(ch, ecode);
3585          GETCHARINC(c, eptr);
3586    
3587          if (op == OP_NOT)
3588            {
3589            if (ch == c) RRETURN(MATCH_NOMATCH);
3590            }
3591          else
3592            {
3593  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3594        if (utf && ch > 127)          if (ch > 127)
3595          och = UCD_OTHERCASE(ch);            och = UCD_OTHERCASE(ch);
3596  #else  #else
3597        if (utf && ch > 127)          if (ch > 127)
3598          och = ch;            och = ch;
3599  #endif /* SUPPORT_UCP */  #endif /* SUPPORT_UCP */
3600        else          else
3601  #endif /* SUPPORT_UTF */            och = TABLE_GET(ch, md->fcc, ch);
3602          och = TABLE_GET(ch, md->fcc, ch);          if (ch == c || och == c) RRETURN(MATCH_NOMATCH);
3603  #endif /* COMPILE_PCRE8 */          }
       if (ch == c || och == c) RRETURN(MATCH_NOMATCH);  
3604        }        }
3605      else    /* Caseful */      else
3606    #endif
3607        {        {
3608        if (*ecode++ == c) RRETURN(MATCH_NOMATCH);        register unsigned int ch = ecode[1];
3609          c = *eptr++;
3610          if (ch == c || (op == OP_NOTI && TABLE_GET(ch, md->fcc, ch) == c))
3611            RRETURN(MATCH_NOMATCH);
3612          ecode += 2;
3613        }        }
3614      break;      break;
3615    
# Line 3615  for (;;) Line 3689  for (;;)
3689      /* Common code for all repeated single-byte matches. */      /* Common code for all repeated single-byte matches. */
3690    
3691      REPEATNOTCHAR:      REPEATNOTCHAR:
3692      fc = *ecode++;      GETCHARINCTEST(fc, ecode);
3693    
3694      /* The code is duplicated for the caseless and caseful cases, for speed,      /* The code is duplicated for the caseless and caseful cases, for speed,
3695      since matching characters is likely to be quite common. First, ensure the      since matching characters is likely to be quite common. First, ensure the
# Line 3630  for (;;) Line 3704  for (;;)
3704    
3705      if (op >= OP_NOTSTARI)     /* Caseless */      if (op >= OP_NOTSTARI)     /* Caseless */
3706        {        {
 #ifdef COMPILE_PCRE8  
       /* fc must be < 128 if UTF is enabled. */  
       foc = md->fcc[fc];  
 #else  
3707  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3708  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3709        if (utf && fc > 127)        if (utf && fc > 127)
# Line 3645  for (;;) Line 3715  for (;;)
3715        else        else
3716  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
3717          foc = TABLE_GET(fc, md->fcc, fc);          foc = TABLE_GET(fc, md->fcc, fc);
 #endif /* COMPILE_PCRE8 */  
3718    
3719  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3720        if (utf)        if (utf)
# Line 3659  for (;;) Line 3728  for (;;)
3728              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3729              }              }
3730            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
3731            if (fc == d || foc == d) RRETURN(MATCH_NOMATCH);            if (fc == d || (unsigned int)foc == d) RRETURN(MATCH_NOMATCH);
3732            }            }
3733          }          }
3734        else        else
# Line 3697  for (;;) Line 3766  for (;;)
3766                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3767                }                }
3768              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
3769              if (fc == d || foc == d) RRETURN(MATCH_NOMATCH);              if (fc == d || (unsigned int)foc == d) RRETURN(MATCH_NOMATCH);
3770              }              }
3771            }            }
3772          else          else
# Line 3740  for (;;) Line 3809  for (;;)
3809                break;                break;
3810                }                }
3811              GETCHARLEN(d, eptr, len);              GETCHARLEN(d, eptr, len);
3812              if (fc == d || foc == d) break;              if (fc == d || (unsigned int)foc == d) break;
3813              eptr += len;              eptr += len;
3814              }              }
3815            if (possessive) continue;            if (possessive) continue;
# Line 4169  for (;;) Line 4238  for (;;)
4238              if (UCD_CATEGORY(c) != ucp_M) break;              if (UCD_CATEGORY(c) != ucp_M) break;
4239              eptr += len;              eptr += len;
4240              }              }
4241              CHECK_PARTIAL();
4242            }            }
4243          }          }
4244    
# Line 4189  for (;;) Line 4259  for (;;)
4259              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4260              }              }
4261            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
4262              if (md->partial != 0 &&
4263                  eptr + 1 >= md->end_subject &&
4264                  NLBLOCK->nltype == NLTYPE_FIXED &&
4265                  NLBLOCK->nllen == 2 &&
4266                  *eptr == NLBLOCK->nl[0])
4267                {
4268                md->hitend = TRUE;
4269                if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
4270                }
4271            eptr++;            eptr++;
4272            ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);            ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
4273            }            }
# Line 4473  for (;;) Line 4552  for (;;)
4552              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4553              }              }
4554            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
4555              if (md->partial != 0 &&
4556                  eptr + 1 >= md->end_subject &&
4557                  NLBLOCK->nltype == NLTYPE_FIXED &&
4558                  NLBLOCK->nllen == 2 &&
4559                  *eptr == NLBLOCK->nl[0])
4560                {
4561                md->hitend = TRUE;
4562                if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
4563                }
4564            eptr++;            eptr++;
4565            }            }
4566          break;          break;
# Line 4953  for (;;) Line 5041  for (;;)
5041              if (UCD_CATEGORY(c) != ucp_M) break;              if (UCD_CATEGORY(c) != ucp_M) break;
5042              eptr += len;              eptr += len;
5043              }              }
5044              CHECK_PARTIAL();
5045            }            }
5046          }          }
5047        else        else
# Line 4976  for (;;) Line 5065  for (;;)
5065            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
5066            switch(ctype)            switch(ctype)
5067              {              {
5068              case OP_ANY:        /* This is the non-NL case */              case OP_ANY:               /* This is the non-NL case */
5069                if (md->partial != 0 &&    /* Take care with CRLF partial */
5070                    eptr >= md->end_subject &&
5071                    NLBLOCK->nltype == NLTYPE_FIXED &&
5072                    NLBLOCK->nllen == 2 &&
5073                    c == NLBLOCK->nl[0])
5074                  {
5075                  md->hitend = TRUE;
5076                  if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
5077                  }
5078                break;
5079    
5080              case OP_ALLANY:              case OP_ALLANY:
5081              case OP_ANYBYTE:              case OP_ANYBYTE:
5082              break;              break;
# Line 5139  for (;;) Line 5239  for (;;)
5239            c = *eptr++;            c = *eptr++;
5240            switch(ctype)            switch(ctype)
5241              {              {
5242              case OP_ANY:     /* This is the non-NL case */              case OP_ANY:               /* This is the non-NL case */
5243                if (md->partial != 0 &&    /* Take care with CRLF partial */
5244                    eptr >= md->end_subject &&
5245                    NLBLOCK->nltype == NLTYPE_FIXED &&
5246                    NLBLOCK->nllen == 2 &&
5247                    c == NLBLOCK->nl[0])
5248                  {
5249                  md->hitend = TRUE;
5250                  if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
5251                  }
5252                break;
5253    
5254              case OP_ALLANY:              case OP_ALLANY:
5255              case OP_ANYBYTE:              case OP_ANYBYTE:
5256              break;              break;
# Line 5496  for (;;) Line 5607  for (;;)
5607              if (UCD_CATEGORY(c) != ucp_M) break;              if (UCD_CATEGORY(c) != ucp_M) break;
5608              eptr += len;              eptr += len;
5609              }              }
5610              CHECK_PARTIAL();
5611            }            }
5612    
5613          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
# Line 5539  for (;;) Line 5651  for (;;)
5651                  break;                  break;
5652                  }                  }
5653                if (IS_NEWLINE(eptr)) break;                if (IS_NEWLINE(eptr)) break;
5654                  if (md->partial != 0 &&    /* Take care with CRLF partial */
5655                      eptr + 1 >= md->end_subject &&
5656                      NLBLOCK->nltype == NLTYPE_FIXED &&
5657                      NLBLOCK->nllen == 2 &&
5658                      *eptr == NLBLOCK->nl[0])
5659                    {
5660                    md->hitend = TRUE;
5661                    if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
5662                    }
5663                eptr++;                eptr++;
5664                ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);                ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
5665                }                }
# Line 5556  for (;;) Line 5677  for (;;)
5677                  break;                  break;
5678                  }                  }
5679                if (IS_NEWLINE(eptr)) break;                if (IS_NEWLINE(eptr)) break;
5680                  if (md->partial != 0 &&    /* Take care with CRLF partial */
5681                      eptr + 1 >= md->end_subject &&
5682                      NLBLOCK->nltype == NLTYPE_FIXED &&
5683                      NLBLOCK->nllen == 2 &&
5684                      *eptr == NLBLOCK->nl[0])
5685                    {
5686                    md->hitend = TRUE;
5687                    if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
5688                    }
5689                eptr++;                eptr++;
5690                ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);                ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
5691                }                }
# Line 5820  for (;;) Line 5950  for (;;)
5950                break;                break;
5951                }                }
5952              if (IS_NEWLINE(eptr)) break;              if (IS_NEWLINE(eptr)) break;
5953                if (md->partial != 0 &&    /* Take care with CRLF partial */
5954                    eptr + 1 >= md->end_subject &&
5955                    NLBLOCK->nltype == NLTYPE_FIXED &&
5956                    NLBLOCK->nllen == 2 &&
5957                    *eptr == NLBLOCK->nl[0])
5958                  {
5959                  md->hitend = TRUE;
5960                  if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
5961                  }
5962              eptr++;              eptr++;
5963              }              }
5964            break;            break;
# Line 6150  Undefine all the macros that were define Line 6289  Undefine all the macros that were define
6289  ***************************************************************************/  ***************************************************************************/
6290    
6291    
6292    #ifdef NO_RECURSE
6293    /*************************************************
6294    *          Release allocated heap frames         *
6295    *************************************************/
6296    
6297    /* This function releases all the allocated frames. The base frame is on the
6298    machine stack, and so must not be freed.
6299    
6300    Argument: the address of the base frame
6301    Returns:  nothing
6302    */
6303    
6304    static void
6305    release_match_heapframes (heapframe *frame_base)
6306    {
6307    heapframe *nextframe = frame_base->Xnextframe;
6308    while (nextframe != NULL)
6309      {
6310      heapframe *oldframe = nextframe;
6311      nextframe = nextframe->Xnextframe;
6312      (PUBL(stack_free))(oldframe);
6313      }
6314    }
6315    #endif
6316    
6317    
6318  /*************************************************  /*************************************************
6319  *         Execute a Regular Expression           *  *         Execute a Regular Expression           *
# Line 6212  PCRE_PUCHAR req_char_ptr = start_match - Line 6376  PCRE_PUCHAR req_char_ptr = start_match -
6376  const pcre_study_data *study;  const pcre_study_data *study;
6377  const REAL_PCRE *re = (const REAL_PCRE *)argument_re;  const REAL_PCRE *re = (const REAL_PCRE *)argument_re;
6378    
6379  /* Check for the special magic call that measures the size of the stack used  #ifdef NO_RECURSE
6380  per recursive call of match(). */  heapframe frame_zero;
6381    frame_zero.Xprevframe = NULL;            /* Marks the top level */
6382    frame_zero.Xnextframe = NULL;            /* None are allocated yet */
6383    md->match_frames_base = &frame_zero;
6384    #endif
6385    
6386    /* Check for the special magic call that measures the size of the stack used
6387    per recursive call of match(). Without the funny casting for sizeof, a Windows
6388    compiler gave this error: "unary minus operator applied to unsigned type,
6389    result still unsigned". Hopefully the cast fixes that. */
6390    
6391  if (re == NULL && extra_data == NULL && subject == NULL && length == -1)  if (re == NULL && extra_data == NULL && subject == NULL && length == -999 &&
6392        start_offset == -999)
6393  #ifdef NO_RECURSE  #ifdef NO_RECURSE
6394    return -sizeof(heapframe);    return -((int)sizeof(heapframe));
6395  #else  #else
6396    return match((PCRE_PUCHAR)&start_partial, NULL, NULL, 0, NULL, NULL, 0);    return match(NULL, NULL, NULL, 0, NULL, NULL, 0);
6397  #endif  #endif
6398    
6399  /* Plausibility checks */  /* Plausibility checks */
6400    
6401  if ((options & ~PUBLIC_EXEC_OPTIONS) != 0) return PCRE_ERROR_BADOPTION;  if ((options & ~PUBLIC_EXEC_OPTIONS) != 0) return PCRE_ERROR_BADOPTION;
6402  if (re == NULL || subject == NULL || (offsets == NULL && offsetcount > 0))  if (re == NULL || subject == NULL || (offsets == NULL && offsetcount > 0))
6403    return PCRE_ERROR_NULL;    return PCRE_ERROR_NULL;
6404  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;
6405  if (start_offset < 0 || start_offset > length) return PCRE_ERROR_BADOFFSET;  if (start_offset < 0 || start_offset > length) return PCRE_ERROR_BADOFFSET;
# Line 6284  if (utf && (options & PCRE_NO_UTF8_CHECK Line 6458  if (utf && (options & PCRE_NO_UTF8_CHECK
6458  /* If the pattern was successfully studied with JIT support, run the JIT  /* If the pattern was successfully studied with JIT support, run the JIT
6459  executable instead of the rest of this function. Most options must be set at  executable instead of the rest of this function. Most options must be set at
6460  compile time for the JIT code to be usable. Fallback to the normal code path if  compile time for the JIT code to be usable. Fallback to the normal code path if
6461  an unsupported flag is set. In particular, JIT does not support partial  an unsupported flag is set. */
 matching. */  
6462    
6463  #ifdef SUPPORT_JIT  #ifdef SUPPORT_JIT
6464  if (extra_data != NULL  if (extra_data != NULL
6465      && (extra_data->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0      && (extra_data->flags & (PCRE_EXTRA_EXECUTABLE_JIT |
6466                                 PCRE_EXTRA_TABLES)) == PCRE_EXTRA_EXECUTABLE_JIT
6467      && extra_data->executable_jit != NULL      && extra_data->executable_jit != NULL
     && (extra_data->flags & PCRE_EXTRA_TABLES) == 0  
6468      && (options & ~(PCRE_NO_UTF8_CHECK | PCRE_NOTBOL | PCRE_NOTEOL |      && (options & ~(PCRE_NO_UTF8_CHECK | PCRE_NOTBOL | PCRE_NOTEOL |
6469                      PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART)) == 0)                      PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART |
6470    return PRIV(jit_exec)(re, extra_data->executable_jit,                      PCRE_PARTIAL_SOFT | PCRE_PARTIAL_HARD)) == 0)
6471      {
6472      rc = PRIV(jit_exec)(re, extra_data->executable_jit,
6473      (const pcre_uchar *)subject, length, start_offset, options,      (const pcre_uchar *)subject, length, start_offset, options,
6474      ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0)      ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0)
6475      ? MATCH_LIMIT : extra_data->match_limit, offsets, offsetcount);      ? MATCH_LIMIT : extra_data->match_limit, offsets, offsetcount,
6476        ((extra_data->flags & PCRE_EXTRA_MARK) != 0) ? extra_data->mark : NULL);
6477    
6478      /* PCRE_ERROR_NULL means that the selected normal or partial matching
6479      mode is not compiled. In this case we simply fallback to interpreter. */
6480    
6481      if (rc != PCRE_ERROR_NULL) return rc;
6482      }
6483  #endif  #endif
6484    
6485  /* Carry on with non-JIT matching. This information is for finding all the  /* Carry on with non-JIT matching. This information is for finding all the
# Line 6500  if (!anchored) Line 6682  if (!anchored)
6682    if ((re->flags & PCRE_FIRSTSET) != 0)    if ((re->flags & PCRE_FIRSTSET) != 0)
6683      {      {
6684      has_first_char = TRUE;      has_first_char = TRUE;
6685      first_char = first_char2 = re->first_char;      first_char = first_char2 = (pcre_uchar)(re->first_char);
6686      if ((re->flags & PCRE_FCH_CASELESS) != 0)      if ((re->flags & PCRE_FCH_CASELESS) != 0)
6687        {        {
6688        first_char2 = TABLE_GET(first_char, md->fcc, first_char);        first_char2 = TABLE_GET(first_char, md->fcc, first_char);
# Line 6522  character" set. */ Line 6704  character" set. */
6704  if ((re->flags & PCRE_REQCHSET) != 0)  if ((re->flags & PCRE_REQCHSET) != 0)
6705    {    {
6706    has_req_char = TRUE;    has_req_char = TRUE;
6707    req_char = req_char2 = re->req_char;    req_char = req_char2 = (pcre_uchar)(re->req_char);
6708    if ((re->flags & PCRE_RCH_CASELESS) != 0)    if ((re->flags & PCRE_RCH_CASELESS) != 0)
6709      {      {
6710      req_char2 = TABLE_GET(req_char, md->fcc, req_char);      req_char2 = TABLE_GET(req_char, md->fcc, req_char);
# Line 6912  if (rc == MATCH_MATCH || rc == MATCH_ACC Line 7094  if (rc == MATCH_MATCH || rc == MATCH_ACC
7094    if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_MARK) != 0)    if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_MARK) != 0)
7095      *(extra_data->mark) = (pcre_uchar *)md->mark;      *(extra_data->mark) = (pcre_uchar *)md->mark;
7096    DPRINTF((">>>> returning %d\n", rc));    DPRINTF((">>>> returning %d\n", rc));
7097    #ifdef NO_RECURSE
7098      release_match_heapframes(&frame_zero);
7099    #endif
7100    return rc;    return rc;
7101    }    }
7102    
# Line 6929  if (using_temporary_offsets) Line 7114  if (using_temporary_offsets)
7114  if (rc != MATCH_NOMATCH && rc != PCRE_ERROR_PARTIAL)  if (rc != MATCH_NOMATCH && rc != PCRE_ERROR_PARTIAL)
7115    {    {
7116    DPRINTF((">>>> error: returning %d\n", rc));    DPRINTF((">>>> error: returning %d\n", rc));
7117    #ifdef NO_RECURSE
7118      release_match_heapframes(&frame_zero);
7119    #endif
7120    return rc;    return rc;
7121    }    }
7122    
# Line 6958  else Line 7146  else
7146    
7147  if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_MARK) != 0)  if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_MARK) != 0)
7148    *(extra_data->mark) = (pcre_uchar *)md->nomatch_mark;    *(extra_data->mark) = (pcre_uchar *)md->nomatch_mark;
7149    #ifdef NO_RECURSE
7150      release_match_heapframes(&frame_zero);
7151    #endif
7152  return rc;  return rc;
7153  }  }
7154    

Legend:
Removed from v.893  
changed lines
  Added in v.940

  ViewVC Help
Powered by ViewVC 1.1.5