/[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 895 by ph10, Fri Jan 20 12:12:03 2012 UTC revision 934 by ph10, Sat Feb 25 12:30:36 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 second argument (ecode) being NULL triggers this behaviour. It  recursion. The second argument (ecode) being NULL triggers this behaviour. It
632  cannot normally every be NULL. The return is the negated value of the frame  cannot normally ever be NULL. The return is the negated value of the frame
633  size. */  size. */
634    
635  if (ecode == NULL)  if (ecode == NULL)
# Line 631  if (ecode == NULL) Line 641  if (ecode == NULL)
641      int len = (char *)&rdepth - (char *)eptr;      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 838  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 857  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 937  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 1043  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 1070  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 1549  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 1571  for (;;) Line 1581  for (;;)
1581    
1582        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1583        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1584        md->mark = save_mark;        md->mark = save_mark;
1585        }        }
1586      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
1587    
# Line 1595  for (;;) Line 1605  for (;;)
1605    
1606      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1607      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
1608      save_mark = md->mark;      save_mark = md->mark;
1609      if (md->match_function_type == MATCH_CONDASSERT)      if (md->match_function_type == MATCH_CONDASSERT)
1610        {        {
1611        condassert = TRUE;        condassert = TRUE;
# Line 1606  for (;;) Line 1616  for (;;)
1616      do      do
1617        {        {
1618        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM5);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM5);
1619        md->mark = save_mark;        md->mark = save_mark;
1620        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) RRETURN(MATCH_NOMATCH);
1621        if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)        if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)
1622          {          {
# Line 1779  for (;;) Line 1789  for (;;)
1789            goto RECURSION_MATCHED;        /* Exit loop; end processing */            goto RECURSION_MATCHED;        /* Exit loop; end processing */
1790            }            }
1791    
1792          /* 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
1793          as NOMATCH. */          is treated as NOMATCH. */
1794    
1795          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN &&
1796                     rrc != MATCH_COMMIT)
1797            {            {
1798            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1799            if (new_recursive.offset_save != stacksave)            if (new_recursive.offset_save != stacksave)
# Line 2059  for (;;) Line 2070  for (;;)
2070    
2071      case OP_DOLLM:      case OP_DOLLM:
2072      if (eptr < md->end_subject)      if (eptr < md->end_subject)
2073        { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); }        {
2074          if (!IS_NEWLINE(eptr))
2075            {
2076            if (md->partial != 0 &&
2077                eptr + 1 >= md->end_subject &&
2078                NLBLOCK->nltype == NLTYPE_FIXED &&
2079                NLBLOCK->nllen == 2 &&
2080                *eptr == NLBLOCK->nl[0])
2081              {
2082              md->hitend = TRUE;
2083              if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
2084              }
2085            RRETURN(MATCH_NOMATCH);
2086            }
2087          }
2088      else      else
2089        {        {
2090        if (md->noteol) RRETURN(MATCH_NOMATCH);        if (md->noteol) RRETURN(MATCH_NOMATCH);
# Line 2091  for (;;) Line 2116  for (;;)
2116      ASSERT_NL_OR_EOS:      ASSERT_NL_OR_EOS:
2117      if (eptr < md->end_subject &&      if (eptr < md->end_subject &&
2118          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
2119          {
2120          if (md->partial != 0 &&
2121              eptr + 1 >= md->end_subject &&
2122              NLBLOCK->nltype == NLTYPE_FIXED &&
2123              NLBLOCK->nllen == 2 &&
2124              *eptr == NLBLOCK->nl[0])
2125            {
2126            md->hitend = TRUE;
2127            if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
2128            }
2129        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2130          }
2131    
2132      /* Either at end of string or \n before end. */      /* Either at end of string or \n before end. */
2133    
# Line 2219  for (;;) Line 2255  for (;;)
2255        }        }
2256      break;      break;
2257    
2258      /* Match a single character type; inline for speed */      /* Match any single character type except newline; have to take care with
2259        CRLF newlines and partial matching. */
2260    
2261      case OP_ANY:      case OP_ANY:
2262      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
2263        if (md->partial != 0 &&
2264            eptr + 1 >= md->end_subject &&
2265            NLBLOCK->nltype == NLTYPE_FIXED &&
2266            NLBLOCK->nllen == 2 &&
2267            *eptr == NLBLOCK->nl[0])
2268          {
2269          md->hitend = TRUE;
2270          if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
2271          }
2272    
2273      /* Fall through */      /* Fall through */
2274    
2275        /* Match any single character whatsoever. */
2276    
2277      case OP_ALLANY:      case OP_ALLANY:
2278      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 */
2279        {                            /* not be updated before SCHECK_PARTIAL. */        {                            /* not be updated before SCHECK_PARTIAL. */
# Line 2365  for (;;) Line 2414  for (;;)
2414        default: RRETURN(MATCH_NOMATCH);        default: RRETURN(MATCH_NOMATCH);
2415    
2416        case 0x000d:        case 0x000d:
2417        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;        if (eptr >= md->end_subject)
2418            {
2419            SCHECK_PARTIAL();
2420            }
2421          else if (*eptr == 0x0a) eptr++;
2422        break;        break;
2423    
2424        case 0x000a:        case 0x000a:
# Line 2595  for (;;) Line 2648  for (;;)
2648        if (UCD_CATEGORY(c) != ucp_M) break;        if (UCD_CATEGORY(c) != ucp_M) break;
2649        eptr += len;        eptr += len;
2650        }        }
2651        CHECK_PARTIAL();
2652      ecode++;      ecode++;
2653      break;      break;
2654  #endif  #endif
# Line 2660  for (;;) Line 2714  for (;;)
2714        default:               /* No repeat follows */        default:               /* No repeat follows */
2715        if ((length = match_ref(offset, eptr, length, md, caseless)) < 0)        if ((length = match_ref(offset, eptr, length, md, caseless)) < 0)
2716          {          {
2717            if (length == -2) eptr = md->end_subject;   /* Partial match */
2718          CHECK_PARTIAL();          CHECK_PARTIAL();
2719          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2720          }          }
# Line 2685  for (;;) Line 2740  for (;;)
2740        int slength;        int slength;
2741        if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)        if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2742          {          {
2743            if (slength == -2) eptr = md->end_subject;   /* Partial match */
2744          CHECK_PARTIAL();          CHECK_PARTIAL();
2745          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2746          }          }
# Line 2708  for (;;) Line 2764  for (;;)
2764          if (fi >= max) RRETURN(MATCH_NOMATCH);          if (fi >= max) RRETURN(MATCH_NOMATCH);
2765          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2766            {            {
2767              if (slength == -2) eptr = md->end_subject;   /* Partial match */
2768            CHECK_PARTIAL();            CHECK_PARTIAL();
2769            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
2770            }            }
# Line 2726  for (;;) Line 2783  for (;;)
2783          int slength;          int slength;
2784          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2785            {            {
2786            CHECK_PARTIAL();            /* Can't use CHECK_PARTIAL because we don't want to update eptr in
2787              the soft partial matching case. */
2788    
2789              if (slength == -2 && md->partial != 0 &&
2790                  md->end_subject > md->start_used_ptr)
2791                {
2792                md->hitend = TRUE;
2793                if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
2794                }
2795            break;            break;
2796            }            }
2797          eptr += slength;          eptr += slength;
2798          }          }
2799    
2800        while (eptr >= pp)        while (eptr >= pp)
2801          {          {
2802          RMATCH(eptr, ecode, offset_top, md, eptrb, RM15);          RMATCH(eptr, ecode, offset_top, md, eptrb, RM15);
# Line 3504  for (;;) Line 3570  for (;;)
3570        SCHECK_PARTIAL();        SCHECK_PARTIAL();
3571        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
3572        }        }
     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  
3573  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3574        if (utf)
3575          {
3576          register unsigned int ch, och;
3577    
3578          ecode++;
3579          GETCHARINC(ch, ecode);
3580          GETCHARINC(c, eptr);
3581    
3582          if (op == OP_NOT)
3583            {
3584            if (ch == c) RRETURN(MATCH_NOMATCH);
3585            }
3586          else
3587            {
3588  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3589        if (utf && ch > 127)          if (ch > 127)
3590          och = UCD_OTHERCASE(ch);            och = UCD_OTHERCASE(ch);
3591  #else  #else
3592        if (utf && ch > 127)          if (ch > 127)
3593          och = ch;            och = ch;
3594  #endif /* SUPPORT_UCP */  #endif /* SUPPORT_UCP */
3595        else          else
3596  #endif /* SUPPORT_UTF */            och = TABLE_GET(ch, md->fcc, ch);
3597          och = TABLE_GET(ch, md->fcc, ch);          if (ch == c || och == c) RRETURN(MATCH_NOMATCH);
3598  #endif /* COMPILE_PCRE8 */          }
       if (ch == c || och == c) RRETURN(MATCH_NOMATCH);  
3599        }        }
3600      else    /* Caseful */      else
3601    #endif
3602        {        {
3603        if (*ecode++ == c) RRETURN(MATCH_NOMATCH);        register unsigned int ch = ecode[1];
3604          c = *eptr++;
3605          if (ch == c || (op == OP_NOTI && TABLE_GET(ch, md->fcc, ch) == c))
3606            RRETURN(MATCH_NOMATCH);
3607          ecode += 2;
3608        }        }
3609      break;      break;
3610    
# Line 3610  for (;;) Line 3684  for (;;)
3684      /* Common code for all repeated single-byte matches. */      /* Common code for all repeated single-byte matches. */
3685    
3686      REPEATNOTCHAR:      REPEATNOTCHAR:
3687      fc = *ecode++;      GETCHARINCTEST(fc, ecode);
3688    
3689      /* The code is duplicated for the caseless and caseful cases, for speed,      /* The code is duplicated for the caseless and caseful cases, for speed,
3690      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 3625  for (;;) Line 3699  for (;;)
3699    
3700      if (op >= OP_NOTSTARI)     /* Caseless */      if (op >= OP_NOTSTARI)     /* Caseless */
3701        {        {
 #ifdef COMPILE_PCRE8  
       /* fc must be < 128 if UTF is enabled. */  
       foc = md->fcc[fc];  
 #else  
3702  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3703  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3704        if (utf && fc > 127)        if (utf && fc > 127)
# Line 3640  for (;;) Line 3710  for (;;)
3710        else        else
3711  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
3712          foc = TABLE_GET(fc, md->fcc, fc);          foc = TABLE_GET(fc, md->fcc, fc);
 #endif /* COMPILE_PCRE8 */  
3713    
3714  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3715        if (utf)        if (utf)
# Line 3654  for (;;) Line 3723  for (;;)
3723              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3724              }              }
3725            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
3726            if (fc == d || foc == d) RRETURN(MATCH_NOMATCH);            if (fc == d || (unsigned int)foc == d) RRETURN(MATCH_NOMATCH);
3727            }            }
3728          }          }
3729        else        else
# Line 3692  for (;;) Line 3761  for (;;)
3761                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3762                }                }
3763              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
3764              if (fc == d || foc == d) RRETURN(MATCH_NOMATCH);              if (fc == d || (unsigned int)foc == d) RRETURN(MATCH_NOMATCH);
3765              }              }
3766            }            }
3767          else          else
# Line 3735  for (;;) Line 3804  for (;;)
3804                break;                break;
3805                }                }
3806              GETCHARLEN(d, eptr, len);              GETCHARLEN(d, eptr, len);
3807              if (fc == d || foc == d) break;              if (fc == d || (unsigned int)foc == d) break;
3808              eptr += len;              eptr += len;
3809              }              }
3810            if (possessive) continue;            if (possessive) continue;
# Line 4164  for (;;) Line 4233  for (;;)
4233              if (UCD_CATEGORY(c) != ucp_M) break;              if (UCD_CATEGORY(c) != ucp_M) break;
4234              eptr += len;              eptr += len;
4235              }              }
4236              CHECK_PARTIAL();
4237            }            }
4238          }          }
4239    
# Line 4184  for (;;) Line 4254  for (;;)
4254              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4255              }              }
4256            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
4257              if (md->partial != 0 &&
4258                  eptr + 1 >= md->end_subject &&
4259                  NLBLOCK->nltype == NLTYPE_FIXED &&
4260                  NLBLOCK->nllen == 2 &&
4261                  *eptr == NLBLOCK->nl[0])
4262                {
4263                md->hitend = TRUE;
4264                if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
4265                }
4266            eptr++;            eptr++;
4267            ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);            ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
4268            }            }
# Line 4468  for (;;) Line 4547  for (;;)
4547              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4548              }              }
4549            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
4550              if (md->partial != 0 &&
4551                  eptr + 1 >= md->end_subject &&
4552                  NLBLOCK->nltype == NLTYPE_FIXED &&
4553                  NLBLOCK->nllen == 2 &&
4554                  *eptr == NLBLOCK->nl[0])
4555                {
4556                md->hitend = TRUE;
4557                if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
4558                }
4559            eptr++;            eptr++;
4560            }            }
4561          break;          break;
# Line 4948  for (;;) Line 5036  for (;;)
5036              if (UCD_CATEGORY(c) != ucp_M) break;              if (UCD_CATEGORY(c) != ucp_M) break;
5037              eptr += len;              eptr += len;
5038              }              }
5039              CHECK_PARTIAL();
5040            }            }
5041          }          }
5042        else        else
# Line 4971  for (;;) Line 5060  for (;;)
5060            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
5061            switch(ctype)            switch(ctype)
5062              {              {
5063              case OP_ANY:        /* This is the non-NL case */              case OP_ANY:               /* This is the non-NL case */
5064                if (md->partial != 0 &&    /* Take care with CRLF partial */
5065                    eptr >= md->end_subject &&
5066                    NLBLOCK->nltype == NLTYPE_FIXED &&
5067                    NLBLOCK->nllen == 2 &&
5068                    c == NLBLOCK->nl[0])
5069                  {
5070                  md->hitend = TRUE;
5071                  if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
5072                  }
5073                break;
5074    
5075              case OP_ALLANY:              case OP_ALLANY:
5076              case OP_ANYBYTE:              case OP_ANYBYTE:
5077              break;              break;
# Line 5134  for (;;) Line 5234  for (;;)
5234            c = *eptr++;            c = *eptr++;
5235            switch(ctype)            switch(ctype)
5236              {              {
5237              case OP_ANY:     /* This is the non-NL case */              case OP_ANY:               /* This is the non-NL case */
5238                if (md->partial != 0 &&    /* Take care with CRLF partial */
5239                    eptr >= md->end_subject &&
5240                    NLBLOCK->nltype == NLTYPE_FIXED &&
5241                    NLBLOCK->nllen == 2 &&
5242                    c == NLBLOCK->nl[0])
5243                  {
5244                  md->hitend = TRUE;
5245                  if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
5246                  }
5247                break;
5248    
5249              case OP_ALLANY:              case OP_ALLANY:
5250              case OP_ANYBYTE:              case OP_ANYBYTE:
5251              break;              break;
# Line 5491  for (;;) Line 5602  for (;;)
5602              if (UCD_CATEGORY(c) != ucp_M) break;              if (UCD_CATEGORY(c) != ucp_M) break;
5603              eptr += len;              eptr += len;
5604              }              }
5605              CHECK_PARTIAL();
5606            }            }
5607    
5608          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
# Line 5534  for (;;) Line 5646  for (;;)
5646                  break;                  break;
5647                  }                  }
5648                if (IS_NEWLINE(eptr)) break;                if (IS_NEWLINE(eptr)) break;
5649                  if (md->partial != 0 &&    /* Take care with CRLF partial */
5650                      eptr + 1 >= md->end_subject &&
5651                      NLBLOCK->nltype == NLTYPE_FIXED &&
5652                      NLBLOCK->nllen == 2 &&
5653                      *eptr == NLBLOCK->nl[0])
5654                    {
5655                    md->hitend = TRUE;
5656                    if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
5657                    }
5658                eptr++;                eptr++;
5659                ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);                ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
5660                }                }
# Line 5551  for (;;) Line 5672  for (;;)
5672                  break;                  break;
5673                  }                  }
5674                if (IS_NEWLINE(eptr)) break;                if (IS_NEWLINE(eptr)) break;
5675                  if (md->partial != 0 &&    /* Take care with CRLF partial */
5676                      eptr + 1 >= md->end_subject &&
5677                      NLBLOCK->nltype == NLTYPE_FIXED &&
5678                      NLBLOCK->nllen == 2 &&
5679                      *eptr == NLBLOCK->nl[0])
5680                    {
5681                    md->hitend = TRUE;
5682                    if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
5683                    }
5684                eptr++;                eptr++;
5685                ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);                ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
5686                }                }
# Line 5815  for (;;) Line 5945  for (;;)
5945                break;                break;
5946                }                }
5947              if (IS_NEWLINE(eptr)) break;              if (IS_NEWLINE(eptr)) break;
5948                if (md->partial != 0 &&    /* Take care with CRLF partial */
5949                    eptr + 1 >= md->end_subject &&
5950                    NLBLOCK->nltype == NLTYPE_FIXED &&
5951                    NLBLOCK->nllen == 2 &&
5952                    *eptr == NLBLOCK->nl[0])
5953                  {
5954                  md->hitend = TRUE;
5955                  if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
5956                  }
5957              eptr++;              eptr++;
5958              }              }
5959            break;            break;
# Line 6145  Undefine all the macros that were define Line 6284  Undefine all the macros that were define
6284  ***************************************************************************/  ***************************************************************************/
6285    
6286    
6287    #ifdef NO_RECURSE
6288    /*************************************************
6289    *          Release allocated heap frames         *
6290    *************************************************/
6291    
6292    /* This function releases all the allocated frames. The base frame is on the
6293    machine stack, and so must not be freed.
6294    
6295    Argument: the address of the base frame
6296    Returns:  nothing
6297    */
6298    
6299    static void
6300    release_match_heapframes (heapframe *frame_base)
6301    {
6302    heapframe *nextframe = frame_base->Xnextframe;
6303    while (nextframe != NULL)
6304      {
6305      heapframe *oldframe = nextframe;
6306      nextframe = nextframe->Xnextframe;
6307      (PUBL(stack_free))(oldframe);
6308      }
6309    }
6310    #endif
6311    
6312    
6313  /*************************************************  /*************************************************
6314  *         Execute a Regular Expression           *  *         Execute a Regular Expression           *
# Line 6207  PCRE_PUCHAR req_char_ptr = start_match - Line 6371  PCRE_PUCHAR req_char_ptr = start_match -
6371  const pcre_study_data *study;  const pcre_study_data *study;
6372  const REAL_PCRE *re = (const REAL_PCRE *)argument_re;  const REAL_PCRE *re = (const REAL_PCRE *)argument_re;
6373    
6374  /* Check for the special magic call that measures the size of the stack used  #ifdef NO_RECURSE
6375  per recursive call of match(). */  heapframe frame_zero;
6376    frame_zero.Xprevframe = NULL;            /* Marks the top level */
6377    frame_zero.Xnextframe = NULL;            /* None are allocated yet */
6378    md->match_frames_base = &frame_zero;
6379    #endif
6380    
6381    /* Check for the special magic call that measures the size of the stack used
6382    per recursive call of match(). Without the funny casting for sizeof, a Windows
6383    compiler gave this error: "unary minus operator applied to unsigned type,
6384    result still unsigned". Hopefully the cast fixes that. */
6385    
6386  if (re == NULL && extra_data == NULL && subject == NULL && length == -1)  if (re == NULL && extra_data == NULL && subject == NULL && length == -999 &&
6387        start_offset == -999)
6388  #ifdef NO_RECURSE  #ifdef NO_RECURSE
6389    return -sizeof(heapframe);    return -((int)sizeof(heapframe));
6390  #else  #else
6391    return match(NULL, NULL, NULL, 0, NULL, NULL, 0);    return match(NULL, NULL, NULL, 0, NULL, NULL, 0);
6392  #endif  #endif
6393    
6394  /* Plausibility checks */  /* Plausibility checks */
6395    
6396  if ((options & ~PUBLIC_EXEC_OPTIONS) != 0) return PCRE_ERROR_BADOPTION;  if ((options & ~PUBLIC_EXEC_OPTIONS) != 0) return PCRE_ERROR_BADOPTION;
6397  if (re == NULL || subject == NULL || (offsets == NULL && offsetcount > 0))  if (re == NULL || subject == NULL || (offsets == NULL && offsetcount > 0))
6398    return PCRE_ERROR_NULL;    return PCRE_ERROR_NULL;
6399  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;
6400  if (start_offset < 0 || start_offset > length) return PCRE_ERROR_BADOFFSET;  if (start_offset < 0 || start_offset > length) return PCRE_ERROR_BADOFFSET;
# Line 6279  if (utf && (options & PCRE_NO_UTF8_CHECK Line 6453  if (utf && (options & PCRE_NO_UTF8_CHECK
6453  /* If the pattern was successfully studied with JIT support, run the JIT  /* If the pattern was successfully studied with JIT support, run the JIT
6454  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
6455  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
6456  an unsupported flag is set. In particular, JIT does not support partial  an unsupported flag is set. */
 matching. */  
6457    
6458  #ifdef SUPPORT_JIT  #ifdef SUPPORT_JIT
6459  if (extra_data != NULL  if (extra_data != NULL
6460      && (extra_data->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0      && (extra_data->flags & (PCRE_EXTRA_EXECUTABLE_JIT |
6461                                 PCRE_EXTRA_TABLES)) == PCRE_EXTRA_EXECUTABLE_JIT
6462      && extra_data->executable_jit != NULL      && extra_data->executable_jit != NULL
     && (extra_data->flags & PCRE_EXTRA_TABLES) == 0  
6463      && (options & ~(PCRE_NO_UTF8_CHECK | PCRE_NOTBOL | PCRE_NOTEOL |      && (options & ~(PCRE_NO_UTF8_CHECK | PCRE_NOTBOL | PCRE_NOTEOL |
6464                      PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART)) == 0)                      PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART |
6465    return PRIV(jit_exec)(re, extra_data->executable_jit,                      PCRE_PARTIAL_SOFT | PCRE_PARTIAL_HARD)) == 0)
6466      {
6467      rc = PRIV(jit_exec)(re, extra_data->executable_jit,
6468      (const pcre_uchar *)subject, length, start_offset, options,      (const pcre_uchar *)subject, length, start_offset, options,
6469      ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0)      ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0)
6470      ? MATCH_LIMIT : extra_data->match_limit, offsets, offsetcount);      ? MATCH_LIMIT : extra_data->match_limit, offsets, offsetcount,
6471        ((extra_data->flags & PCRE_EXTRA_MARK) != 0) ? extra_data->mark : NULL);
6472    
6473      /* PCRE_ERROR_NULL means that the selected normal or partial matching
6474      mode is not compiled. In this case we simply fallback to interpreter. */
6475    
6476      if (rc != PCRE_ERROR_NULL) return rc;
6477      }
6478  #endif  #endif
6479    
6480  /* 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 6495  if (!anchored) Line 6677  if (!anchored)
6677    if ((re->flags & PCRE_FIRSTSET) != 0)    if ((re->flags & PCRE_FIRSTSET) != 0)
6678      {      {
6679      has_first_char = TRUE;      has_first_char = TRUE;
6680      first_char = first_char2 = re->first_char;      first_char = first_char2 = (pcre_uchar)(re->first_char);
6681      if ((re->flags & PCRE_FCH_CASELESS) != 0)      if ((re->flags & PCRE_FCH_CASELESS) != 0)
6682        {        {
6683        first_char2 = TABLE_GET(first_char, md->fcc, first_char);        first_char2 = TABLE_GET(first_char, md->fcc, first_char);
# Line 6517  character" set. */ Line 6699  character" set. */
6699  if ((re->flags & PCRE_REQCHSET) != 0)  if ((re->flags & PCRE_REQCHSET) != 0)
6700    {    {
6701    has_req_char = TRUE;    has_req_char = TRUE;
6702    req_char = req_char2 = re->req_char;    req_char = req_char2 = (pcre_uchar)(re->req_char);
6703    if ((re->flags & PCRE_RCH_CASELESS) != 0)    if ((re->flags & PCRE_RCH_CASELESS) != 0)
6704      {      {
6705      req_char2 = TABLE_GET(req_char, md->fcc, req_char);      req_char2 = TABLE_GET(req_char, md->fcc, req_char);
# Line 6907  if (rc == MATCH_MATCH || rc == MATCH_ACC Line 7089  if (rc == MATCH_MATCH || rc == MATCH_ACC
7089    if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_MARK) != 0)    if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_MARK) != 0)
7090      *(extra_data->mark) = (pcre_uchar *)md->mark;      *(extra_data->mark) = (pcre_uchar *)md->mark;
7091    DPRINTF((">>>> returning %d\n", rc));    DPRINTF((">>>> returning %d\n", rc));
7092    #ifdef NO_RECURSE
7093      release_match_heapframes(&frame_zero);
7094    #endif
7095    return rc;    return rc;
7096    }    }
7097    
# Line 6924  if (using_temporary_offsets) Line 7109  if (using_temporary_offsets)
7109  if (rc != MATCH_NOMATCH && rc != PCRE_ERROR_PARTIAL)  if (rc != MATCH_NOMATCH && rc != PCRE_ERROR_PARTIAL)
7110    {    {
7111    DPRINTF((">>>> error: returning %d\n", rc));    DPRINTF((">>>> error: returning %d\n", rc));
7112    #ifdef NO_RECURSE
7113      release_match_heapframes(&frame_zero);
7114    #endif
7115    return rc;    return rc;
7116    }    }
7117    
# Line 6953  else Line 7141  else
7141    
7142  if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_MARK) != 0)  if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_MARK) != 0)
7143    *(extra_data->mark) = (pcre_uchar *)md->nomatch_mark;    *(extra_data->mark) = (pcre_uchar *)md->nomatch_mark;
7144    #ifdef NO_RECURSE
7145      release_match_heapframes(&frame_zero);
7146    #endif
7147  return rc;  return rc;
7148  }  }
7149    

Legend:
Removed from v.895  
changed lines
  Added in v.934

  ViewVC Help
Powered by ViewVC 1.1.5