/[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 427 by ph10, Fri Aug 28 09:55:54 2009 UTC revision 500 by ph10, Sat Mar 6 19:00:29 2010 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2009 University of Cambridge             Copyright (c) 1997-2010 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 89  static const char rep_max[] = { 0, 0, 0, Line 89  static const char rep_max[] = { 0, 0, 0,
89    
90    
91    
92  #ifdef DEBUG  #ifdef PCRE_DEBUG
93  /*************************************************  /*************************************************
94  *        Debugging function to print chars       *  *        Debugging function to print chars       *
95  *************************************************/  *************************************************/
# Line 141  match_ref(int offset, register USPTR ept Line 141  match_ref(int offset, register USPTR ept
141  {  {
142  USPTR p = md->start_subject + md->offset_vector[offset];  USPTR p = md->start_subject + md->offset_vector[offset];
143    
144  #ifdef DEBUG  #ifdef PCRE_DEBUG
145  if (eptr >= md->end_subject)  if (eptr >= md->end_subject)
146    printf("matching subject <null>");    printf("matching subject <null>");
147  else  else
# Line 254  actuall used in this definition. */ Line 254  actuall used in this definition. */
254  #ifndef NO_RECURSE  #ifndef NO_RECURSE
255  #define REGISTER register  #define REGISTER register
256    
257  #ifdef DEBUG  #ifdef PCRE_DEBUG
258  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
259    { \    { \
260    printf("match() called in line %d\n", __LINE__); \    printf("match() called in line %d\n", __LINE__); \
# Line 408  immediately. The second one is used when Line 408  immediately. The second one is used when
408  the subject. */  the subject. */
409    
410  #define CHECK_PARTIAL()\  #define CHECK_PARTIAL()\
411    if (md->partial && eptr >= md->end_subject && eptr > mstart)\    if (md->partial != 0 && eptr >= md->end_subject && eptr > mstart)\
412      {\      {\
413      md->hitend = TRUE;\      md->hitend = TRUE;\
414      if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);\      if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);\
415      }      }
416    
417  #define SCHECK_PARTIAL()\  #define SCHECK_PARTIAL()\
418    if (md->partial && eptr > mstart)\    if (md->partial != 0 && eptr > mstart)\
419      {\      {\
420      md->hitend = TRUE;\      md->hitend = TRUE;\
     md->hitend = TRUE;\  
421      if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);\      if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);\
422      }      }
423    
# Line 623  TAIL_RECURSE: Line 622  TAIL_RECURSE:
622  /* OK, now we can get on with the real code of the function. Recursive calls  /* OK, now we can get on with the real code of the function. Recursive calls
623  are specified by the macro RMATCH and RRETURN is used to return. When  are specified by the macro RMATCH and RRETURN is used to return. When
624  NO_RECURSE is *not* defined, these just turn into a recursive call to match()  NO_RECURSE is *not* defined, these just turn into a recursive call to match()
625  and a "return", respectively (possibly with some debugging if DEBUG is  and a "return", respectively (possibly with some debugging if PCRE_DEBUG is
626  defined). However, RMATCH isn't like a function call because it's quite a  defined). However, RMATCH isn't like a function call because it's quite a
627  complicated macro. It has to be used in one particular way. This shouldn't,  complicated macro. It has to be used in one particular way. This shouldn't,
628  however, impact performance when true recursion is being used. */  however, impact performance when true recursion is being used. */
# Line 665  for (;;) Line 664  for (;;)
664    minimize = possessive = FALSE;    minimize = possessive = FALSE;
665    op = *ecode;    op = *ecode;
666    
   /* For partial matching, remember if we ever hit the end of the subject after  
   matching at least one subject character. This code is now wrapped in a macro  
   because it appears several times below. */  
   
   CHECK_PARTIAL();  
   
667    switch(op)    switch(op)
668      {      {
669      case OP_FAIL:      case OP_FAIL:
# Line 720  for (;;) Line 713  for (;;)
713      number = GET2(ecode, 1+LINK_SIZE);      number = GET2(ecode, 1+LINK_SIZE);
714      offset = number << 1;      offset = number << 1;
715    
716  #ifdef DEBUG  #ifdef PCRE_DEBUG
717      printf("start bracket %d\n", number);      printf("start bracket %d\n", number);
718      printf("subject=");      printf("subject=");
719      pchars(eptr, 16, TRUE, md);      pchars(eptr, 16, TRUE, md);
# Line 846  for (;;) Line 839  for (;;)
839    
840      /* Now see what the actual condition is */      /* Now see what the actual condition is */
841    
842      if (condcode == OP_RREF)         /* Recursion test */      if (condcode == OP_RREF || condcode == OP_NRREF)    /* Recursion test */
843        {        {
844        offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/        if (md->recursive == NULL)                /* Not recursing => FALSE */
845        condition = md->recursive != NULL &&          {
846          (offset == RREF_ANY || offset == md->recursive->group_num);          condition = FALSE;
847        ecode += condition? 3 : GET(ecode, 1);          ecode += GET(ecode, 1);
848            }
849          else
850            {
851            int recno = GET2(ecode, LINK_SIZE + 2);   /* Recursion group number*/
852            condition =  (recno == RREF_ANY || recno == md->recursive->group_num);
853    
854            /* If the test is for recursion into a specific subpattern, and it is
855            false, but the test was set up by name, scan the table to see if the
856            name refers to any other numbers, and test them. The condition is true
857            if any one is set. */
858    
859            if (!condition && condcode == OP_NRREF && recno != RREF_ANY)
860              {
861              uschar *slotA = md->name_table;
862              for (i = 0; i < md->name_count; i++)
863                {
864                if (GET2(slotA, 0) == recno) break;
865                slotA += md->name_entry_size;
866                }
867    
868              /* Found a name for the number - there can be only one; duplicate
869              names for different numbers are allowed, but not vice versa. First
870              scan down for duplicates. */
871    
872              if (i < md->name_count)
873                {
874                uschar *slotB = slotA;
875                while (slotB > md->name_table)
876                  {
877                  slotB -= md->name_entry_size;
878                  if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
879                    {
880                    condition = GET2(slotB, 0) == md->recursive->group_num;
881                    if (condition) break;
882                    }
883                  else break;
884                  }
885    
886                /* Scan up for duplicates */
887    
888                if (!condition)
889                  {
890                  slotB = slotA;
891                  for (i++; i < md->name_count; i++)
892                    {
893                    slotB += md->name_entry_size;
894                    if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
895                      {
896                      condition = GET2(slotB, 0) == md->recursive->group_num;
897                      if (condition) break;
898                      }
899                    else break;
900                    }
901                  }
902                }
903              }
904    
905            /* Chose branch according to the condition */
906    
907            ecode += condition? 3 : GET(ecode, 1);
908            }
909        }        }
910    
911      else if (condcode == OP_CREF)    /* Group used test */      else if (condcode == OP_CREF || condcode == OP_NCREF)  /* Group used test */
912        {        {
913        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */
914        condition = offset < offset_top && md->offset_vector[offset] >= 0;        condition = offset < offset_top && md->offset_vector[offset] >= 0;
915    
916          /* If the numbered capture is unset, but the reference was by name,
917          scan the table to see if the name refers to any other numbers, and test
918          them. The condition is true if any one is set. This is tediously similar
919          to the code above, but not close enough to try to amalgamate. */
920    
921          if (!condition && condcode == OP_NCREF)
922            {
923            int refno = offset >> 1;
924            uschar *slotA = md->name_table;
925    
926            for (i = 0; i < md->name_count; i++)
927              {
928              if (GET2(slotA, 0) == refno) break;
929              slotA += md->name_entry_size;
930              }
931    
932            /* Found a name for the number - there can be only one; duplicate names
933            for different numbers are allowed, but not vice versa. First scan down
934            for duplicates. */
935    
936            if (i < md->name_count)
937              {
938              uschar *slotB = slotA;
939              while (slotB > md->name_table)
940                {
941                slotB -= md->name_entry_size;
942                if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
943                  {
944                  offset = GET2(slotB, 0) << 1;
945                  condition = offset < offset_top &&
946                    md->offset_vector[offset] >= 0;
947                  if (condition) break;
948                  }
949                else break;
950                }
951    
952              /* Scan up for duplicates */
953    
954              if (!condition)
955                {
956                slotB = slotA;
957                for (i++; i < md->name_count; i++)
958                  {
959                  slotB += md->name_entry_size;
960                  if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
961                    {
962                    offset = GET2(slotB, 0) << 1;
963                    condition = offset < offset_top &&
964                      md->offset_vector[offset] >= 0;
965                    if (condition) break;
966                    }
967                  else break;
968                  }
969                }
970              }
971            }
972    
973          /* Chose branch according to the condition */
974    
975        ecode += condition? 3 : GET(ecode, 1);        ecode += condition? 3 : GET(ecode, 1);
976        }        }
977    
# Line 918  for (;;) Line 1032  for (;;)
1032      break;      break;
1033    
1034    
1035        /* Before OP_ACCEPT there may be any number of OP_CLOSE opcodes,
1036        to close any currently open capturing brackets. */
1037    
1038        case OP_CLOSE:
1039        number = GET2(ecode, 1);
1040        offset = number << 1;
1041    
1042    #ifdef PCRE_DEBUG
1043          printf("end bracket %d at *ACCEPT", number);
1044          printf("\n");
1045    #endif
1046    
1047        md->capture_last = number;
1048        if (offset >= md->offset_max) md->offset_overflow = TRUE; else
1049          {
1050          md->offset_vector[offset] =
1051            md->offset_vector[md->offset_end - number];
1052          md->offset_vector[offset+1] = eptr - md->start_subject;
1053          if (offset_top <= offset) offset_top = offset + 2;
1054          }
1055        ecode += 3;
1056        break;
1057    
1058    
1059      /* End of the pattern, either real or forced. If we are in a top-level      /* End of the pattern, either real or forced. If we are in a top-level
1060      recursion, we should restore the offsets appropriately and continue from      recursion, we should restore the offsets appropriately and continue from
1061      after the call. */      after the call. */
# Line 931  for (;;) Line 1069  for (;;)
1069        md->recursive = rec->prevrec;        md->recursive = rec->prevrec;
1070        memmove(md->offset_vector, rec->offset_save,        memmove(md->offset_vector, rec->offset_save,
1071          rec->saved_max * sizeof(int));          rec->saved_max * sizeof(int));
1072        mstart = rec->save_start;        offset_top = rec->save_offset_top;
1073        ims = original_ims;        ims = original_ims;
1074        ecode = rec->after_call;        ecode = rec->after_call;
1075        break;        break;
1076        }        }
1077    
1078      /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty      /* Otherwise, if we have matched an empty string, fail if PCRE_NOTEMPTY is
1079      string - backtracking will then try other alternatives, if any. */      set, or if PCRE_NOTEMPTY_ATSTART is set and we have matched at the start of
1080        the subject. In both cases, backtracking will then try other alternatives,
1081        if any. */
1082    
1083        if (eptr == mstart &&
1084            (md->notempty ||
1085              (md->notempty_atstart &&
1086                mstart == md->start_subject + md->start_offset)))
1087          RRETURN(MATCH_NOMATCH);
1088    
1089        /* Otherwise, we have a match. */
1090    
     if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH);  
1091      md->end_match_ptr = eptr;           /* Record where we ended */      md->end_match_ptr = eptr;           /* Record where we ended */
1092      md->end_offset_top = offset_top;    /* and how many extracts were taken */      md->end_offset_top = offset_top;    /* and how many extracts were taken */
1093      md->start_match_ptr = mstart;       /* and the start (\K can modify) */      md->start_match_ptr = mstart;       /* and the start (\K can modify) */
# Line 966  for (;;) Line 1113  for (;;)
1113        {        {
1114        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
1115          RM4);          RM4);
1116        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH)
1117            {
1118            mstart = md->start_match_ptr;   /* In case \K reset it */
1119            break;
1120            }
1121        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1122        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1123        }        }
# Line 985  for (;;) Line 1136  for (;;)
1136      offset_top = md->end_offset_top;      offset_top = md->end_offset_top;
1137      continue;      continue;
1138    
1139      /* Negative assertion: all branches must fail to match */      /* Negative assertion: all branches must fail to match. Encountering SKIP,
1140        PRUNE, or COMMIT means we must assume failure without checking subsequent
1141        branches. */
1142    
1143      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1144      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
# Line 994  for (;;) Line 1147  for (;;)
1147        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
1148          RM5);          RM5);
1149        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);
1150          if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)
1151            {
1152            do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1153            break;
1154            }
1155        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1156        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1157        }        }
# Line 1031  for (;;) Line 1189  for (;;)
1189        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
1190        }        }
1191    
1192      /* Skip to next op code */      /* Save the earliest consulted character, then skip to next op code */
1193    
1194        if (eptr < md->start_used_ptr) md->start_used_ptr = eptr;
1195      ecode += 1 + LINK_SIZE;      ecode += 1 + LINK_SIZE;
1196      break;      break;
1197    
# Line 1111  for (;;) Line 1270  for (;;)
1270    
1271        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
1272              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1273        new_recursive.save_start = mstart;        new_recursive.save_offset_top = offset_top;
       mstart = eptr;  
1274    
1275        /* OK, now we can do the recursion. For each top-level alternative we        /* OK, now we can do the recursion. For each top-level alternative we
1276        restore the offset and recursion data. */        restore the offset and recursion data. */
# Line 1159  for (;;) Line 1317  for (;;)
1317      a move back into the brackets. Friedl calls these "atomic" subpatterns.      a move back into the brackets. Friedl calls these "atomic" subpatterns.
1318      Check the alternative branches in turn - the matching won't pass the KET      Check the alternative branches in turn - the matching won't pass the KET
1319      for this kind of subpattern. If any one branch matches, we carry on as at      for this kind of subpattern. If any one branch matches, we carry on as at
1320      the end of a normal bracket, leaving the subject pointer. */      the end of a normal bracket, leaving the subject pointer, but resetting
1321        the start-of-match value in case it was changed by \K. */
1322    
1323      case OP_ONCE:      case OP_ONCE:
1324      prev = ecode;      prev = ecode;
# Line 1168  for (;;) Line 1327  for (;;)
1327      do      do
1328        {        {
1329        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);
1330        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH)
1331            {
1332            mstart = md->start_match_ptr;
1333            break;
1334            }
1335        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1336        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1337        }        }
# Line 1287  for (;;) Line 1450  for (;;)
1450        }        }
1451      else saved_eptr = NULL;      else saved_eptr = NULL;
1452    
1453      /* If we are at the end of an assertion group, stop matching and return      /* If we are at the end of an assertion group or an atomic group, stop
1454      MATCH_MATCH, but record the current high water mark for use by positive      matching and return MATCH_MATCH, but record the current high water mark for
1455      assertions. Do this also for the "once" (atomic) groups. */      use by positive assertions. We also need to record the match start in case
1456        it was changed by \K. */
1457    
1458      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||
1459          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||
# Line 1297  for (;;) Line 1461  for (;;)
1461        {        {
1462        md->end_match_ptr = eptr;      /* For ONCE */        md->end_match_ptr = eptr;      /* For ONCE */
1463        md->end_offset_top = offset_top;        md->end_offset_top = offset_top;
1464          md->start_match_ptr = mstart;
1465        RRETURN(MATCH_MATCH);        RRETURN(MATCH_MATCH);
1466        }        }
1467    
# Line 1311  for (;;) Line 1476  for (;;)
1476        number = GET2(prev, 1+LINK_SIZE);        number = GET2(prev, 1+LINK_SIZE);
1477        offset = number << 1;        offset = number << 1;
1478    
1479  #ifdef DEBUG  #ifdef PCRE_DEBUG
1480        printf("end bracket %d", number);        printf("end bracket %d", number);
1481        printf("\n");        printf("\n");
1482  #endif  #endif
# Line 1333  for (;;) Line 1498  for (;;)
1498          recursion_info *rec = md->recursive;          recursion_info *rec = md->recursive;
1499          DPRINTF(("Recursion (%d) succeeded - continuing\n", number));          DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
1500          md->recursive = rec->prevrec;          md->recursive = rec->prevrec;
         mstart = rec->save_start;  
1501          memcpy(md->offset_vector, rec->offset_save,          memcpy(md->offset_vector, rec->offset_save,
1502            rec->saved_max * sizeof(int));            rec->saved_max * sizeof(int));
1503            offset_top = rec->save_offset_top;
1504          ecode = rec->after_call;          ecode = rec->after_call;
1505          ims = original_ims;          ims = original_ims;
1506          break;          break;
# Line 1475  for (;;) Line 1640  for (;;)
1640    
1641        /* Find out if the previous and current characters are "word" characters.        /* Find out if the previous and current characters are "word" characters.
1642        It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to        It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to
1643        be "non-word" characters. */        be "non-word" characters. Remember the earliest consulted character for
1644          partial matching. */
1645    
1646  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1647        if (utf8)        if (utf8)
# Line 1484  for (;;) Line 1650  for (;;)
1650            {            {
1651            USPTR lastptr = eptr - 1;            USPTR lastptr = eptr - 1;
1652            while((*lastptr & 0xc0) == 0x80) lastptr--;            while((*lastptr & 0xc0) == 0x80) lastptr--;
1653              if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr;
1654            GETCHAR(c, lastptr);            GETCHAR(c, lastptr);
1655            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
1656            }            }
1657          if (eptr >= md->end_subject) cur_is_word = FALSE; else          if (eptr >= md->end_subject)
1658              {
1659              SCHECK_PARTIAL();
1660              cur_is_word = FALSE;
1661              }
1662            else
1663            {            {
1664            GETCHAR(c, eptr);            GETCHAR(c, eptr);
1665            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
# Line 1496  for (;;) Line 1668  for (;;)
1668        else        else
1669  #endif  #endif
1670    
1671        /* More streamlined when not in UTF-8 mode */        /* Not in UTF-8 mode */
1672    
1673          {          {
1674          prev_is_word = (eptr != md->start_subject) &&          if (eptr == md->start_subject) prev_is_word = FALSE; else
1675            ((md->ctypes[eptr[-1]] & ctype_word) != 0);            {
1676          cur_is_word = (eptr < md->end_subject) &&            if (eptr <= md->start_used_ptr) md->start_used_ptr = eptr - 1;
1677            ((md->ctypes[*eptr] & ctype_word) != 0);            prev_is_word = ((md->ctypes[eptr[-1]] & ctype_word) != 0);
1678              }
1679            if (eptr >= md->end_subject)
1680              {
1681              SCHECK_PARTIAL();
1682              cur_is_word = FALSE;
1683              }
1684            else cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0);
1685          }          }
1686    
1687        /* Now see if the situation is what we want */        /* Now see if the situation is what we want */
# Line 1520  for (;;) Line 1699  for (;;)
1699      /* Fall through */      /* Fall through */
1700    
1701      case OP_ALLANY:      case OP_ALLANY:
1702      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject)
1703          {
1704          SCHECK_PARTIAL();
1705          RRETURN(MATCH_NOMATCH);
1706          }
1707      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
1708      ecode++;      ecode++;
1709      break;      break;
# Line 1529  for (;;) Line 1712  for (;;)
1712      any byte, even newline, independent of the setting of PCRE_DOTALL. */      any byte, even newline, independent of the setting of PCRE_DOTALL. */
1713    
1714      case OP_ANYBYTE:      case OP_ANYBYTE:
1715      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject)
1716          {
1717          SCHECK_PARTIAL();
1718          RRETURN(MATCH_NOMATCH);
1719          }
1720      ecode++;      ecode++;
1721      break;      break;
1722    
1723      case OP_NOT_DIGIT:      case OP_NOT_DIGIT:
1724      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1725          {
1726          SCHECK_PARTIAL();
1727          RRETURN(MATCH_NOMATCH);
1728          }
1729      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1730      if (      if (
1731  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1547  for (;;) Line 1738  for (;;)
1738      break;      break;
1739    
1740      case OP_DIGIT:      case OP_DIGIT:
1741      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1742          {
1743          SCHECK_PARTIAL();
1744          RRETURN(MATCH_NOMATCH);
1745          }
1746      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1747      if (      if (
1748  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1560  for (;;) Line 1755  for (;;)
1755      break;      break;
1756    
1757      case OP_NOT_WHITESPACE:      case OP_NOT_WHITESPACE:
1758      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1759          {
1760          SCHECK_PARTIAL();
1761          RRETURN(MATCH_NOMATCH);
1762          }
1763      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1764      if (      if (
1765  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1573  for (;;) Line 1772  for (;;)
1772      break;      break;
1773    
1774      case OP_WHITESPACE:      case OP_WHITESPACE:
1775      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1776          {
1777          SCHECK_PARTIAL();
1778          RRETURN(MATCH_NOMATCH);
1779          }
1780      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1781      if (      if (
1782  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1586  for (;;) Line 1789  for (;;)
1789      break;      break;
1790    
1791      case OP_NOT_WORDCHAR:      case OP_NOT_WORDCHAR:
1792      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1793          {
1794          SCHECK_PARTIAL();
1795          RRETURN(MATCH_NOMATCH);
1796          }
1797      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1798      if (      if (
1799  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1599  for (;;) Line 1806  for (;;)
1806      break;      break;
1807    
1808      case OP_WORDCHAR:      case OP_WORDCHAR:
1809      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1810          {
1811          SCHECK_PARTIAL();
1812          RRETURN(MATCH_NOMATCH);
1813          }
1814      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1815      if (      if (
1816  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1612  for (;;) Line 1823  for (;;)
1823      break;      break;
1824    
1825      case OP_ANYNL:      case OP_ANYNL:
1826      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1827          {
1828          SCHECK_PARTIAL();
1829          RRETURN(MATCH_NOMATCH);
1830          }
1831      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1832      switch(c)      switch(c)
1833        {        {
# Line 1636  for (;;) Line 1851  for (;;)
1851      break;      break;
1852    
1853      case OP_NOT_HSPACE:      case OP_NOT_HSPACE:
1854      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1855          {
1856          SCHECK_PARTIAL();
1857          RRETURN(MATCH_NOMATCH);
1858          }
1859      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1860      switch(c)      switch(c)
1861        {        {
# Line 1666  for (;;) Line 1885  for (;;)
1885      break;      break;
1886    
1887      case OP_HSPACE:      case OP_HSPACE:
1888      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1889          {
1890          SCHECK_PARTIAL();
1891          RRETURN(MATCH_NOMATCH);
1892          }
1893      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1894      switch(c)      switch(c)
1895        {        {
# Line 1696  for (;;) Line 1919  for (;;)
1919      break;      break;
1920    
1921      case OP_NOT_VSPACE:      case OP_NOT_VSPACE:
1922      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1923          {
1924          SCHECK_PARTIAL();
1925          RRETURN(MATCH_NOMATCH);
1926          }
1927      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1928      switch(c)      switch(c)
1929        {        {
# Line 1714  for (;;) Line 1941  for (;;)
1941      break;      break;
1942    
1943      case OP_VSPACE:      case OP_VSPACE:
1944      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1945          {
1946          SCHECK_PARTIAL();
1947          RRETURN(MATCH_NOMATCH);
1948          }
1949      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1950      switch(c)      switch(c)
1951        {        {
# Line 1737  for (;;) Line 1968  for (;;)
1968    
1969      case OP_PROP:      case OP_PROP:
1970      case OP_NOTPROP:      case OP_NOTPROP:
1971      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1972          {
1973          SCHECK_PARTIAL();
1974          RRETURN(MATCH_NOMATCH);
1975          }
1976      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1977        {        {
1978        const ucd_record *prop = GET_UCD(c);        const ucd_record *prop = GET_UCD(c);
# Line 1782  for (;;) Line 2017  for (;;)
2017      is in the binary; otherwise a compile-time error occurs. */      is in the binary; otherwise a compile-time error occurs. */
2018    
2019      case OP_EXTUNI:      case OP_EXTUNI:
2020      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2021          {
2022          SCHECK_PARTIAL();
2023          RRETURN(MATCH_NOMATCH);
2024          }
2025      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2026        {        {
2027        int category = UCD_CATEGORY(c);        int category = UCD_CATEGORY(c);
# Line 1862  for (;;) Line 2101  for (;;)
2101          break;          break;
2102    
2103          default:               /* No repeat follows */          default:               /* No repeat follows */
2104          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
2105              {
2106              CHECK_PARTIAL();
2107              RRETURN(MATCH_NOMATCH);
2108              }
2109          eptr += length;          eptr += length;
2110          continue;              /* With the main loop */          continue;              /* With the main loop */
2111          }          }
# Line 1899  for (;;) Line 2142  for (;;)
2142            {            {
2143            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
2144            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2145            if (fi >= max || !match_ref(offset, eptr, length, md, ims))            if (fi >= max) RRETURN(MATCH_NOMATCH);
2146              if (!match_ref(offset, eptr, length, md, ims))
2147              {              {
2148              CHECK_PARTIAL();              CHECK_PARTIAL();
2149              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
# Line 1916  for (;;) Line 2160  for (;;)
2160          pp = eptr;          pp = eptr;
2161          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2162            {            {
2163            if (!match_ref(offset, eptr, length, md, ims)) break;            if (!match_ref(offset, eptr, length, md, ims))
2164                {
2165                CHECK_PARTIAL();
2166                break;
2167                }
2168            eptr += length;            eptr += length;
2169            }            }
         CHECK_PARTIAL();  
2170          while (eptr >= pp)          while (eptr >= pp)
2171            {            {
2172            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);
# Line 1931  for (;;) Line 2178  for (;;)
2178        }        }
2179      /* Control never gets here */      /* Control never gets here */
2180    
   
   
2181      /* Match a bit-mapped character class, possibly repeatedly. This op code is      /* Match a bit-mapped character class, possibly repeatedly. This op code is
2182      used when all the characters in the class have values in the range 0-255,      used when all the characters in the class have values in the range 0-255,
2183      and either the matching is caseful, or the characters are in the range      and either the matching is caseful, or the characters are in the range
# Line 1989  for (;;) Line 2234  for (;;)
2234            {            {
2235            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
2236              {              {
2237              CHECK_PARTIAL();              SCHECK_PARTIAL();
2238              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2239              }              }
2240            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
# Line 2011  for (;;) Line 2256  for (;;)
2256            {            {
2257            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
2258              {              {
2259              CHECK_PARTIAL();              SCHECK_PARTIAL();
2260              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2261              }              }
2262            c = *eptr++;            c = *eptr++;
# Line 2037  for (;;) Line 2282  for (;;)
2282              {              {
2283              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
2284              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2285              if (fi >= max)              if (fi >= max) RRETURN(MATCH_NOMATCH);
               {  
               CHECK_PARTIAL();  
               RRETURN(MATCH_NOMATCH);  
               }  
2286              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
2287                {                {
2288                SCHECK_PARTIAL();                SCHECK_PARTIAL();
# Line 2066  for (;;) Line 2307  for (;;)
2307              {              {
2308              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
2309              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2310              if (fi >= max)              if (fi >= max) RRETURN(MATCH_NOMATCH);
               {  
               CHECK_PARTIAL();  
               RRETURN(MATCH_NOMATCH);  
               }  
2311              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
2312                {                {
2313                SCHECK_PARTIAL();                SCHECK_PARTIAL();
# Line 2096  for (;;) Line 2333  for (;;)
2333            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2334              {              {
2335              int len = 1;              int len = 1;
2336              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
2337                  {
2338                  SCHECK_PARTIAL();
2339                  break;
2340                  }
2341              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
2342              if (c > 255)              if (c > 255)
2343                {                {
# Line 2108  for (;;) Line 2349  for (;;)
2349                }                }
2350              eptr += len;              eptr += len;
2351              }              }
           CHECK_PARTIAL();  
2352            for (;;)            for (;;)
2353              {              {
2354              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);
# Line 2123  for (;;) Line 2363  for (;;)
2363            {            {
2364            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2365              {              {
2366              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
2367                  {
2368                  SCHECK_PARTIAL();
2369                  break;
2370                  }
2371              c = *eptr;              c = *eptr;
2372              if ((data[c/8] & (1 << (c&7))) == 0) break;              if ((data[c/8] & (1 << (c&7))) == 0) break;
2373              eptr++;              eptr++;
2374              }              }
           CHECK_PARTIAL();  
2375            while (eptr >= pp)            while (eptr >= pp)
2376              {              {
2377              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);
# Line 2209  for (;;) Line 2452  for (;;)
2452            {            {
2453            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
2454            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2455            if (fi >= max)            if (fi >= max) RRETURN(MATCH_NOMATCH);
             {  
             CHECK_PARTIAL();  
             RRETURN(MATCH_NOMATCH);  
             }  
2456            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
2457              {              {
2458              SCHECK_PARTIAL();              SCHECK_PARTIAL();
# Line 2233  for (;;) Line 2472  for (;;)
2472          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2473            {            {
2474            int len = 1;            int len = 1;
2475            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject)
2476                {
2477                SCHECK_PARTIAL();
2478                break;
2479                }
2480            GETCHARLENTEST(c, eptr, len);            GETCHARLENTEST(c, eptr, len);
2481            if (!_pcre_xclass(c, data)) break;            if (!_pcre_xclass(c, data)) break;
2482            eptr += len;            eptr += len;
2483            }            }
         CHECK_PARTIAL();  
2484          for(;;)          for(;;)
2485            {            {
2486            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
# Line 2262  for (;;) Line 2504  for (;;)
2504        length = 1;        length = 1;
2505        ecode++;        ecode++;
2506        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2507        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2508            {
2509            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2510            RRETURN(MATCH_NOMATCH);
2511            }
2512        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);
2513        }        }
2514      else      else
# Line 2270  for (;;) Line 2516  for (;;)
2516    
2517      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2518        {        {
2519        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2520            {
2521            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2522            RRETURN(MATCH_NOMATCH);
2523            }
2524        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);
2525        ecode += 2;        ecode += 2;
2526        }        }
# Line 2286  for (;;) Line 2536  for (;;)
2536        ecode++;        ecode++;
2537        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2538    
2539        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2540            {
2541            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2542            RRETURN(MATCH_NOMATCH);
2543            }
2544    
2545        /* If the pattern character's value is < 128, we have only one byte, and        /* If the pattern character's value is < 128, we have only one byte, and
2546        can use the fast lookup table. */        can use the fast lookup table. */
# Line 2321  for (;;) Line 2575  for (;;)
2575    
2576      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2577        {        {
2578        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2579            {
2580            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2581            RRETURN(MATCH_NOMATCH);
2582            }
2583        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2584        ecode += 2;        ecode += 2;
2585        }        }
# Line 2375  for (;;) Line 2633  for (;;)
2633      case OP_MINQUERY:      case OP_MINQUERY:
2634      c = *ecode++ - OP_STAR;      c = *ecode++ - OP_STAR;
2635      minimize = (c & 1) != 0;      minimize = (c & 1) != 0;
2636    
2637      min = rep_min[c];                 /* Pick up values from tables; */      min = rep_min[c];                 /* Pick up values from tables; */
2638      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2639      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
# Line 2427  for (;;) Line 2686  for (;;)
2686              {              {
2687              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
2688              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2689              if (fi >= max)              if (fi >= max) RRETURN(MATCH_NOMATCH);
               {  
               CHECK_PARTIAL();  
               RRETURN(MATCH_NOMATCH);  
               }  
2690              if (eptr <= md->end_subject - length &&              if (eptr <= md->end_subject - length &&
2691                memcmp(eptr, charptr, length) == 0) eptr += length;                memcmp(eptr, charptr, length) == 0) eptr += length;
2692  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 2460  for (;;) Line 2715  for (;;)
2715                       eptr <= md->end_subject - oclength &&                       eptr <= md->end_subject - oclength &&
2716                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2717  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2718              else break;              else
2719                  {
2720                  CHECK_PARTIAL();
2721                  break;
2722                  }
2723              }              }
2724    
           CHECK_PARTIAL();  
2725            if (possessive) continue;            if (possessive) continue;
2726    
2727            for(;;)            for(;;)
# Line 2524  for (;;) Line 2782  for (;;)
2782            {            {
2783            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
2784            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2785            if (fi >= max)            if (fi >= max) RRETURN(MATCH_NOMATCH);
             {  
             CHECK_PARTIAL();  
             RRETURN(MATCH_NOMATCH);  
             }  
2786            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
2787              {              {
2788              SCHECK_PARTIAL();              SCHECK_PARTIAL();
# Line 2543  for (;;) Line 2797  for (;;)
2797          pp = eptr;          pp = eptr;
2798          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2799            {            {
2800            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;            if (eptr >= md->end_subject)
2801                {
2802                SCHECK_PARTIAL();
2803                break;
2804                }
2805              if (fc != md->lcc[*eptr]) break;
2806            eptr++;            eptr++;
2807            }            }
2808    
         CHECK_PARTIAL();  
2809          if (possessive) continue;          if (possessive) continue;
2810    
2811          while (eptr >= pp)          while (eptr >= pp)
# Line 2574  for (;;) Line 2832  for (;;)
2832            }            }
2833          if (fc != *eptr++) RRETURN(MATCH_NOMATCH);          if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
2834          }          }
2835    
2836        if (min == max) continue;        if (min == max) continue;
2837    
2838        if (minimize)        if (minimize)
2839          {          {
2840          for (fi = min;; fi++)          for (fi = min;; fi++)
2841            {            {
2842            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
2843            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2844            if (fi >= max)            if (fi >= max) RRETURN(MATCH_NOMATCH);
             {  
             CHECK_PARTIAL();  
             RRETURN(MATCH_NOMATCH);  
             }  
2845            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
2846              {              {
2847              SCHECK_PARTIAL();              SCHECK_PARTIAL();
# Line 2600  for (;;) Line 2856  for (;;)
2856          pp = eptr;          pp = eptr;
2857          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2858            {            {
2859            if (eptr >= md->end_subject || fc != *eptr) break;            if (eptr >= md->end_subject)
2860                {
2861                SCHECK_PARTIAL();
2862                break;
2863                }
2864              if (fc != *eptr) break;
2865            eptr++;            eptr++;
2866            }            }
         CHECK_PARTIAL();  
2867          if (possessive) continue;          if (possessive) continue;
2868    
2869          while (eptr >= pp)          while (eptr >= pp)
2870            {            {
2871            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);
# Line 2620  for (;;) Line 2881  for (;;)
2881      checking can be multibyte. */      checking can be multibyte. */
2882    
2883      case OP_NOT:      case OP_NOT:
2884      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2885          {
2886          SCHECK_PARTIAL();
2887          RRETURN(MATCH_NOMATCH);
2888          }
2889      ecode++;      ecode++;
2890      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2891      if ((ims & PCRE_CASELESS) != 0)      if ((ims & PCRE_CASELESS) != 0)
# Line 2763  for (;;) Line 3028  for (;;)
3028              {              {
3029              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
3030              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3031              if (fi >= max)              if (fi >= max) RRETURN(MATCH_NOMATCH);
               {  
               CHECK_PARTIAL();  
               RRETURN(MATCH_NOMATCH);  
               }  
3032              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
3033                {                {
3034                SCHECK_PARTIAL();                SCHECK_PARTIAL();
# Line 2786  for (;;) Line 3047  for (;;)
3047              {              {
3048              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
3049              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3050              if (fi >= max)              if (fi >= max) RRETURN(MATCH_NOMATCH);
               {  
               CHECK_PARTIAL();  
               RRETURN(MATCH_NOMATCH);  
               }  
3051              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
3052                {                {
3053                SCHECK_PARTIAL();                SCHECK_PARTIAL();
# Line 2816  for (;;) Line 3073  for (;;)
3073            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3074              {              {
3075              int len = 1;              int len = 1;
3076              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
3077                  {
3078                  SCHECK_PARTIAL();
3079                  break;
3080                  }
3081              GETCHARLEN(d, eptr, len);              GETCHARLEN(d, eptr, len);
3082              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
3083              if (fc == d) break;              if (fc == d) break;
3084              eptr += len;              eptr += len;
3085              }              }
         CHECK_PARTIAL();  
3086          if (possessive) continue;          if (possessive) continue;
3087          for(;;)          for(;;)
3088              {              {
# Line 2838  for (;;) Line 3098  for (;;)
3098            {            {
3099            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3100              {              {
3101              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;              if (eptr >= md->end_subject)
3102                  {
3103                  SCHECK_PARTIAL();
3104                  break;
3105                  }
3106                if (fc == md->lcc[*eptr]) break;
3107              eptr++;              eptr++;
3108              }              }
           CHECK_PARTIAL();  
3109            if (possessive) continue;            if (possessive) continue;
3110            while (eptr >= pp)            while (eptr >= pp)
3111              {              {
# Line 2904  for (;;) Line 3168  for (;;)
3168              {              {
3169              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
3170              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3171              if (fi >= max)              if (fi >= max) RRETURN(MATCH_NOMATCH);
               {  
               CHECK_PARTIAL();  
               RRETURN(MATCH_NOMATCH);  
               }  
3172              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
3173                {                {
3174                SCHECK_PARTIAL();                SCHECK_PARTIAL();
# Line 2926  for (;;) Line 3186  for (;;)
3186              {              {
3187              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);
3188              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3189              if (fi >= max)              if (fi >= max) RRETURN(MATCH_NOMATCH);
               {  
               CHECK_PARTIAL();  
               RRETURN(MATCH_NOMATCH);  
               }  
3190              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
3191                {                {
3192                SCHECK_PARTIAL();                SCHECK_PARTIAL();
# Line 2956  for (;;) Line 3212  for (;;)
3212            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3213              {              {
3214              int len = 1;              int len = 1;
3215              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
3216                  {
3217                  SCHECK_PARTIAL();
3218                  break;
3219                  }
3220              GETCHARLEN(d, eptr, len);              GETCHARLEN(d, eptr, len);
3221              if (fc == d) break;              if (fc == d) break;
3222              eptr += len;              eptr += len;
3223              }              }
           CHECK_PARTIAL();  
3224            if (possessive) continue;            if (possessive) continue;
3225            for(;;)            for(;;)
3226              {              {
# Line 2977  for (;;) Line 3236  for (;;)
3236            {            {
3237            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3238              {              {
3239              if (eptr >= md->end_subject || fc == *eptr) break;              if (eptr >= md->end_subject)
3240                  {
3241                  SCHECK_PARTIAL();
3242                  break;
3243                  }
3244                if (fc == *eptr) break;
3245              eptr++;              eptr++;
3246              }              }
           CHECK_PARTIAL();  
3247            if (possessive) continue;            if (possessive) continue;
3248            while (eptr >= pp)            while (eptr >= pp)
3249              {              {
# Line 3439  for (;;) Line 3702  for (;;)
3702          case OP_NOT_WORDCHAR:          case OP_NOT_WORDCHAR:
3703          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3704            {            {
3705            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3706               (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0))              {
3707                SCHECK_PARTIAL();
3708                RRETURN(MATCH_NOMATCH);
3709                }
3710              if (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0)
3711              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3712            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3713            }            }
# Line 3486  for (;;) Line 3753  for (;;)
3753          break;          break;
3754    
3755          case OP_ALLANY:          case OP_ALLANY:
3756          if (eptr > md->end_subject - min) RRETURN(MATCH_NOMATCH);          if (eptr > md->end_subject - min)
3757              {
3758              SCHECK_PARTIAL();
3759              RRETURN(MATCH_NOMATCH);
3760              }
3761          eptr += min;          eptr += min;
3762          break;          break;
3763    
3764          case OP_ANYBYTE:          case OP_ANYBYTE:
3765          if (eptr > md->end_subject - min) RRETURN(MATCH_NOMATCH);          if (eptr > md->end_subject - min)
3766              {
3767              SCHECK_PARTIAL();
3768              RRETURN(MATCH_NOMATCH);
3769              }
3770          eptr += min;          eptr += min;
3771          break;          break;
3772    
# Line 3700  for (;;) Line 3975  for (;;)
3975              {              {
3976              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);
3977              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3978              if (fi >= max)              if (fi >= max) RRETURN(MATCH_NOMATCH);
               {  
               CHECK_PARTIAL();  
               RRETURN(MATCH_NOMATCH);  
               }  
3979              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
3980                {                {
3981                SCHECK_PARTIAL();                SCHECK_PARTIAL();
# Line 3720  for (;;) Line 3991  for (;;)
3991              {              {
3992              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);
3993              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3994              if (fi >= max)              if (fi >= max) RRETURN(MATCH_NOMATCH);
               {  
               CHECK_PARTIAL();  
               RRETURN(MATCH_NOMATCH);  
               }  
3995              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
3996                {                {
3997                SCHECK_PARTIAL();                SCHECK_PARTIAL();
# Line 3744  for (;;) Line 4011  for (;;)
4011              {              {
4012              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);
4013              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4014              if (fi >= max)              if (fi >= max) RRETURN(MATCH_NOMATCH);
               {  
               CHECK_PARTIAL();  
               RRETURN(MATCH_NOMATCH);  
               }  
4015              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
4016                {                {
4017                SCHECK_PARTIAL();                SCHECK_PARTIAL();
# Line 3766  for (;;) Line 4029  for (;;)
4029              {              {
4030              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);
4031              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4032              if (fi >= max)              if (fi >= max) RRETURN(MATCH_NOMATCH);
               {  
               CHECK_PARTIAL();  
               RRETURN(MATCH_NOMATCH);  
               }  
4033              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
4034                {                {
4035                SCHECK_PARTIAL();                SCHECK_PARTIAL();
# Line 3788  for (;;) Line 4047  for (;;)
4047              {              {
4048              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);
4049              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4050              if (fi >= max)              if (fi >= max) RRETURN(MATCH_NOMATCH);
               {  
               CHECK_PARTIAL();  
               RRETURN(MATCH_NOMATCH);  
               }  
4051              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
4052                {                {
4053                SCHECK_PARTIAL();                SCHECK_PARTIAL();
# Line 3819  for (;;) Line 4074  for (;;)
4074            {            {
4075            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);
4076            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4077            if (fi >= max)            if (fi >= max) RRETURN(MATCH_NOMATCH);
             {  
             CHECK_PARTIAL();  
             RRETURN(MATCH_NOMATCH);  
             }  
4078            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4079              {              {
4080              SCHECK_PARTIAL();              SCHECK_PARTIAL();
# Line 3855  for (;;) Line 4106  for (;;)
4106            {            {
4107            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);
4108            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4109            if (fi >= max)            if (fi >= max) RRETURN(MATCH_NOMATCH);
             {  
             CHECK_PARTIAL();  
             RRETURN(MATCH_NOMATCH);  
             }  
4110            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4111              {              {
4112              SCHECK_PARTIAL();              SCHECK_PARTIAL();
# Line 4022  for (;;) Line 4269  for (;;)
4269            {            {
4270            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);
4271            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4272            if (fi >= max)            if (fi >= max) RRETURN(MATCH_NOMATCH);
             {  
             CHECK_PARTIAL();  
             RRETURN(MATCH_NOMATCH);  
             }  
4273            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4274              {              {
4275              SCHECK_PARTIAL();              SCHECK_PARTIAL();
# Line 4158  for (;;) Line 4401  for (;;)
4401            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4402              {              {
4403              int len = 1;              int len = 1;
4404              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4405                  {
4406                  SCHECK_PARTIAL();
4407                  break;
4408                  }
4409              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4410              if (prop_fail_result) break;              if (prop_fail_result) break;
4411              eptr+= len;              eptr+= len;
# Line 4169  for (;;) Line 4416  for (;;)
4416            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4417              {              {
4418              int len = 1;              int len = 1;
4419              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4420                  {
4421                  SCHECK_PARTIAL();
4422                  break;
4423                  }
4424              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4425              prop_chartype = UCD_CHARTYPE(c);              prop_chartype = UCD_CHARTYPE(c);
4426              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
# Line 4184  for (;;) Line 4435  for (;;)
4435            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4436              {              {
4437              int len = 1;              int len = 1;
4438              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4439                  {
4440                  SCHECK_PARTIAL();
4441                  break;
4442                  }
4443              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4444              prop_category = UCD_CATEGORY(c);              prop_category = UCD_CATEGORY(c);
4445              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
# Line 4197  for (;;) Line 4452  for (;;)
4452            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4453              {              {
4454              int len = 1;              int len = 1;
4455              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4456                  {
4457                  SCHECK_PARTIAL();
4458                  break;
4459                  }
4460              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4461              prop_chartype = UCD_CHARTYPE(c);              prop_chartype = UCD_CHARTYPE(c);
4462              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
# Line 4210  for (;;) Line 4469  for (;;)
4469            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4470              {              {
4471              int len = 1;              int len = 1;
4472              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4473                  {
4474                  SCHECK_PARTIAL();
4475                  break;
4476                  }
4477              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4478              prop_script = UCD_SCRIPT(c);              prop_script = UCD_SCRIPT(c);
4479              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
# Line 4222  for (;;) Line 4485  for (;;)
4485    
4486          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
4487    
         CHECK_PARTIAL();  
4488          if (possessive) continue;          if (possessive) continue;
4489          for(;;)          for(;;)
4490            {            {
# Line 4240  for (;;) Line 4502  for (;;)
4502          {          {
4503          for (i = min; i < max; i++)          for (i = min; i < max; i++)
4504            {            {
4505            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject)
4506                {
4507                SCHECK_PARTIAL();
4508                break;
4509                }
4510            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
4511            prop_category = UCD_CATEGORY(c);            prop_category = UCD_CATEGORY(c);
4512            if (prop_category == ucp_M) break;            if (prop_category == ucp_M) break;
# Line 4259  for (;;) Line 4525  for (;;)
4525    
4526          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
4527    
         CHECK_PARTIAL();  
4528          if (possessive) continue;          if (possessive) continue;
4529    
4530          for(;;)          for(;;)
4531            {            {
4532            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45);
# Line 4296  for (;;) Line 4562  for (;;)
4562              {              {
4563              for (i = min; i < max; i++)              for (i = min; i < max; i++)
4564                {                {
4565                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;                if (eptr >= md->end_subject)
4566                    {
4567                    SCHECK_PARTIAL();
4568                    break;
4569                    }
4570                  if (IS_NEWLINE(eptr)) break;
4571                eptr++;                eptr++;
4572                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
4573                }                }
# Line 4308  for (;;) Line 4579  for (;;)
4579              {              {
4580              for (i = min; i < max; i++)              for (i = min; i < max; i++)
4581                {                {
4582                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;                if (eptr >= md->end_subject)
4583                    {
4584                    SCHECK_PARTIAL();
4585                    break;
4586                    }
4587                  if (IS_NEWLINE(eptr)) break;
4588                eptr++;                eptr++;
4589                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
4590                }                }
# Line 4320  for (;;) Line 4596  for (;;)
4596              {              {
4597              for (i = min; i < max; i++)              for (i = min; i < max; i++)
4598                {                {
4599                if (eptr >= md->end_subject) break;                if (eptr >= md->end_subject)
4600                    {
4601                    SCHECK_PARTIAL();
4602                    break;
4603                    }
4604                eptr++;                eptr++;
4605                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
4606                }                }
# Line 4333  for (;;) Line 4613  for (;;)
4613            case OP_ANYBYTE:            case OP_ANYBYTE:
4614            c = max - min;            c = max - min;
4615            if (c > (unsigned int)(md->end_subject - eptr))            if (c > (unsigned int)(md->end_subject - eptr))
4616              c = md->end_subject - eptr;              {
4617            eptr += c;              eptr = md->end_subject;
4618                SCHECK_PARTIAL();
4619                }
4620              else eptr += c;
4621            break;            break;
4622    
4623            case OP_ANYNL:            case OP_ANYNL:
4624            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4625              {              {
4626              int len = 1;              int len = 1;
4627              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4628                  {
4629                  SCHECK_PARTIAL();
4630                  break;
4631                  }
4632              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4633              if (c == 0x000d)              if (c == 0x000d)
4634                {                {
# Line 4366  for (;;) Line 4653  for (;;)
4653              {              {
4654              BOOL gotspace;              BOOL gotspace;
4655              int len = 1;              int len = 1;
4656              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4657                  {
4658                  SCHECK_PARTIAL();
4659                  break;
4660                  }
4661              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4662              switch(c)              switch(c)
4663                {                {
# Line 4404  for (;;) Line 4695  for (;;)
4695              {              {
4696              BOOL gotspace;              BOOL gotspace;
4697              int len = 1;              int len = 1;
4698              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4699                  {
4700                  SCHECK_PARTIAL();
4701                  break;
4702                  }
4703              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4704              switch(c)              switch(c)
4705                {                {
# Line 4428  for (;;) Line 4723  for (;;)
4723            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4724              {              {
4725              int len = 1;              int len = 1;
4726              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4727                  {
4728                  SCHECK_PARTIAL();
4729                  break;
4730                  }
4731              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4732              if (c < 256 && (md->ctypes[c] & ctype_digit) != 0) break;              if (c < 256 && (md->ctypes[c] & ctype_digit) != 0) break;
4733              eptr+= len;              eptr+= len;
# Line 4439  for (;;) Line 4738  for (;;)
4738            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4739              {              {
4740              int len = 1;              int len = 1;
4741              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4742                  {
4743                  SCHECK_PARTIAL();
4744                  break;
4745                  }
4746              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4747              if (c >= 256 ||(md->ctypes[c] & ctype_digit) == 0) break;              if (c >= 256 ||(md->ctypes[c] & ctype_digit) == 0) break;
4748              eptr+= len;              eptr+= len;
# Line 4450  for (;;) Line 4753  for (;;)
4753            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4754              {              {
4755              int len = 1;              int len = 1;
4756              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4757                  {
4758                  SCHECK_PARTIAL();
4759                  break;
4760                  }
4761              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4762              if (c < 256 && (md->ctypes[c] & ctype_space) != 0) break;              if (c < 256 && (md->ctypes[c] & ctype_space) != 0) break;
4763              eptr+= len;              eptr+= len;
# Line 4461  for (;;) Line 4768  for (;;)
4768            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4769              {              {
4770              int len = 1;              int len = 1;
4771              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4772                  {
4773                  SCHECK_PARTIAL();
4774                  break;
4775                  }
4776              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4777              if (c >= 256 ||(md->ctypes[c] & ctype_space) == 0) break;              if (c >= 256 ||(md->ctypes[c] & ctype_space) == 0) break;
4778              eptr+= len;              eptr+= len;
# Line 4472  for (;;) Line 4783  for (;;)
4783            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4784              {              {
4785              int len = 1;              int len = 1;
4786              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4787                  {
4788                  SCHECK_PARTIAL();
4789                  break;
4790                  }
4791              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4792              if (c < 256 && (md->ctypes[c] & ctype_word) != 0) break;              if (c < 256 && (md->ctypes[c] & ctype_word) != 0) break;
4793              eptr+= len;              eptr+= len;
# Line 4483  for (;;) Line 4798  for (;;)
4798            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4799              {              {
4800              int len = 1;              int len = 1;
4801              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4802                  {
4803                  SCHECK_PARTIAL();
4804                  break;
4805                  }
4806              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4807              if (c >= 256 || (md->ctypes[c] & ctype_word) == 0) break;              if (c >= 256 || (md->ctypes[c] & ctype_word) == 0) break;
4808              eptr+= len;              eptr+= len;
# Line 4496  for (;;) Line 4815  for (;;)
4815    
4816          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
4817    
         CHECK_PARTIAL();  
4818          if (possessive) continue;          if (possessive) continue;
4819          for(;;)          for(;;)
4820            {            {
# Line 4516  for (;;) Line 4834  for (;;)
4834            case OP_ANY:            case OP_ANY:
4835            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4836              {              {
4837              if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;              if (eptr >= md->end_subject)
4838                  {
4839                  SCHECK_PARTIAL();
4840                  break;
4841                  }
4842                if (IS_NEWLINE(eptr)) break;
4843              eptr++;              eptr++;
4844              }              }
4845            break;            break;
# Line 4525  for (;;) Line 4848  for (;;)
4848            case OP_ANYBYTE:            case OP_ANYBYTE:
4849            c = max - min;            c = max - min;
4850            if (c > (unsigned int)(md->end_subject - eptr))            if (c > (unsigned int)(md->end_subject - eptr))
4851              c = md->end_subject - eptr;              {
4852            eptr += c;              eptr = md->end_subject;
4853                SCHECK_PARTIAL();
4854                }
4855              else eptr += c;
4856            break;            break;
4857    
4858            case OP_ANYNL:            case OP_ANYNL:
4859            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4860              {              {
4861              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4862                  {
4863                  SCHECK_PARTIAL();
4864                  break;
4865                  }
4866              c = *eptr;              c = *eptr;
4867              if (c == 0x000d)              if (c == 0x000d)
4868                {                {
# Line 4553  for (;;) Line 4883  for (;;)
4883            case OP_NOT_HSPACE:            case OP_NOT_HSPACE:
4884            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4885              {              {
4886              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4887                  {
4888                  SCHECK_PARTIAL();
4889                  break;
4890                  }
4891              c = *eptr;              c = *eptr;
4892              if (c == 0x09 || c == 0x20 || c == 0xa0) break;              if (c == 0x09 || c == 0x20 || c == 0xa0) break;
4893              eptr++;              eptr++;
# Line 4563  for (;;) Line 4897  for (;;)
4897            case OP_HSPACE:            case OP_HSPACE:
4898            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4899              {              {
4900              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4901                  {
4902                  SCHECK_PARTIAL();
4903                  break;
4904                  }
4905              c = *eptr;              c = *eptr;
4906              if (c != 0x09 && c != 0x20 && c != 0xa0) break;              if (c != 0x09 && c != 0x20 && c != 0xa0) break;
4907              eptr++;              eptr++;
# Line 4573  for (;;) Line 4911  for (;;)
4911            case OP_NOT_VSPACE:            case OP_NOT_VSPACE:
4912            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4913              {              {
4914              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4915                  {
4916                  SCHECK_PARTIAL();
4917                  break;
4918                  }
4919              c = *eptr;              c = *eptr;
4920              if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85)              if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85)
4921                break;                break;
# Line 4584  for (;;) Line 4926  for (;;)
4926            case OP_VSPACE:            case OP_VSPACE:
4927            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4928              {              {
4929              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4930                  {
4931                  SCHECK_PARTIAL();
4932                  break;
4933                  }
4934              c = *eptr;              c = *eptr;
4935              if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85)              if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85)
4936                break;                break;
# Line 4595  for (;;) Line 4941  for (;;)
4941            case OP_NOT_DIGIT:            case OP_NOT_DIGIT:
4942            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4943              {              {
4944              if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_digit) != 0)              if (eptr >= md->end_subject)
4945                  {
4946                  SCHECK_PARTIAL();
4947                break;                break;
4948                  }
4949                if ((md->ctypes[*eptr] & ctype_digit) != 0) break;
4950              eptr++;              eptr++;
4951              }              }
4952            break;            break;
# Line 4604  for (;;) Line 4954  for (;;)
4954            case OP_DIGIT:            case OP_DIGIT:
4955            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4956              {              {
4957              if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_digit) == 0)              if (eptr >= md->end_subject)
4958                  {
4959                  SCHECK_PARTIAL();
4960                break;                break;
4961                  }
4962                if ((md->ctypes[*eptr] & ctype_digit) == 0) break;
4963              eptr++;              eptr++;
4964              }              }
4965            break;            break;
# Line 4613  for (;;) Line 4967  for (;;)
4967            case OP_NOT_WHITESPACE:            case OP_NOT_WHITESPACE:
4968            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4969              {              {
4970              if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_space) != 0)              if (eptr >= md->end_subject)
4971                  {
4972                  SCHECK_PARTIAL();
4973                break;                break;
4974                  }
4975                if ((md->ctypes[*eptr] & ctype_space) != 0) break;
4976              eptr++;              eptr++;
4977              }              }
4978            break;            break;
# Line 4622  for (;;) Line 4980  for (;;)
4980            case OP_WHITESPACE:            case OP_WHITESPACE:
4981            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4982              {              {
4983              if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_space) == 0)              if (eptr >= md->end_subject)
4984                  {
4985                  SCHECK_PARTIAL();
4986                break;                break;
4987                  }
4988                if ((md->ctypes[*eptr] & ctype_space) == 0) break;
4989              eptr++;              eptr++;
4990              }              }
4991            break;            break;
# Line 4631  for (;;) Line 4993  for (;;)
4993            case OP_NOT_WORDCHAR:            case OP_NOT_WORDCHAR:
4994            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4995              {              {
4996              if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_word) != 0)              if (eptr >= md->end_subject)
4997                  {
4998                  SCHECK_PARTIAL();
4999                break;                break;
5000                  }
5001                if ((md->ctypes[*eptr] & ctype_word) != 0) break;
5002              eptr++;              eptr++;
5003              }              }
5004            break;            break;
# Line 4640  for (;;) Line 5006  for (;;)
5006            case OP_WORDCHAR:            case OP_WORDCHAR:
5007            for (i = min; i < max; i++)            for (i = min; i < max; i++)
5008              {              {
5009              if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_word) == 0)              if (eptr >= md->end_subject)
5010                  {
5011                  SCHECK_PARTIAL();
5012                break;                break;
5013                  }
5014                if ((md->ctypes[*eptr] & ctype_word) == 0) break;
5015              eptr++;              eptr++;
5016              }              }
5017            break;            break;
# Line 4652  for (;;) Line 5022  for (;;)
5022    
5023          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
5024    
         CHECK_PARTIAL();  
5025          if (possessive) continue;          if (possessive) continue;
5026          while (eptr >= pp)          while (eptr >= pp)
5027            {            {
# Line 4837  if (re == NULL || subject == NULL || Line 5206  if (re == NULL || subject == NULL ||
5206     (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;     (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;
5207  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;
5208    
5209    /* This information is for finding all the numbers associated with a given
5210    name, for condition testing. */
5211    
5212    md->name_table = (uschar *)re + re->name_table_offset;
5213    md->name_count = re->name_count;
5214    md->name_entry_size = re->name_entry_size;
5215    
5216  /* Fish out the optional data from the extra_data structure, first setting  /* Fish out the optional data from the extra_data structure, first setting
5217  the default values. */  the default values. */
5218    
# Line 4904  md->jscript_compat = (re->options & PCRE Line 5280  md->jscript_compat = (re->options & PCRE
5280  md->notbol = (options & PCRE_NOTBOL) != 0;  md->notbol = (options & PCRE_NOTBOL) != 0;
5281  md->noteol = (options & PCRE_NOTEOL) != 0;  md->noteol = (options & PCRE_NOTEOL) != 0;
5282  md->notempty = (options & PCRE_NOTEMPTY) != 0;  md->notempty = (options & PCRE_NOTEMPTY) != 0;
5283    md->notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;
5284  md->partial = ((options & PCRE_PARTIAL_HARD) != 0)? 2 :  md->partial = ((options & PCRE_PARTIAL_HARD) != 0)? 2 :
5285                ((options & PCRE_PARTIAL_SOFT) != 0)? 1 : 0;                ((options & PCRE_PARTIAL_SOFT) != 0)? 1 : 0;
5286  md->hitend = FALSE;  md->hitend = FALSE;
# Line 5068  if (!anchored) Line 5445  if (!anchored)
5445      }      }
5446    else    else
5447      if (!startline && study != NULL &&      if (!startline && study != NULL &&
5448        (study->options & PCRE_STUDY_MAPPED) != 0)        (study->flags & PCRE_STUDY_MAPPED) != 0)
5449          start_bits = study->start_bits;          start_bits = study->start_bits;
5450    }    }
5451    
# Line 5195  for(;;) Line 5572  for(;;)
5572    
5573    end_subject = save_end_subject;    end_subject = save_end_subject;
5574    
5575  #ifdef DEBUG  /* Sigh. Some compilers never learn. */    /* The following two optimizations are disabled for partial matching or if
   printf(">>>> Match against: ");  
   pchars(start_match, end_subject - start_match, TRUE, md);  
   printf("\n");  
 #endif  
   
   /* If req_byte is set, we know that that character must appear in the  
   subject for the match to succeed. If the first character is set, req_byte  
   must be later in the subject; otherwise the test starts at the match point.  
   This optimization can save a huge amount of backtracking in patterns with  
   nested unlimited repeats that aren't going to match. Writing separate code  
   for cased/caseless versions makes it go faster, as does using an  
   autoincrement and backing off on a match.  
   
   HOWEVER: when the subject string is very, very long, searching to its end  
   can take a long time, and give bad performance on quite ordinary patterns.  
   This showed up when somebody was matching something like /^\d+C/ on a  
   32-megabyte string... so we don't do this when the string is sufficiently  
   long.  
   
   ALSO: this processing is disabled when partial matching is requested, or if  
5576    disabling is explicitly requested. */    disabling is explicitly requested. */
5577    
5578    if ((options & PCRE_NO_START_OPTIMIZE) == 0 &&    if ((options & PCRE_NO_START_OPTIMIZE) == 0 && !md->partial)
       req_byte >= 0 &&  
       end_subject - start_match < REQ_BYTE_MAX &&  
       !md->partial)  
5579      {      {
5580      register USPTR p = start_match + ((first_byte >= 0)? 1 : 0);      /* If the pattern was studied, a minimum subject length may be set. This is
5581        a lower bound; no actual string of that length may actually match the
5582        pattern. Although the value is, strictly, in characters, we treat it as
5583        bytes to avoid spending too much time in this optimization. */
5584    
5585        if (study != NULL && (study->flags & PCRE_STUDY_MINLEN) != 0 &&
5586            (pcre_uint32)(end_subject - start_match) < study->minlength)
5587          {
5588          rc = MATCH_NOMATCH;
5589          break;
5590          }
5591    
5592      /* We don't need to repeat the search if we haven't yet reached the      /* If req_byte is set, we know that that character must appear in the
5593      place we found it at last time. */      subject for the match to succeed. If the first character is set, req_byte
5594        must be later in the subject; otherwise the test starts at the match point.
5595        This optimization can save a huge amount of backtracking in patterns with
5596        nested unlimited repeats that aren't going to match. Writing separate code
5597        for cased/caseless versions makes it go faster, as does using an
5598        autoincrement and backing off on a match.
5599    
5600      if (p > req_byte_ptr)      HOWEVER: when the subject string is very, very long, searching to its end
5601        can take a long time, and give bad performance on quite ordinary patterns.
5602        This showed up when somebody was matching something like /^\d+C/ on a
5603        32-megabyte string... so we don't do this when the string is sufficiently
5604        long. */
5605    
5606        if (req_byte >= 0 && end_subject - start_match < REQ_BYTE_MAX)
5607        {        {
5608        if (req_byte_caseless)        register USPTR p = start_match + ((first_byte >= 0)? 1 : 0);
5609    
5610          /* We don't need to repeat the search if we haven't yet reached the
5611          place we found it at last time. */
5612    
5613          if (p > req_byte_ptr)
5614          {          {
5615          while (p < end_subject)          if (req_byte_caseless)
5616            {            {
5617            register int pp = *p++;            while (p < end_subject)
5618            if (pp == req_byte || pp == req_byte2) { p--; break; }              {
5619                register int pp = *p++;
5620                if (pp == req_byte || pp == req_byte2) { p--; break; }
5621                }
5622            }            }
5623          }          else
       else  
         {  
         while (p < end_subject)  
5624            {            {
5625            if (*p++ == req_byte) { p--; break; }            while (p < end_subject)
5626                {
5627                if (*p++ == req_byte) { p--; break; }
5628                }
5629            }            }
         }  
5630    
5631        /* If we can't find the required character, break the matching loop,          /* If we can't find the required character, break the matching loop,
5632        forcing a match failure. */          forcing a match failure. */
5633    
5634        if (p >= end_subject)          if (p >= end_subject)
5635          {            {
5636          rc = MATCH_NOMATCH;            rc = MATCH_NOMATCH;
5637          break;            break;
5638          }            }
5639    
5640        /* If we have found the required character, save the point where we          /* If we have found the required character, save the point where we
5641        found it, so that we don't search again next time round the loop if          found it, so that we don't search again next time round the loop if
5642        the start hasn't passed this character yet. */          the start hasn't passed this character yet. */
5643    
5644        req_byte_ptr = p;          req_byte_ptr = p;
5645            }
5646        }        }
5647      }      }
5648    
5649    #ifdef PCRE_DEBUG  /* Sigh. Some compilers never learn. */
5650      printf(">>>> Match against: ");
5651      pchars(start_match, end_subject - start_match, TRUE, md);
5652      printf("\n");
5653    #endif
5654    
5655    /* OK, we can now run the match. If "hitend" is set afterwards, remember the    /* OK, we can now run the match. If "hitend" is set afterwards, remember the
5656    first starting point for which a partial match was found. */    first starting point for which a partial match was found. */
5657    
5658    md->start_match_ptr = start_match;    md->start_match_ptr = start_match;
5659      md->start_used_ptr = start_match;
5660    md->match_call_count = 0;    md->match_call_count = 0;
5661    rc = match(start_match, md->start_code, start_match, 2, md, ims, NULL, 0, 0);    rc = match(start_match, md->start_code, start_match, 2, md, ims, NULL, 0, 0);
5662    if (md->hitend && start_partial == NULL) start_partial = start_match;    if (md->hitend && start_partial == NULL) start_partial = md->start_used_ptr;
5663    
5664    switch(rc)    switch(rc)
5665      {      {
# Line 5299  for(;;) Line 5689  for(;;)
5689      rc = MATCH_NOMATCH;      rc = MATCH_NOMATCH;
5690      goto ENDLOOP;      goto ENDLOOP;
5691    
5692      /* Any other return is some kind of error. */      /* Any other return is either a match, or some kind of error. */
5693    
5694      default:      default:
5695      goto ENDLOOP;      goto ENDLOOP;

Legend:
Removed from v.427  
changed lines
  Added in v.500

  ViewVC Help
Powered by ViewVC 1.1.5