/[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 444 by ph10, Sun Sep 13 16:26:39 2009 UTC revision 501 by ph10, Sun Mar 7 11:49:54 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 249  enum { RM1=1, RM2, RM3, RM4, RM5, RM Line 249  enum { RM1=1, RM2, RM3, RM4, RM5, RM
249    
250  /* These versions of the macros use the stack, as normal. There are debugging  /* These versions of the macros use the stack, as normal. There are debugging
251  versions and production versions. Note that the "rw" argument of RMATCH isn't  versions and production versions. Note that the "rw" argument of RMATCH isn't
252  actuall used in this definition. */  actually used in this definition. */
253    
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__); \
261    rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1); \    rrc = match(ra,rb,mstart,markptr,rc,rd,re,rf,rg,rdepth+1); \
262    printf("to line %d\n", __LINE__); \    printf("to line %d\n", __LINE__); \
263    }    }
264  #define RRETURN(ra) \  #define RRETURN(ra) \
# Line 268  actuall used in this definition. */ Line 268  actuall used in this definition. */
268    }    }
269  #else  #else
270  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
271    rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1)    rrc = match(ra,rb,mstart,markptr,rc,rd,re,rf,rg,rdepth+1)
272  #define RRETURN(ra) return ra  #define RRETURN(ra) return ra
273  #endif  #endif
274    
# Line 288  argument of match(), which never changes Line 288  argument of match(), which never changes
288    newframe->Xeptr = ra;\    newframe->Xeptr = ra;\
289    newframe->Xecode = rb;\    newframe->Xecode = rb;\
290    newframe->Xmstart = mstart;\    newframe->Xmstart = mstart;\
291      newframe->Xmarkptr = markptr;\
292    newframe->Xoffset_top = rc;\    newframe->Xoffset_top = rc;\
293    newframe->Xims = re;\    newframe->Xims = re;\
294    newframe->Xeptrb = rf;\    newframe->Xeptrb = rf;\
# Line 325  typedef struct heapframe { Line 326  typedef struct heapframe {
326    USPTR Xeptr;    USPTR Xeptr;
327    const uschar *Xecode;    const uschar *Xecode;
328    USPTR Xmstart;    USPTR Xmstart;
329      USPTR Xmarkptr;
330    int Xoffset_top;    int Xoffset_top;
331    long int Xims;    long int Xims;
332    eptrblock *Xeptrb;    eptrblock *Xeptrb;
# Line 415  the subject. */ Line 417  the subject. */
417      }      }
418    
419  #define SCHECK_PARTIAL()\  #define SCHECK_PARTIAL()\
420    if (md->partial && eptr > mstart)\    if (md->partial != 0 && eptr > mstart)\
421      {\      {\
422      md->hitend = TRUE;\      md->hitend = TRUE;\
423      if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);\      if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);\
# Line 432  Arguments: Line 434  Arguments:
434     ecode       pointer to current position in compiled code     ecode       pointer to current position in compiled code
435     mstart      pointer to the current match start position (can be modified     mstart      pointer to the current match start position (can be modified
436                   by encountering \K)                   by encountering \K)
437       markptr     pointer to the most recent MARK name, or NULL
438     offset_top  current top pointer     offset_top  current top pointer
439     md          pointer to "static" info for the match     md          pointer to "static" info for the match
440     ims         current /i, /m, and /s options     ims         current /i, /m, and /s options
# Line 450  Returns: MATCH_MATCH if matched Line 453  Returns: MATCH_MATCH if matched
453  */  */
454    
455  static int  static int
456  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart,  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart, USPTR
457    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,    markptr, int offset_top, match_data *md, unsigned long int ims,
458    int flags, unsigned int rdepth)    eptrblock *eptrb, int flags, unsigned int rdepth)
459  {  {
460  /* These variables do not need to be preserved over recursion in this function,  /* These variables do not need to be preserved over recursion in this function,
461  so they can be ordinary variables in all cases. Mark some of them with  so they can be ordinary variables in all cases. Mark some of them with
# Line 480  frame->Xprevframe = NULL; /* Line 483  frame->Xprevframe = NULL; /*
483  frame->Xeptr = eptr;  frame->Xeptr = eptr;
484  frame->Xecode = ecode;  frame->Xecode = ecode;
485  frame->Xmstart = mstart;  frame->Xmstart = mstart;
486    frame->Xmarkptr = markptr;
487  frame->Xoffset_top = offset_top;  frame->Xoffset_top = offset_top;
488  frame->Xims = ims;  frame->Xims = ims;
489  frame->Xeptrb = eptrb;  frame->Xeptrb = eptrb;
# Line 495  HEAP_RECURSE: Line 499  HEAP_RECURSE:
499  #define eptr               frame->Xeptr  #define eptr               frame->Xeptr
500  #define ecode              frame->Xecode  #define ecode              frame->Xecode
501  #define mstart             frame->Xmstart  #define mstart             frame->Xmstart
502    #define markptr            frame->Xmarkptr
503  #define offset_top         frame->Xoffset_top  #define offset_top         frame->Xoffset_top
504  #define ims                frame->Xims  #define ims                frame->Xims
505  #define eptrb              frame->Xeptrb  #define eptrb              frame->Xeptrb
# Line 622  TAIL_RECURSE: Line 627  TAIL_RECURSE:
627  /* 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
628  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
629  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()
630  and a "return", respectively (possibly with some debugging if DEBUG is  and a "return", respectively (possibly with some debugging if PCRE_DEBUG is
631  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
632  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,
633  however, impact performance when true recursion is being used. */  however, impact performance when true recursion is being used. */
# Line 713  for (;;) Line 718  for (;;)
718      number = GET2(ecode, 1+LINK_SIZE);      number = GET2(ecode, 1+LINK_SIZE);
719      offset = number << 1;      offset = number << 1;
720    
721  #ifdef DEBUG  #ifdef PCRE_DEBUG
722      printf("start bracket %d\n", number);      printf("start bracket %d\n", number);
723      printf("subject=");      printf("subject=");
724      pchars(eptr, 16, TRUE, md);      pchars(eptr, 16, TRUE, md);
# Line 839  for (;;) Line 844  for (;;)
844    
845      /* Now see what the actual condition is */      /* Now see what the actual condition is */
846    
847      if (condcode == OP_RREF)         /* Recursion test */      if (condcode == OP_RREF || condcode == OP_NRREF)    /* Recursion test */
848        {        {
849        offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/        if (md->recursive == NULL)                /* Not recursing => FALSE */
850        condition = md->recursive != NULL &&          {
851          (offset == RREF_ANY || offset == md->recursive->group_num);          condition = FALSE;
852        ecode += condition? 3 : GET(ecode, 1);          ecode += GET(ecode, 1);
853            }
854          else
855            {
856            int recno = GET2(ecode, LINK_SIZE + 2);   /* Recursion group number*/
857            condition =  (recno == RREF_ANY || recno == md->recursive->group_num);
858    
859            /* If the test is for recursion into a specific subpattern, and it is
860            false, but the test was set up by name, scan the table to see if the
861            name refers to any other numbers, and test them. The condition is true
862            if any one is set. */
863    
864            if (!condition && condcode == OP_NRREF && recno != RREF_ANY)
865              {
866              uschar *slotA = md->name_table;
867              for (i = 0; i < md->name_count; i++)
868                {
869                if (GET2(slotA, 0) == recno) break;
870                slotA += md->name_entry_size;
871                }
872    
873              /* Found a name for the number - there can be only one; duplicate
874              names for different numbers are allowed, but not vice versa. First
875              scan down for duplicates. */
876    
877              if (i < md->name_count)
878                {
879                uschar *slotB = slotA;
880                while (slotB > md->name_table)
881                  {
882                  slotB -= md->name_entry_size;
883                  if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
884                    {
885                    condition = GET2(slotB, 0) == md->recursive->group_num;
886                    if (condition) break;
887                    }
888                  else break;
889                  }
890    
891                /* Scan up for duplicates */
892    
893                if (!condition)
894                  {
895                  slotB = slotA;
896                  for (i++; i < md->name_count; i++)
897                    {
898                    slotB += md->name_entry_size;
899                    if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
900                      {
901                      condition = GET2(slotB, 0) == md->recursive->group_num;
902                      if (condition) break;
903                      }
904                    else break;
905                    }
906                  }
907                }
908              }
909    
910            /* Chose branch according to the condition */
911    
912            ecode += condition? 3 : GET(ecode, 1);
913            }
914        }        }
915    
916      else if (condcode == OP_CREF)    /* Group used test */      else if (condcode == OP_CREF || condcode == OP_NCREF)  /* Group used test */
917        {        {
918        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */
919        condition = offset < offset_top && md->offset_vector[offset] >= 0;        condition = offset < offset_top && md->offset_vector[offset] >= 0;
920    
921          /* If the numbered capture is unset, but the reference was by name,
922          scan the table to see if the name refers to any other numbers, and test
923          them. The condition is true if any one is set. This is tediously similar
924          to the code above, but not close enough to try to amalgamate. */
925    
926          if (!condition && condcode == OP_NCREF)
927            {
928            int refno = offset >> 1;
929            uschar *slotA = md->name_table;
930    
931            for (i = 0; i < md->name_count; i++)
932              {
933              if (GET2(slotA, 0) == refno) break;
934              slotA += md->name_entry_size;
935              }
936    
937            /* Found a name for the number - there can be only one; duplicate names
938            for different numbers are allowed, but not vice versa. First scan down
939            for duplicates. */
940    
941            if (i < md->name_count)
942              {
943              uschar *slotB = slotA;
944              while (slotB > md->name_table)
945                {
946                slotB -= md->name_entry_size;
947                if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
948                  {
949                  offset = GET2(slotB, 0) << 1;
950                  condition = offset < offset_top &&
951                    md->offset_vector[offset] >= 0;
952                  if (condition) break;
953                  }
954                else break;
955                }
956    
957              /* Scan up for duplicates */
958    
959              if (!condition)
960                {
961                slotB = slotA;
962                for (i++; i < md->name_count; i++)
963                  {
964                  slotB += md->name_entry_size;
965                  if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
966                    {
967                    offset = GET2(slotB, 0) << 1;
968                    condition = offset < offset_top &&
969                      md->offset_vector[offset] >= 0;
970                    if (condition) break;
971                    }
972                  else break;
973                  }
974                }
975              }
976            }
977    
978          /* Chose branch according to the condition */
979    
980        ecode += condition? 3 : GET(ecode, 1);        ecode += condition? 3 : GET(ecode, 1);
981        }        }
982    
# Line 911  for (;;) Line 1037  for (;;)
1037      break;      break;
1038    
1039    
1040        /* Before OP_ACCEPT there may be any number of OP_CLOSE opcodes,
1041        to close any currently open capturing brackets. */
1042    
1043        case OP_CLOSE:
1044        number = GET2(ecode, 1);
1045        offset = number << 1;
1046    
1047    #ifdef PCRE_DEBUG
1048          printf("end bracket %d at *ACCEPT", number);
1049          printf("\n");
1050    #endif
1051    
1052        md->capture_last = number;
1053        if (offset >= md->offset_max) md->offset_overflow = TRUE; else
1054          {
1055          md->offset_vector[offset] =
1056            md->offset_vector[md->offset_end - number];
1057          md->offset_vector[offset+1] = eptr - md->start_subject;
1058          if (offset_top <= offset) offset_top = offset + 2;
1059          }
1060        ecode += 3;
1061        break;
1062    
1063    
1064      /* 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
1065      recursion, we should restore the offsets appropriately and continue from      recursion, we should restore the offsets appropriately and continue from
1066      after the call. */      after the call. */
# Line 924  for (;;) Line 1074  for (;;)
1074        md->recursive = rec->prevrec;        md->recursive = rec->prevrec;
1075        memmove(md->offset_vector, rec->offset_save,        memmove(md->offset_vector, rec->offset_save,
1076          rec->saved_max * sizeof(int));          rec->saved_max * sizeof(int));
1077        mstart = rec->save_start;        offset_top = rec->save_offset_top;
1078        ims = original_ims;        ims = original_ims;
1079        ecode = rec->after_call;        ecode = rec->after_call;
1080        break;        break;
# Line 968  for (;;) Line 1118  for (;;)
1118        {        {
1119        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
1120          RM4);          RM4);
1121        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH)
1122            {
1123            mstart = md->start_match_ptr;   /* In case \K reset it */
1124            break;
1125            }
1126        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1127        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1128        }        }
# Line 987  for (;;) Line 1141  for (;;)
1141      offset_top = md->end_offset_top;      offset_top = md->end_offset_top;
1142      continue;      continue;
1143    
1144      /* Negative assertion: all branches must fail to match */      /* Negative assertion: all branches must fail to match. Encountering SKIP,
1145        PRUNE, or COMMIT means we must assume failure without checking subsequent
1146        branches. */
1147    
1148      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1149      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
# Line 996  for (;;) Line 1152  for (;;)
1152        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
1153          RM5);          RM5);
1154        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);
1155          if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)
1156            {
1157            do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1158            break;
1159            }
1160        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1161        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1162        }        }
# Line 1114  for (;;) Line 1275  for (;;)
1275    
1276        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
1277              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1278        new_recursive.save_start = mstart;        new_recursive.save_offset_top = offset_top;
       mstart = eptr;  
1279    
1280        /* 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
1281        restore the offset and recursion data. */        restore the offset and recursion data. */
# Line 1162  for (;;) Line 1322  for (;;)
1322      a move back into the brackets. Friedl calls these "atomic" subpatterns.      a move back into the brackets. Friedl calls these "atomic" subpatterns.
1323      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
1324      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
1325      the end of a normal bracket, leaving the subject pointer. */      the end of a normal bracket, leaving the subject pointer, but resetting
1326        the start-of-match value in case it was changed by \K. */
1327    
1328      case OP_ONCE:      case OP_ONCE:
1329      prev = ecode;      prev = ecode;
# Line 1171  for (;;) Line 1332  for (;;)
1332      do      do
1333        {        {
1334        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);
1335        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH)
1336            {
1337            mstart = md->start_match_ptr;
1338            break;
1339            }
1340        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1341        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1342        }        }
# Line 1290  for (;;) Line 1455  for (;;)
1455        }        }
1456      else saved_eptr = NULL;      else saved_eptr = NULL;
1457    
1458      /* 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
1459      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
1460      assertions. Do this also for the "once" (atomic) groups. */      use by positive assertions. We also need to record the match start in case
1461        it was changed by \K. */
1462    
1463      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||
1464          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||
# Line 1300  for (;;) Line 1466  for (;;)
1466        {        {
1467        md->end_match_ptr = eptr;      /* For ONCE */        md->end_match_ptr = eptr;      /* For ONCE */
1468        md->end_offset_top = offset_top;        md->end_offset_top = offset_top;
1469          md->start_match_ptr = mstart;
1470        RRETURN(MATCH_MATCH);        RRETURN(MATCH_MATCH);
1471        }        }
1472    
# Line 1314  for (;;) Line 1481  for (;;)
1481        number = GET2(prev, 1+LINK_SIZE);        number = GET2(prev, 1+LINK_SIZE);
1482        offset = number << 1;        offset = number << 1;
1483    
1484  #ifdef DEBUG  #ifdef PCRE_DEBUG
1485        printf("end bracket %d", number);        printf("end bracket %d", number);
1486        printf("\n");        printf("\n");
1487  #endif  #endif
# Line 1336  for (;;) Line 1503  for (;;)
1503          recursion_info *rec = md->recursive;          recursion_info *rec = md->recursive;
1504          DPRINTF(("Recursion (%d) succeeded - continuing\n", number));          DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
1505          md->recursive = rec->prevrec;          md->recursive = rec->prevrec;
         mstart = rec->save_start;  
1506          memcpy(md->offset_vector, rec->offset_save,          memcpy(md->offset_vector, rec->offset_save,
1507            rec->saved_max * sizeof(int));            rec->saved_max * sizeof(int));
1508            offset_top = rec->save_offset_top;
1509          ecode = rec->after_call;          ecode = rec->after_call;
1510          ims = original_ims;          ims = original_ims;
1511          break;          break;
# Line 1998  for (;;) Line 2165  for (;;)
2165          pp = eptr;          pp = eptr;
2166          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2167            {            {
2168            if (!match_ref(offset, eptr, length, md, ims)) break;            if (!match_ref(offset, eptr, length, md, ims))
2169                {
2170                CHECK_PARTIAL();
2171                break;
2172                }
2173            eptr += length;            eptr += length;
2174            }            }
2175          while (eptr >= pp)          while (eptr >= pp)
# Line 2167  for (;;) Line 2338  for (;;)
2338            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2339              {              {
2340              int len = 1;              int len = 1;
2341              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
2342                  {
2343                  SCHECK_PARTIAL();
2344                  break;
2345                  }
2346              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
2347              if (c > 255)              if (c > 255)
2348                {                {
# Line 2193  for (;;) Line 2368  for (;;)
2368            {            {
2369            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2370              {              {
2371              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
2372                  {
2373                  SCHECK_PARTIAL();
2374                  break;
2375                  }
2376              c = *eptr;              c = *eptr;
2377              if ((data[c/8] & (1 << (c&7))) == 0) break;              if ((data[c/8] & (1 << (c&7))) == 0) break;
2378              eptr++;              eptr++;
# Line 2298  for (;;) Line 2477  for (;;)
2477          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2478            {            {
2479            int len = 1;            int len = 1;
2480            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject)
2481                {
2482                SCHECK_PARTIAL();
2483                break;
2484                }
2485            GETCHARLENTEST(c, eptr, len);            GETCHARLENTEST(c, eptr, len);
2486            if (!_pcre_xclass(c, data)) break;            if (!_pcre_xclass(c, data)) break;
2487            eptr += len;            eptr += len;
# Line 2537  for (;;) Line 2720  for (;;)
2720                       eptr <= md->end_subject - oclength &&                       eptr <= md->end_subject - oclength &&
2721                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2722  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2723              else break;              else
2724                  {
2725                  CHECK_PARTIAL();
2726                  break;
2727                  }
2728              }              }
2729    
2730            if (possessive) continue;            if (possessive) continue;
# Line 2615  for (;;) Line 2802  for (;;)
2802          pp = eptr;          pp = eptr;
2803          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2804            {            {
2805            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;            if (eptr >= md->end_subject)
2806                {
2807                SCHECK_PARTIAL();
2808                break;
2809                }
2810              if (fc != md->lcc[*eptr]) break;
2811            eptr++;            eptr++;
2812            }            }
2813    
# Line 2669  for (;;) Line 2861  for (;;)
2861          pp = eptr;          pp = eptr;
2862          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2863            {            {
2864            if (eptr >= md->end_subject || fc != *eptr) break;            if (eptr >= md->end_subject)
2865                {
2866                SCHECK_PARTIAL();
2867                break;
2868                }
2869              if (fc != *eptr) break;
2870            eptr++;            eptr++;
2871            }            }
2872          if (possessive) continue;          if (possessive) continue;
# Line 2881  for (;;) Line 3078  for (;;)
3078            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3079              {              {
3080              int len = 1;              int len = 1;
3081              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
3082                  {
3083                  SCHECK_PARTIAL();
3084                  break;
3085                  }
3086              GETCHARLEN(d, eptr, len);              GETCHARLEN(d, eptr, len);
3087              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
3088              if (fc == d) break;              if (fc == d) break;
# Line 2902  for (;;) Line 3103  for (;;)
3103            {            {
3104            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3105              {              {
3106              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;              if (eptr >= md->end_subject)
3107                  {
3108                  SCHECK_PARTIAL();
3109                  break;
3110                  }
3111                if (fc == md->lcc[*eptr]) break;
3112              eptr++;              eptr++;
3113              }              }
3114            if (possessive) continue;            if (possessive) continue;
# Line 3011  for (;;) Line 3217  for (;;)
3217            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3218              {              {
3219              int len = 1;              int len = 1;
3220              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
3221                  {
3222                  SCHECK_PARTIAL();
3223                  break;
3224                  }
3225              GETCHARLEN(d, eptr, len);              GETCHARLEN(d, eptr, len);
3226              if (fc == d) break;              if (fc == d) break;
3227              eptr += len;              eptr += len;
# Line 3031  for (;;) Line 3241  for (;;)
3241            {            {
3242            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3243              {              {
3244              if (eptr >= md->end_subject || fc == *eptr) break;              if (eptr >= md->end_subject)
3245                  {
3246                  SCHECK_PARTIAL();
3247                  break;
3248                  }
3249                if (fc == *eptr) break;
3250              eptr++;              eptr++;
3251              }              }
3252            if (possessive) continue;            if (possessive) continue;
# Line 3492  for (;;) Line 3707  for (;;)
3707          case OP_NOT_WORDCHAR:          case OP_NOT_WORDCHAR:
3708          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3709            {            {
3710            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3711               (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0))              {
3712                SCHECK_PARTIAL();
3713                RRETURN(MATCH_NOMATCH);
3714                }
3715              if (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0)
3716              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3717            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3718            }            }
# Line 4187  for (;;) Line 4406  for (;;)
4406            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4407              {              {
4408              int len = 1;              int len = 1;
4409              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4410                  {
4411                  SCHECK_PARTIAL();
4412                  break;
4413                  }
4414              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4415              if (prop_fail_result) break;              if (prop_fail_result) break;
4416              eptr+= len;              eptr+= len;
# Line 4198  for (;;) Line 4421  for (;;)
4421            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4422              {              {
4423              int len = 1;              int len = 1;
4424              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4425                  {
4426                  SCHECK_PARTIAL();
4427                  break;
4428                  }
4429              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4430              prop_chartype = UCD_CHARTYPE(c);              prop_chartype = UCD_CHARTYPE(c);
4431              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
# Line 4213  for (;;) Line 4440  for (;;)
4440            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4441              {              {
4442              int len = 1;              int len = 1;
4443              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4444                  {
4445                  SCHECK_PARTIAL();
4446                  break;
4447                  }
4448              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4449              prop_category = UCD_CATEGORY(c);              prop_category = UCD_CATEGORY(c);
4450              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
# Line 4226  for (;;) Line 4457  for (;;)
4457            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4458              {              {
4459              int len = 1;              int len = 1;
4460              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4461                  {
4462                  SCHECK_PARTIAL();
4463                  break;
4464                  }
4465              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4466              prop_chartype = UCD_CHARTYPE(c);              prop_chartype = UCD_CHARTYPE(c);
4467              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
# Line 4239  for (;;) Line 4474  for (;;)
4474            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4475              {              {
4476              int len = 1;              int len = 1;
4477              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4478                  {
4479                  SCHECK_PARTIAL();
4480                  break;
4481                  }
4482              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4483              prop_script = UCD_SCRIPT(c);              prop_script = UCD_SCRIPT(c);
4484              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
# Line 4268  for (;;) Line 4507  for (;;)
4507          {          {
4508          for (i = min; i < max; i++)          for (i = min; i < max; i++)
4509            {            {
4510            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject)
4511                {
4512                SCHECK_PARTIAL();
4513                break;
4514                }
4515            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
4516            prop_category = UCD_CATEGORY(c);            prop_category = UCD_CATEGORY(c);
4517            if (prop_category == ucp_M) break;            if (prop_category == ucp_M) break;
# Line 4288  for (;;) Line 4531  for (;;)
4531          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
4532    
4533          if (possessive) continue;          if (possessive) continue;
4534    
4535          for(;;)          for(;;)
4536            {            {
4537            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45);
# Line 4323  for (;;) Line 4567  for (;;)
4567              {              {
4568              for (i = min; i < max; i++)              for (i = min; i < max; i++)
4569                {                {
4570                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;                if (eptr >= md->end_subject)
4571                    {
4572                    SCHECK_PARTIAL();
4573                    break;
4574                    }
4575                  if (IS_NEWLINE(eptr)) break;
4576                eptr++;                eptr++;
4577                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
4578                }                }
# Line 4335  for (;;) Line 4584  for (;;)
4584              {              {
4585              for (i = min; i < max; i++)              for (i = min; i < max; i++)
4586                {                {
4587                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;                if (eptr >= md->end_subject)
4588                    {
4589                    SCHECK_PARTIAL();
4590                    break;
4591                    }
4592                  if (IS_NEWLINE(eptr)) break;
4593                eptr++;                eptr++;
4594                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
4595                }                }
# Line 4347  for (;;) Line 4601  for (;;)
4601              {              {
4602              for (i = min; i < max; i++)              for (i = min; i < max; i++)
4603                {                {
4604                if (eptr >= md->end_subject) break;                if (eptr >= md->end_subject)
4605                    {
4606                    SCHECK_PARTIAL();
4607                    break;
4608                    }
4609                eptr++;                eptr++;
4610                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
4611                }                }
# Line 4360  for (;;) Line 4618  for (;;)
4618            case OP_ANYBYTE:            case OP_ANYBYTE:
4619            c = max - min;            c = max - min;
4620            if (c > (unsigned int)(md->end_subject - eptr))            if (c > (unsigned int)(md->end_subject - eptr))
4621              c = md->end_subject - eptr;              {
4622            eptr += c;              eptr = md->end_subject;
4623                SCHECK_PARTIAL();
4624                }
4625              else eptr += c;
4626            break;            break;
4627    
4628            case OP_ANYNL:            case OP_ANYNL:
4629            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4630              {              {
4631              int len = 1;              int len = 1;
4632              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4633                  {
4634                  SCHECK_PARTIAL();
4635                  break;
4636                  }
4637              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4638              if (c == 0x000d)              if (c == 0x000d)
4639                {                {
# Line 4393  for (;;) Line 4658  for (;;)
4658              {              {
4659              BOOL gotspace;              BOOL gotspace;
4660              int len = 1;              int len = 1;
4661              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4662                  {
4663                  SCHECK_PARTIAL();
4664                  break;
4665                  }
4666              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4667              switch(c)              switch(c)
4668                {                {
# Line 4431  for (;;) Line 4700  for (;;)
4700              {              {
4701              BOOL gotspace;              BOOL gotspace;
4702              int len = 1;              int len = 1;
4703              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4704                  {
4705                  SCHECK_PARTIAL();
4706                  break;
4707                  }
4708              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4709              switch(c)              switch(c)
4710                {                {
# Line 4455  for (;;) Line 4728  for (;;)
4728            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4729              {              {
4730              int len = 1;              int len = 1;
4731              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4732                  {
4733                  SCHECK_PARTIAL();
4734                  break;
4735                  }
4736              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4737              if (c < 256 && (md->ctypes[c] & ctype_digit) != 0) break;              if (c < 256 && (md->ctypes[c] & ctype_digit) != 0) break;
4738              eptr+= len;              eptr+= len;
# Line 4466  for (;;) Line 4743  for (;;)
4743            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4744              {              {
4745              int len = 1;              int len = 1;
4746              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4747                  {
4748                  SCHECK_PARTIAL();
4749                  break;
4750                  }
4751              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4752              if (c >= 256 ||(md->ctypes[c] & ctype_digit) == 0) break;              if (c >= 256 ||(md->ctypes[c] & ctype_digit) == 0) break;
4753              eptr+= len;              eptr+= len;
# Line 4477  for (;;) Line 4758  for (;;)
4758            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4759              {              {
4760              int len = 1;              int len = 1;
4761              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4762                  {
4763                  SCHECK_PARTIAL();
4764                  break;
4765                  }
4766              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4767              if (c < 256 && (md->ctypes[c] & ctype_space) != 0) break;              if (c < 256 && (md->ctypes[c] & ctype_space) != 0) break;
4768              eptr+= len;              eptr+= len;
# Line 4488  for (;;) Line 4773  for (;;)
4773            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4774              {              {
4775              int len = 1;              int len = 1;
4776              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4777                  {
4778                  SCHECK_PARTIAL();
4779                  break;
4780                  }
4781              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4782              if (c >= 256 ||(md->ctypes[c] & ctype_space) == 0) break;              if (c >= 256 ||(md->ctypes[c] & ctype_space) == 0) break;
4783              eptr+= len;              eptr+= len;
# Line 4499  for (;;) Line 4788  for (;;)
4788            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4789              {              {
4790              int len = 1;              int len = 1;
4791              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4792                  {
4793                  SCHECK_PARTIAL();
4794                  break;
4795                  }
4796              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4797              if (c < 256 && (md->ctypes[c] & ctype_word) != 0) break;              if (c < 256 && (md->ctypes[c] & ctype_word) != 0) break;
4798              eptr+= len;              eptr+= len;
# Line 4510  for (;;) Line 4803  for (;;)
4803            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4804              {              {
4805              int len = 1;              int len = 1;
4806              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4807                  {
4808                  SCHECK_PARTIAL();
4809                  break;
4810                  }
4811              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4812              if (c >= 256 || (md->ctypes[c] & ctype_word) == 0) break;              if (c >= 256 || (md->ctypes[c] & ctype_word) == 0) break;
4813              eptr+= len;              eptr+= len;
# Line 4542  for (;;) Line 4839  for (;;)
4839            case OP_ANY:            case OP_ANY:
4840            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4841              {              {
4842              if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;              if (eptr >= md->end_subject)
4843                  {
4844                  SCHECK_PARTIAL();
4845                  break;
4846                  }
4847                if (IS_NEWLINE(eptr)) break;
4848              eptr++;              eptr++;
4849              }              }
4850            break;            break;
# Line 4551  for (;;) Line 4853  for (;;)
4853            case OP_ANYBYTE:            case OP_ANYBYTE:
4854            c = max - min;            c = max - min;
4855            if (c > (unsigned int)(md->end_subject - eptr))            if (c > (unsigned int)(md->end_subject - eptr))
4856              c = md->end_subject - eptr;              {
4857            eptr += c;              eptr = md->end_subject;
4858                SCHECK_PARTIAL();
4859                }
4860              else eptr += c;
4861            break;            break;
4862    
4863            case OP_ANYNL:            case OP_ANYNL:
4864            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4865              {              {
4866              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4867                  {
4868                  SCHECK_PARTIAL();
4869                  break;
4870                  }
4871              c = *eptr;              c = *eptr;
4872              if (c == 0x000d)              if (c == 0x000d)
4873                {                {
# Line 4579  for (;;) Line 4888  for (;;)
4888            case OP_NOT_HSPACE:            case OP_NOT_HSPACE:
4889            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4890              {              {
4891              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4892                  {
4893                  SCHECK_PARTIAL();
4894                  break;
4895                  }
4896              c = *eptr;              c = *eptr;
4897              if (c == 0x09 || c == 0x20 || c == 0xa0) break;              if (c == 0x09 || c == 0x20 || c == 0xa0) break;
4898              eptr++;              eptr++;
# Line 4589  for (;;) Line 4902  for (;;)
4902            case OP_HSPACE:            case OP_HSPACE:
4903            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4904              {              {
4905              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4906                  {
4907                  SCHECK_PARTIAL();
4908                  break;
4909                  }
4910              c = *eptr;              c = *eptr;
4911              if (c != 0x09 && c != 0x20 && c != 0xa0) break;              if (c != 0x09 && c != 0x20 && c != 0xa0) break;
4912              eptr++;              eptr++;
# Line 4599  for (;;) Line 4916  for (;;)
4916            case OP_NOT_VSPACE:            case OP_NOT_VSPACE:
4917            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4918              {              {
4919              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4920                  {
4921                  SCHECK_PARTIAL();
4922                  break;
4923                  }
4924              c = *eptr;              c = *eptr;
4925              if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85)              if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85)
4926                break;                break;
# Line 4610  for (;;) Line 4931  for (;;)
4931            case OP_VSPACE:            case OP_VSPACE:
4932            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4933              {              {
4934              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4935                  {
4936                  SCHECK_PARTIAL();
4937                  break;
4938                  }
4939              c = *eptr;              c = *eptr;
4940              if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85)              if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85)
4941                break;                break;
# Line 4621  for (;;) Line 4946  for (;;)
4946            case OP_NOT_DIGIT:            case OP_NOT_DIGIT:
4947            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4948              {              {
4949              if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_digit) != 0)              if (eptr >= md->end_subject)
4950                  {
4951                  SCHECK_PARTIAL();
4952                break;                break;
4953                  }
4954                if ((md->ctypes[*eptr] & ctype_digit) != 0) break;
4955              eptr++;              eptr++;
4956              }              }
4957            break;            break;
# Line 4630  for (;;) Line 4959  for (;;)
4959            case OP_DIGIT:            case OP_DIGIT:
4960            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4961              {              {
4962              if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_digit) == 0)              if (eptr >= md->end_subject)
4963                  {
4964                  SCHECK_PARTIAL();
4965                break;                break;
4966                  }
4967                if ((md->ctypes[*eptr] & ctype_digit) == 0) break;
4968              eptr++;              eptr++;
4969              }              }
4970            break;            break;
# Line 4639  for (;;) Line 4972  for (;;)
4972            case OP_NOT_WHITESPACE:            case OP_NOT_WHITESPACE:
4973            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4974              {              {
4975              if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_space) != 0)              if (eptr >= md->end_subject)
4976                  {
4977                  SCHECK_PARTIAL();
4978                break;                break;
4979                  }
4980                if ((md->ctypes[*eptr] & ctype_space) != 0) break;
4981              eptr++;              eptr++;
4982              }              }
4983            break;            break;
# Line 4648  for (;;) Line 4985  for (;;)
4985            case OP_WHITESPACE:            case OP_WHITESPACE:
4986            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4987              {              {
4988              if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_space) == 0)              if (eptr >= md->end_subject)
4989                  {
4990                  SCHECK_PARTIAL();
4991                break;                break;
4992                  }
4993                if ((md->ctypes[*eptr] & ctype_space) == 0) break;
4994              eptr++;              eptr++;
4995              }              }
4996            break;            break;
# Line 4657  for (;;) Line 4998  for (;;)
4998            case OP_NOT_WORDCHAR:            case OP_NOT_WORDCHAR:
4999            for (i = min; i < max; i++)            for (i = min; i < max; i++)
5000              {              {
5001              if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_word) != 0)              if (eptr >= md->end_subject)
5002                  {
5003                  SCHECK_PARTIAL();
5004                break;                break;
5005                  }
5006                if ((md->ctypes[*eptr] & ctype_word) != 0) break;
5007              eptr++;              eptr++;
5008              }              }
5009            break;            break;
# Line 4666  for (;;) Line 5011  for (;;)
5011            case OP_WORDCHAR:            case OP_WORDCHAR:
5012            for (i = min; i < max; i++)            for (i = min; i < max; i++)
5013              {              {
5014              if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_word) == 0)              if (eptr >= md->end_subject)
5015                  {
5016                  SCHECK_PARTIAL();
5017                break;                break;
5018                  }
5019                if ((md->ctypes[*eptr] & ctype_word) == 0) break;
5020              eptr++;              eptr++;
5021              }              }
5022            break;            break;
# Line 4862  if (re == NULL || subject == NULL || Line 5211  if (re == NULL || subject == NULL ||
5211     (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;     (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;
5212  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;
5213    
5214    /* This information is for finding all the numbers associated with a given
5215    name, for condition testing. */
5216    
5217    md->name_table = (uschar *)re + re->name_table_offset;
5218    md->name_count = re->name_count;
5219    md->name_entry_size = re->name_entry_size;
5220    
5221  /* Fish out the optional data from the extra_data structure, first setting  /* Fish out the optional data from the extra_data structure, first setting
5222  the default values. */  the default values. */
5223    
# Line 5094  if (!anchored) Line 5450  if (!anchored)
5450      }      }
5451    else    else
5452      if (!startline && study != NULL &&      if (!startline && study != NULL &&
5453        (study->options & PCRE_STUDY_MAPPED) != 0)        (study->flags & PCRE_STUDY_MAPPED) != 0)
5454          start_bits = study->start_bits;          start_bits = study->start_bits;
5455    }    }
5456    
# Line 5221  for(;;) Line 5577  for(;;)
5577    
5578    end_subject = save_end_subject;    end_subject = save_end_subject;
5579    
5580  #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  
5581    disabling is explicitly requested. */    disabling is explicitly requested. */
5582    
5583    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)  
5584      {      {
5585      register USPTR p = start_match + ((first_byte >= 0)? 1 : 0);      /* If the pattern was studied, a minimum subject length may be set. This is
5586        a lower bound; no actual string of that length may actually match the
5587        pattern. Although the value is, strictly, in characters, we treat it as
5588        bytes to avoid spending too much time in this optimization. */
5589    
5590      /* We don't need to repeat the search if we haven't yet reached the      if (study != NULL && (study->flags & PCRE_STUDY_MINLEN) != 0 &&
5591      place we found it at last time. */          (pcre_uint32)(end_subject - start_match) < study->minlength)
5592          {
5593          rc = MATCH_NOMATCH;
5594          break;
5595          }
5596    
5597        /* If req_byte is set, we know that that character must appear in the
5598        subject for the match to succeed. If the first character is set, req_byte
5599        must be later in the subject; otherwise the test starts at the match point.
5600        This optimization can save a huge amount of backtracking in patterns with
5601        nested unlimited repeats that aren't going to match. Writing separate code
5602        for cased/caseless versions makes it go faster, as does using an
5603        autoincrement and backing off on a match.
5604    
5605        HOWEVER: when the subject string is very, very long, searching to its end
5606        can take a long time, and give bad performance on quite ordinary patterns.
5607        This showed up when somebody was matching something like /^\d+C/ on a
5608        32-megabyte string... so we don't do this when the string is sufficiently
5609        long. */
5610    
5611      if (p > req_byte_ptr)      if (req_byte >= 0 && end_subject - start_match < REQ_BYTE_MAX)
5612        {        {
5613        if (req_byte_caseless)        register USPTR p = start_match + ((first_byte >= 0)? 1 : 0);
5614    
5615          /* We don't need to repeat the search if we haven't yet reached the
5616          place we found it at last time. */
5617    
5618          if (p > req_byte_ptr)
5619          {          {
5620          while (p < end_subject)          if (req_byte_caseless)
5621            {            {
5622            register int pp = *p++;            while (p < end_subject)
5623            if (pp == req_byte || pp == req_byte2) { p--; break; }              {
5624                register int pp = *p++;
5625                if (pp == req_byte || pp == req_byte2) { p--; break; }
5626                }
5627            }            }
5628          }          else
       else  
         {  
         while (p < end_subject)  
5629            {            {
5630            if (*p++ == req_byte) { p--; break; }            while (p < end_subject)
5631                {
5632                if (*p++ == req_byte) { p--; break; }
5633                }
5634            }            }
         }  
5635    
5636        /* If we can't find the required character, break the matching loop,          /* If we can't find the required character, break the matching loop,
5637        forcing a match failure. */          forcing a match failure. */
5638    
5639        if (p >= end_subject)          if (p >= end_subject)
5640          {            {
5641          rc = MATCH_NOMATCH;            rc = MATCH_NOMATCH;
5642          break;            break;
5643          }            }
5644    
5645        /* If we have found the required character, save the point where we          /* If we have found the required character, save the point where we
5646        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
5647        the start hasn't passed this character yet. */          the start hasn't passed this character yet. */
5648    
5649        req_byte_ptr = p;          req_byte_ptr = p;
5650            }
5651        }        }
5652      }      }
5653    
5654    #ifdef PCRE_DEBUG  /* Sigh. Some compilers never learn. */
5655      printf(">>>> Match against: ");
5656      pchars(start_match, end_subject - start_match, TRUE, md);
5657      printf("\n");
5658    #endif
5659    
5660    /* 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
5661    first starting point for which a partial match was found. */    first starting point for which a partial match was found. */
5662    
5663    md->start_match_ptr = start_match;    md->start_match_ptr = start_match;
5664    md->start_used_ptr = start_match;    md->start_used_ptr = start_match;
5665    md->match_call_count = 0;    md->match_call_count = 0;
5666    rc = match(start_match, md->start_code, start_match, 2, md, ims, NULL, 0, 0);    rc = match(start_match, md->start_code, start_match, NULL, 2, md, ims, NULL,
5667        0, 0);
5668    if (md->hitend && start_partial == NULL) start_partial = md->start_used_ptr;    if (md->hitend && start_partial == NULL) start_partial = md->start_used_ptr;
5669    
5670    switch(rc)    switch(rc)

Legend:
Removed from v.444  
changed lines
  Added in v.501

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12