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

Diff of /code/trunk/pcre_dfa_exec.c

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

revision 152 by ph10, Tue Apr 17 15:55:53 2007 UTC revision 567 by ph10, Sat Nov 6 17:10:00 2010 UTC
# Line 3  Line 3 
3  *************************************************/  *************************************************/
4    
5  /* PCRE is a library of functions to support regular expressions whose syntax  /* PCRE is a library of functions to support regular expressions whose syntax
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 (but see
7    below for why this module is different).
8    
9                         Written by Philip Hazel                         Written by Philip Hazel
10             Copyright (c) 1997-2007 University of Cambridge             Copyright (c) 1997-2010 University of Cambridge
11    
12  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
13  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 44  FSM). This is NOT Perl- compatible, but Line 45  FSM). This is NOT Perl- compatible, but
45  applications. */  applications. */
46    
47    
48    /* NOTE ABOUT PERFORMANCE: A user of this function sent some code that improved
49    the performance of his patterns greatly. I could not use it as it stood, as it
50    was not thread safe, and made assumptions about pattern sizes. Also, it caused
51    test 7 to loop, and test 9 to crash with a segfault.
52    
53    The issue is the check for duplicate states, which is done by a simple linear
54    search up the state list. (Grep for "duplicate" below to find the code.) For
55    many patterns, there will never be many states active at one time, so a simple
56    linear search is fine. In patterns that have many active states, it might be a
57    bottleneck. The suggested code used an indexing scheme to remember which states
58    had previously been used for each character, and avoided the linear search when
59    it knew there was no chance of a duplicate. This was implemented when adding
60    states to the state lists.
61    
62    I wrote some thread-safe, not-limited code to try something similar at the time
63    of checking for duplicates (instead of when adding states), using index vectors
64    on the stack. It did give a 13% improvement with one specially constructed
65    pattern for certain subject strings, but on other strings and on many of the
66    simpler patterns in the test suite it did worse. The major problem, I think,
67    was the extra time to initialize the index. This had to be done for each call
68    of internal_dfa_exec(). (The supplied patch used a static vector, initialized
69    only once - I suspect this was the cause of the problems with the tests.)
70    
71    Overall, I concluded that the gains in some cases did not outweigh the losses
72    in others, so I abandoned this code. */
73    
74    
75    
76    #ifdef HAVE_CONFIG_H
77    #include "config.h"
78    #endif
79    
80  #define NLBLOCK md             /* Block containing newline information */  #define NLBLOCK md             /* Block containing newline information */
81  #define PSSTART start_subject  /* Field containing processed string start */  #define PSSTART start_subject  /* Field containing processed string start */
82  #define PSEND   end_subject    /* Field containing processed string end */  #define PSEND   end_subject    /* Field containing processed string end */
# Line 56  applications. */ Line 89  applications. */
89  #define SP "                   "  #define SP "                   "
90    
91    
   
92  /*************************************************  /*************************************************
93  *      Code parameters and static tables         *  *      Code parameters and static tables         *
94  *************************************************/  *************************************************/
95    
96  /* These are offsets that are used to turn the OP_TYPESTAR and friends opcodes  /* These are offsets that are used to turn the OP_TYPESTAR and friends opcodes
97  into others, under special conditions. A gap of 20 between the blocks should be  into others, under special conditions. A gap of 20 between the blocks should be
98  enough. */  enough. The resulting opcodes don't have to be less than 256 because they are
99    never stored, so we push them well clear of the normal opcodes. */
100    
101  #define OP_PROP_EXTRA 100  #define OP_PROP_EXTRA       300
102  #define OP_EXTUNI_EXTRA 120  #define OP_EXTUNI_EXTRA     320
103  #define OP_ANYNL_EXTRA 140  #define OP_ANYNL_EXTRA      340
104    #define OP_HSPACE_EXTRA     360
105    #define OP_VSPACE_EXTRA     380
106    
107    
108  /* This table identifies those opcodes that are followed immediately by a  /* This table identifies those opcodes that are followed immediately by a
109  character that is to be tested in some way. This makes is possible to  character that is to be tested in some way. This makes it possible to
110  centralize the loading of these characters. In the case of Type * etc, the  centralize the loading of these characters. In the case of Type * etc, the
111  "character" is the opcode for \D, \d, \S, \s, \W, or \w, which will always be a  "character" is the opcode for \D, \d, \S, \s, \W, or \w, which will always be a
112  small value. */  small value. Non-zero values in the table are the offsets from the opcode where
113    the character is to be found. ***NOTE*** If the start of this table is
114    modified, the three tables that follow must also be modified. */
115    
116  static uschar coptable[] = {  static const uschar coptable[] = {
117    0,                             /* End                                    */    0,                             /* End                                    */
118    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* \A, \G, \B, \b, \D, \d, \S, \s, \W, \w */    0, 0, 0, 0, 0,                 /* \A, \G, \K, \B, \b                     */
119    0, 0,                          /* Any, Anybyte                           */    0, 0, 0, 0, 0, 0,              /* \D, \d, \S, \s, \W, \w                 */
120    0, 0, 0, 0,                    /* NOTPROP, PROP, EXTUNI, ANYNL           */    0, 0, 0,                       /* Any, AllAny, Anybyte                   */
121      0, 0,                          /* \P, \p                                 */
122      0, 0, 0, 0, 0,                 /* \R, \H, \h, \V, \v                     */
123      0,                             /* \X                                     */
124    0, 0, 0, 0, 0,                 /* \Z, \z, Opt, ^, $                      */    0, 0, 0, 0, 0,                 /* \Z, \z, Opt, ^, $                      */
125    1,                             /* Char                                   */    1,                             /* Char                                   */
126    1,                             /* Charnc                                 */    1,                             /* Charnc                                 */
# Line 117  static uschar coptable[] = { Line 157  static uschar coptable[] = {
157    0,                             /* Reverse                                */    0,                             /* Reverse                                */
158    0, 0, 0, 0,                    /* ONCE, BRA, CBRA, COND                  */    0, 0, 0, 0,                    /* ONCE, BRA, CBRA, COND                  */
159    0, 0, 0,                       /* SBRA, SCBRA, SCOND                     */    0, 0, 0,                       /* SBRA, SCBRA, SCOND                     */
160    0,                             /* CREF                                   */    0, 0,                          /* CREF, NCREF                            */
161    0,                             /* RREF                                   */    0, 0,                          /* RREF, NRREF                            */
162      0,                             /* DEF                                    */
163      0, 0,                          /* BRAZERO, BRAMINZERO                    */
164      0, 0, 0,                       /* MARK, PRUNE, PRUNE_ARG,                */
165      0, 0, 0, 0,                    /* SKIP, SKIP_ARG, THEN, THEN_ARG,        */
166      0, 0, 0, 0, 0                  /* COMMIT, FAIL, ACCEPT, CLOSE, SKIPZERO  */
167    };
168    
169    /* This table identifies those opcodes that inspect a character. It is used to
170    remember the fact that a character could have been inspected when the end of
171    the subject is reached. ***NOTE*** If the start of this table is modified, the
172    two tables that follow must also be modified. */
173    
174    static const uschar poptable[] = {
175      0,                             /* End                                    */
176      0, 0, 0, 1, 1,                 /* \A, \G, \K, \B, \b                     */
177      1, 1, 1, 1, 1, 1,              /* \D, \d, \S, \s, \W, \w                 */
178      1, 1, 1,                       /* Any, AllAny, Anybyte                   */
179      1, 1,                          /* \P, \p                                 */
180      1, 1, 1, 1, 1,                 /* \R, \H, \h, \V, \v                     */
181      1,                             /* \X                                     */
182      0, 0, 0, 0, 0,                 /* \Z, \z, Opt, ^, $                      */
183      1,                             /* Char                                   */
184      1,                             /* Charnc                                 */
185      1,                             /* not                                    */
186      /* Positive single-char repeats                                          */
187      1, 1, 1, 1, 1, 1,              /* *, *?, +, +?, ?, ??                    */
188      1, 1, 1,                       /* upto, minupto, exact                   */
189      1, 1, 1, 1,                    /* *+, ++, ?+, upto+                      */
190      /* Negative single-char repeats - only for chars < 256                   */
191      1, 1, 1, 1, 1, 1,              /* NOT *, *?, +, +?, ?, ??                */
192      1, 1, 1,                       /* NOT upto, minupto, exact               */
193      1, 1, 1, 1,                    /* NOT *+, ++, ?+, upto+                  */
194      /* Positive type repeats                                                 */
195      1, 1, 1, 1, 1, 1,              /* Type *, *?, +, +?, ?, ??               */
196      1, 1, 1,                       /* Type upto, minupto, exact              */
197      1, 1, 1, 1,                    /* Type *+, ++, ?+, upto+                 */
198      /* Character class & ref repeats                                         */
199      1, 1, 1, 1, 1, 1,              /* *, *?, +, +?, ?, ??                    */
200      1, 1,                          /* CRRANGE, CRMINRANGE                    */
201      1,                             /* CLASS                                  */
202      1,                             /* NCLASS                                 */
203      1,                             /* XCLASS - variable length               */
204      0,                             /* REF                                    */
205      0,                             /* RECURSE                                */
206      0,                             /* CALLOUT                                */
207      0,                             /* Alt                                    */
208      0,                             /* Ket                                    */
209      0,                             /* KetRmax                                */
210      0,                             /* KetRmin                                */
211      0,                             /* Assert                                 */
212      0,                             /* Assert not                             */
213      0,                             /* Assert behind                          */
214      0,                             /* Assert behind not                      */
215      0,                             /* Reverse                                */
216      0, 0, 0, 0,                    /* ONCE, BRA, CBRA, COND                  */
217      0, 0, 0,                       /* SBRA, SCBRA, SCOND                     */
218      0, 0,                          /* CREF, NCREF                            */
219      0, 0,                          /* RREF, NRREF                            */
220    0,                             /* DEF                                    */    0,                             /* DEF                                    */
221    0, 0                           /* BRAZERO, BRAMINZERO                    */    0, 0,                          /* BRAZERO, BRAMINZERO                    */
222      0, 0, 0,                       /* MARK, PRUNE, PRUNE_ARG,                */
223      0, 0, 0, 0,                    /* SKIP, SKIP_ARG, THEN, THEN_ARG,        */
224      0, 0, 0, 0, 0                  /* COMMIT, FAIL, ACCEPT, CLOSE, SKIPZERO  */
225  };  };
226    
227  /* These 2 tables allow for compact code for testing for \D, \d, \S, \s, \W,  /* These 2 tables allow for compact code for testing for \D, \d, \S, \s, \W,
228  and \w */  and \w */
229    
230  static uschar toptable1[] = {  static const uschar toptable1[] = {
231    0, 0, 0, 0, 0,    0, 0, 0, 0, 0, 0,
232    ctype_digit, ctype_digit,    ctype_digit, ctype_digit,
233    ctype_space, ctype_space,    ctype_space, ctype_space,
234    ctype_word,  ctype_word,    ctype_word,  ctype_word,
235    0                               /* OP_ANY */    0, 0                            /* OP_ANY, OP_ALLANY */
236  };  };
237    
238  static uschar toptable2[] = {  static const uschar toptable2[] = {
239    0, 0, 0, 0, 0,    0, 0, 0, 0, 0, 0,
240    ctype_digit, 0,    ctype_digit, 0,
241    ctype_space, 0,    ctype_space, 0,
242    ctype_word,  0,    ctype_word,  0,
243    1                               /* OP_ANY */    1, 1                            /* OP_ANY, OP_ALLANY */
244  };  };
245    
246    
# Line 158  typedef struct stateblock { Line 259  typedef struct stateblock {
259  #define INTS_PER_STATEBLOCK  (sizeof(stateblock)/sizeof(int))  #define INTS_PER_STATEBLOCK  (sizeof(stateblock)/sizeof(int))
260    
261    
262  #ifdef DEBUG  #ifdef PCRE_DEBUG
263  /*************************************************  /*************************************************
264  *             Print character string             *  *             Print character string             *
265  *************************************************/  *************************************************/
# Line 211  Arguments: Line 312  Arguments:
312    rlevel            function call recursion level    rlevel            function call recursion level
313    recursing         regex recursive call level    recursing         regex recursive call level
314    
315  Returns:            > 0 =>  Returns:            > 0 => number of match offset pairs placed in offsets
316                      = 0 =>                      = 0 => offsets overflowed; longest matches are present
317                       -1 => failed to match                       -1 => failed to match
318                     < -1 => some kind of unexpected problem                     < -1 => some kind of unexpected problem
319    
# Line 374  if (*first_op == OP_REVERSE) Line 475  if (*first_op == OP_REVERSE)
475    
476      {      {
477      gone_back = (current_subject - max_back < start_subject)?      gone_back = (current_subject - max_back < start_subject)?
478        current_subject - start_subject : max_back;        (int)(current_subject - start_subject) : max_back;
479      current_subject -= gone_back;      current_subject -= gone_back;
480      }      }
481    
482      /* Save the earliest consulted character */
483    
484      if (current_subject < md->start_used_ptr)
485        md->start_used_ptr = current_subject;
486    
487    /* Now we can process the individual branches. */    /* Now we can process the individual branches. */
488    
489    end_code = this_start_code;    end_code = this_start_code;
# Line 386  if (*first_op == OP_REVERSE) Line 492  if (*first_op == OP_REVERSE)
492      int back = GET(end_code, 2+LINK_SIZE);      int back = GET(end_code, 2+LINK_SIZE);
493      if (back <= gone_back)      if (back <= gone_back)
494        {        {
495        int bstate = end_code - start_code + 2 + 2*LINK_SIZE;        int bstate = (int)(end_code - start_code + 2 + 2*LINK_SIZE);
496        ADD_NEW_DATA(-bstate, 0, gone_back - back);        ADD_NEW_DATA(-bstate, 0, gone_back - back);
497        }        }
498      end_code += GET(end_code, 1);      end_code += GET(end_code, 1);
# Line 422  else Line 528  else
528        ((*this_start_code == OP_CBRA || *this_start_code == OP_SCBRA)? 2:0);        ((*this_start_code == OP_CBRA || *this_start_code == OP_SCBRA)? 2:0);
529      do      do
530        {        {
531        ADD_NEW(end_code - start_code + length, 0);        ADD_NEW((int)(end_code - start_code + length), 0);
532        end_code += GET(end_code, 1);        end_code += GET(end_code, 1);
533        length = 1 + LINK_SIZE;        length = 1 + LINK_SIZE;
534        }        }
# Line 442  for (;;) Line 548  for (;;)
548    int i, j;    int i, j;
549    int clen, dlen;    int clen, dlen;
550    unsigned int c, d;    unsigned int c, d;
551      int forced_fail = 0;
552      BOOL could_continue = FALSE;
553    
554    /* Make the new state list into the active state list and empty the    /* Make the new state list into the active state list and empty the
555    new state list. */    new state list. */
# Line 455  for (;;) Line 563  for (;;)
563    workspace[0] ^= 1;              /* Remember for the restarting feature */    workspace[0] ^= 1;              /* Remember for the restarting feature */
564    workspace[1] = active_count;    workspace[1] = active_count;
565    
566  #ifdef DEBUG  #ifdef PCRE_DEBUG
567    printf("%.*sNext character: rest of subject = \"", rlevel*2-2, SP);    printf("%.*sNext character: rest of subject = \"", rlevel*2-2, SP);
568    pchars((uschar *)ptr, strlen((char *)ptr), stdout);    pchars((uschar *)ptr, strlen((char *)ptr), stdout);
569    printf("\"\n");    printf("\"\n");
# Line 499  for (;;) Line 607  for (;;)
607      stateblock *current_state = active_states + i;      stateblock *current_state = active_states + i;
608      const uschar *code;      const uschar *code;
609      int state_offset = current_state->offset;      int state_offset = current_state->offset;
610      int count, codevalue;      int count, codevalue, rrc;
 #ifdef SUPPORT_UCP  
     int chartype, script;  
 #endif  
611    
612  #ifdef DEBUG  #ifdef PCRE_DEBUG
613      printf ("%.*sProcessing state %d c=", rlevel*2-2, SP, state_offset);      printf ("%.*sProcessing state %d c=", rlevel*2-2, SP, state_offset);
614      if (clen == 0) printf("EOL\n");      if (clen == 0) printf("EOL\n");
615        else if (c > 32 && c < 127) printf("'%c'\n", c);        else if (c > 32 && c < 127) printf("'%c'\n", c);
# Line 534  for (;;) Line 639  for (;;)
639          }          }
640        }        }
641    
642      /* Check for a duplicate state with the same count, and skip if found. */      /* Check for a duplicate state with the same count, and skip if found.
643        See the note at the head of this module about the possibility of improving
644        performance here. */
645    
646      for (j = 0; j < i; j++)      for (j = 0; j < i; j++)
647        {        {
# Line 551  for (;;) Line 658  for (;;)
658      code = start_code + state_offset;      code = start_code + state_offset;
659      codevalue = *code;      codevalue = *code;
660    
661        /* If this opcode inspects a character, but we are at the end of the
662        subject, remember the fact for use when testing for a partial match. */
663    
664        if (clen == 0 && poptable[codevalue] != 0)
665          could_continue = TRUE;
666    
667      /* If this opcode is followed by an inline character, load it. It is      /* If this opcode is followed by an inline character, load it. It is
668      tempting to test for the presence of a subject character here, but that      tempting to test for the presence of a subject character here, but that
669      is wrong, because sometimes zero repetitions of the subject are      is wrong, because sometimes zero repetitions of the subject are
670      permitted.      permitted.
671    
672      We also use this mechanism for opcodes such as OP_TYPEPLUS that take an      We also use this mechanism for opcodes such as OP_TYPEPLUS that take an
673      argument that is not a data character - but is always one byte long.      argument that is not a data character - but is always one byte long. We
674      Unfortunately, we have to take special action to deal with  \P, \p, and      have to take special action to deal with  \P, \p, \H, \h, \V, \v and \X in
675      \X in this case. To keep the other cases fast, convert these ones to new      this case. To keep the other cases fast, convert these ones to new opcodes.
676      opcodes. */      */
677    
678      if (coptable[codevalue] > 0)      if (coptable[codevalue] > 0)
679        {        {
# Line 578  for (;;) Line 691  for (;;)
691            case OP_PROP: codevalue += OP_PROP_EXTRA; break;            case OP_PROP: codevalue += OP_PROP_EXTRA; break;
692            case OP_ANYNL: codevalue += OP_ANYNL_EXTRA; break;            case OP_ANYNL: codevalue += OP_ANYNL_EXTRA; break;
693            case OP_EXTUNI: codevalue += OP_EXTUNI_EXTRA; break;            case OP_EXTUNI: codevalue += OP_EXTUNI_EXTRA; break;
694              case OP_NOT_HSPACE:
695              case OP_HSPACE: codevalue += OP_HSPACE_EXTRA; break;
696              case OP_NOT_VSPACE:
697              case OP_VSPACE: codevalue += OP_VSPACE_EXTRA; break;
698            default: break;            default: break;
699            }            }
700          }          }
# Line 593  for (;;) Line 710  for (;;)
710    
711      switch (codevalue)      switch (codevalue)
712        {        {
713    /* ========================================================================== */
714          /* These cases are never obeyed. This is a fudge that causes a compile-
715          time error if the vectors coptable or poptable, which are indexed by
716          opcode, are not the correct length. It seems to be the only way to do
717          such a check at compile time, as the sizeof() operator does not work
718          in the C preprocessor. */
719    
720          case OP_TABLE_LENGTH:
721          case OP_TABLE_LENGTH +
722            ((sizeof(coptable) == OP_TABLE_LENGTH) &&
723             (sizeof(poptable) == OP_TABLE_LENGTH)):
724          break;
725    
726  /* ========================================================================== */  /* ========================================================================== */
727        /* Reached a closing bracket. If not at the end of the pattern, carry        /* Reached a closing bracket. If not at the end of the pattern, carry
728        on with the next opcode. Otherwise, unless we have an empty string and        on with the next opcode. Otherwise, unless we have an empty string and
729        PCRE_NOTEMPTY is set, save the match data, shifting up all previous        PCRE_NOTEMPTY is set, or PCRE_NOTEMPTY_ATSTART is set and we are at the
730          start of the subject, save the match data, shifting up all previous
731        matches so we always have the longest first. */        matches so we always have the longest first. */
732    
733        case OP_KET:        case OP_KET:
# Line 611  for (;;) Line 741  for (;;)
741            ADD_ACTIVE(state_offset - GET(code, 1), 0);            ADD_ACTIVE(state_offset - GET(code, 1), 0);
742            }            }
743          }          }
744        else if (ptr > current_subject || (md->moptions & PCRE_NOTEMPTY) == 0)        else
745          {          {
746          if (match_count < 0) match_count = (offsetcount >= 2)? 1 : 0;          if (ptr > current_subject ||
747            else if (match_count > 0 && ++match_count * 2 >= offsetcount)              ((md->moptions & PCRE_NOTEMPTY) == 0 &&
748              match_count = 0;                ((md->moptions & PCRE_NOTEMPTY_ATSTART) == 0 ||
749          count = ((match_count == 0)? offsetcount : match_count * 2) - 2;                  current_subject > start_subject + md->start_offset)))
750          if (count > 0) memmove(offsets + 2, offsets, count * sizeof(int));            {
751          if (offsetcount >= 2)            if (match_count < 0) match_count = (offsetcount >= 2)? 1 : 0;
752            {              else if (match_count > 0 && ++match_count * 2 >= offsetcount)
753            offsets[0] = current_subject - start_subject;                match_count = 0;
754            offsets[1] = ptr - start_subject;            count = ((match_count == 0)? offsetcount : match_count * 2) - 2;
755            DPRINTF(("%.*sSet matched string = \"%.*s\"\n", rlevel*2-2, SP,            if (count > 0) memmove(offsets + 2, offsets, count * sizeof(int));
756              offsets[1] - offsets[0], current_subject));            if (offsetcount >= 2)
757            }              {
758          if ((md->moptions & PCRE_DFA_SHORTEST) != 0)              offsets[0] = (int)(current_subject - start_subject);
759            {              offsets[1] = (int)(ptr - start_subject);
760            DPRINTF(("%.*sEnd of internal_dfa_exec %d: returning %d\n"              DPRINTF(("%.*sSet matched string = \"%.*s\"\n", rlevel*2-2, SP,
761              "%.*s---------------------\n\n", rlevel*2-2, SP, rlevel,                offsets[1] - offsets[0], current_subject));
762              match_count, rlevel*2-2, SP));              }
763            return match_count;            if ((md->moptions & PCRE_DFA_SHORTEST) != 0)
764                {
765                DPRINTF(("%.*sEnd of internal_dfa_exec %d: returning %d\n"
766                  "%.*s---------------------\n\n", rlevel*2-2, SP, rlevel,
767                  match_count, rlevel*2-2, SP));
768                return match_count;
769                }
770            }            }
771          }          }
772        break;        break;
# Line 642  for (;;) Line 778  for (;;)
778        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
779        case OP_ALT:        case OP_ALT:
780        do { code += GET(code, 1); } while (*code == OP_ALT);        do { code += GET(code, 1); } while (*code == OP_ALT);
781        ADD_ACTIVE(code - start_code, 0);        ADD_ACTIVE((int)(code - start_code), 0);
782        break;        break;
783    
784        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
# Line 650  for (;;) Line 786  for (;;)
786        case OP_SBRA:        case OP_SBRA:
787        do        do
788          {          {
789          ADD_ACTIVE(code - start_code + 1 + LINK_SIZE, 0);          ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE), 0);
790          code += GET(code, 1);          code += GET(code, 1);
791          }          }
792        while (*code == OP_ALT);        while (*code == OP_ALT);
# Line 659  for (;;) Line 795  for (;;)
795        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
796        case OP_CBRA:        case OP_CBRA:
797        case OP_SCBRA:        case OP_SCBRA:
798        ADD_ACTIVE(code - start_code + 3 + LINK_SIZE,  0);        ADD_ACTIVE((int)(code - start_code + 3 + LINK_SIZE),  0);
799        code += GET(code, 1);        code += GET(code, 1);
800        while (*code == OP_ALT)        while (*code == OP_ALT)
801          {          {
802          ADD_ACTIVE(code - start_code + 1 + LINK_SIZE,  0);          ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE),  0);
803          code += GET(code, 1);          code += GET(code, 1);
804          }          }
805        break;        break;
# Line 674  for (;;) Line 810  for (;;)
810        ADD_ACTIVE(state_offset + 1, 0);        ADD_ACTIVE(state_offset + 1, 0);
811        code += 1 + GET(code, 2);        code += 1 + GET(code, 2);
812        while (*code == OP_ALT) code += GET(code, 1);        while (*code == OP_ALT) code += GET(code, 1);
813        ADD_ACTIVE(code - start_code + 1 + LINK_SIZE, 0);        ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE), 0);
814          break;
815    
816          /*-----------------------------------------------------------------*/
817          case OP_SKIPZERO:
818          code += 1 + GET(code, 2);
819          while (*code == OP_ALT) code += GET(code, 1);
820          ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE), 0);
821        break;        break;
822    
823        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
# Line 688  for (;;) Line 831  for (;;)
831    
832        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
833        case OP_EOD:        case OP_EOD:
834        if (ptr >= end_subject) { ADD_ACTIVE(state_offset + 1, 0); }        if (ptr >= end_subject)
835            {
836            if ((md->moptions & PCRE_PARTIAL_HARD) != 0)
837              could_continue = TRUE;
838            else { ADD_ACTIVE(state_offset + 1, 0); }
839            }
840        break;        break;
841    
842        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
# Line 716  for (;;) Line 864  for (;;)
864    
865        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
866        case OP_ANY:        case OP_ANY:
867        if (clen > 0 && ((ims & PCRE_DOTALL) != 0 || !IS_NEWLINE(ptr)))        if (clen > 0 && !IS_NEWLINE(ptr))
868            { ADD_NEW(state_offset + 1, 0); }
869          break;
870    
871          /*-----------------------------------------------------------------*/
872          case OP_ALLANY:
873          if (clen > 0)
874          { ADD_NEW(state_offset + 1, 0); }          { ADD_NEW(state_offset + 1, 0); }
875        break;        break;
876    
877        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
878        case OP_EODN:        case OP_EODN:
879        if (clen == 0 || (IS_NEWLINE(ptr) && ptr == end_subject - md->nllen))        if (clen == 0 && (md->moptions & PCRE_PARTIAL_HARD) != 0)
880            could_continue = TRUE;
881          else if (clen == 0 || (IS_NEWLINE(ptr) && ptr == end_subject - md->nllen))
882          { ADD_ACTIVE(state_offset + 1, 0); }          { ADD_ACTIVE(state_offset + 1, 0); }
883        break;        break;
884    
# Line 730  for (;;) Line 886  for (;;)
886        case OP_DOLL:        case OP_DOLL:
887        if ((md->moptions & PCRE_NOTEOL) == 0)        if ((md->moptions & PCRE_NOTEOL) == 0)
888          {          {
889          if (clen == 0 ||          if (clen == 0 && (md->moptions & PCRE_PARTIAL_HARD) != 0)
890              (IS_NEWLINE(ptr) &&            could_continue = TRUE;
891            else if (clen == 0 ||
892                ((md->poptions & PCRE_DOLLAR_ENDONLY) == 0 && IS_NEWLINE(ptr) &&
893                 ((ims & PCRE_MULTILINE) != 0 || ptr == end_subject - md->nllen)                 ((ims & PCRE_MULTILINE) != 0 || ptr == end_subject - md->nllen)
894              ))              ))
895            { ADD_ACTIVE(state_offset + 1, 0); }            { ADD_ACTIVE(state_offset + 1, 0); }
# Line 768  for (;;) Line 926  for (;;)
926          if (ptr > start_subject)          if (ptr > start_subject)
927            {            {
928            const uschar *temp = ptr - 1;            const uschar *temp = ptr - 1;
929              if (temp < md->start_used_ptr) md->start_used_ptr = temp;
930  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
931            if (utf8) BACKCHAR(temp);            if (utf8) BACKCHAR(temp);
932  #endif  #endif
933            GETCHARTEST(d, temp);            GETCHARTEST(d, temp);
934    #ifdef SUPPORT_UCP
935              if ((md->poptions & PCRE_UCP) != 0)
936                {
937                if (d == '_') left_word = TRUE; else
938                  {
939                  int cat = UCD_CATEGORY(d);
940                  left_word = (cat == ucp_L || cat == ucp_N);
941                  }
942                }
943              else
944    #endif
945            left_word = d < 256 && (ctypes[d] & ctype_word) != 0;            left_word = d < 256 && (ctypes[d] & ctype_word) != 0;
946            }            }
947          else left_word = 0;          else left_word = FALSE;
948    
949          if (clen > 0) right_word = c < 256 && (ctypes[c] & ctype_word) != 0;          if (clen > 0)
950            else right_word = 0;            {
951    #ifdef SUPPORT_UCP
952              if ((md->poptions & PCRE_UCP) != 0)
953                {
954                if (c == '_') right_word = TRUE; else
955                  {
956                  int cat = UCD_CATEGORY(c);
957                  right_word = (cat == ucp_L || cat == ucp_N);
958                  }
959                }
960              else
961    #endif
962              right_word = c < 256 && (ctypes[c] & ctype_word) != 0;
963              }
964            else right_word = FALSE;
965    
966          if ((left_word == right_word) == (codevalue == OP_NOT_WORD_BOUNDARY))          if ((left_word == right_word) == (codevalue == OP_NOT_WORD_BOUNDARY))
967            { ADD_ACTIVE(state_offset + 1, 0); }            { ADD_ACTIVE(state_offset + 1, 0); }
# Line 796  for (;;) Line 980  for (;;)
980        if (clen > 0)        if (clen > 0)
981          {          {
982          BOOL OK;          BOOL OK;
983          int category = _pcre_ucp_findprop(c, &chartype, &script);          const ucd_record * prop = GET_UCD(c);
984          switch(code[1])          switch(code[1])
985            {            {
986            case PT_ANY:            case PT_ANY:
# Line 804  for (;;) Line 988  for (;;)
988            break;            break;
989    
990            case PT_LAMP:            case PT_LAMP:
991            OK = chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt;            OK = prop->chartype == ucp_Lu || prop->chartype == ucp_Ll ||
992                   prop->chartype == ucp_Lt;
993            break;            break;
994    
995            case PT_GC:            case PT_GC:
996            OK = category == code[2];            OK = _pcre_ucp_gentype[prop->chartype] == code[2];
997            break;            break;
998    
999            case PT_PC:            case PT_PC:
1000            OK = chartype == code[2];            OK = prop->chartype == code[2];
1001            break;            break;
1002    
1003            case PT_SC:            case PT_SC:
1004            OK = script == code[2];            OK = prop->script == code[2];
1005              break;
1006    
1007              /* These are specials for combination cases. */
1008    
1009              case PT_ALNUM:
1010              OK = _pcre_ucp_gentype[prop->chartype] == ucp_L ||
1011                   _pcre_ucp_gentype[prop->chartype] == ucp_N;
1012              break;
1013    
1014              case PT_SPACE:    /* Perl space */
1015              OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z ||
1016                   c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR;
1017              break;
1018    
1019              case PT_PXSPACE:  /* POSIX space */
1020              OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z ||
1021                   c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
1022                   c == CHAR_FF || c == CHAR_CR;
1023              break;
1024    
1025              case PT_WORD:
1026              OK = _pcre_ucp_gentype[prop->chartype] == ucp_L ||
1027                   _pcre_ucp_gentype[prop->chartype] == ucp_N ||
1028                   c == CHAR_UNDERSCORE;
1029            break;            break;
1030    
1031            /* Should never occur, but keep compilers from grumbling. */            /* Should never occur, but keep compilers from grumbling. */
# Line 836  for (;;) Line 1045  for (;;)
1045  /* ========================================================================== */  /* ========================================================================== */
1046        /* These opcodes likewise inspect the subject character, but have an        /* These opcodes likewise inspect the subject character, but have an
1047        argument that is not a data character. It is one of these opcodes:        argument that is not a data character. It is one of these opcodes:
1048        OP_ANY, OP_DIGIT, OP_NOT_DIGIT, OP_WHITESPACE, OP_NOT_SPACE, OP_WORDCHAR,        OP_ANY, OP_ALLANY, OP_DIGIT, OP_NOT_DIGIT, OP_WHITESPACE, OP_NOT_SPACE,
1049        OP_NOT_WORDCHAR. The value is loaded into d. */        OP_WORDCHAR, OP_NOT_WORDCHAR. The value is loaded into d. */
1050    
1051        case OP_TYPEPLUS:        case OP_TYPEPLUS:
1052        case OP_TYPEMINPLUS:        case OP_TYPEMINPLUS:
# Line 848  for (;;) Line 1057  for (;;)
1057          {          {
1058          if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||          if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
1059              (c < 256 &&              (c < 256 &&
1060                (d != OP_ANY ||                (d != OP_ANY || !IS_NEWLINE(ptr)) &&
                (ims & PCRE_DOTALL) != 0 ||  
                !IS_NEWLINE(ptr)  
               ) &&  
1061                ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))                ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
1062            {            {
1063            if (count > 0 && codevalue == OP_TYPEPOSPLUS)            if (count > 0 && codevalue == OP_TYPEPOSPLUS)
# Line 874  for (;;) Line 1080  for (;;)
1080          {          {
1081          if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||          if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
1082              (c < 256 &&              (c < 256 &&
1083                (d != OP_ANY ||                (d != OP_ANY || !IS_NEWLINE(ptr)) &&
                (ims & PCRE_DOTALL) != 0 ||  
                !IS_NEWLINE(ptr)  
               ) &&  
1084                ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))                ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
1085            {            {
1086            if (codevalue == OP_TYPEPOSQUERY)            if (codevalue == OP_TYPEPOSQUERY)
# Line 899  for (;;) Line 1102  for (;;)
1102          {          {
1103          if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||          if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
1104              (c < 256 &&              (c < 256 &&
1105                (d != OP_ANY ||                (d != OP_ANY || !IS_NEWLINE(ptr)) &&
                (ims & PCRE_DOTALL) != 0 ||  
                !IS_NEWLINE(ptr)  
               ) &&  
1106                ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))                ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
1107            {            {
1108            if (codevalue == OP_TYPEPOSSTAR)            if (codevalue == OP_TYPEPOSSTAR)
# Line 922  for (;;) Line 1122  for (;;)
1122          {          {
1123          if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||          if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
1124              (c < 256 &&              (c < 256 &&
1125                (d != OP_ANY ||                (d != OP_ANY || !IS_NEWLINE(ptr)) &&
                (ims & PCRE_DOTALL) != 0 ||  
                !IS_NEWLINE(ptr)  
               ) &&  
1126                ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))                ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
1127            {            {
1128            if (++count >= GET2(code, 1))            if (++count >= GET2(code, 1))
# Line 946  for (;;) Line 1143  for (;;)
1143          {          {
1144          if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||          if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
1145              (c < 256 &&              (c < 256 &&
1146                (d != OP_ANY ||                (d != OP_ANY || !IS_NEWLINE(ptr)) &&
                (ims & PCRE_DOTALL) != 0 ||  
                !IS_NEWLINE(ptr)  
               ) &&  
1147                ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))                ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
1148            {            {
1149            if (codevalue == OP_TYPEPOSUPTO)            if (codevalue == OP_TYPEPOSUPTO)
# Line 980  for (;;) Line 1174  for (;;)
1174        if (clen > 0)        if (clen > 0)
1175          {          {
1176          BOOL OK;          BOOL OK;
1177          int category = _pcre_ucp_findprop(c, &chartype, &script);          const ucd_record * prop = GET_UCD(c);
1178          switch(code[2])          switch(code[2])
1179            {            {
1180            case PT_ANY:            case PT_ANY:
# Line 988  for (;;) Line 1182  for (;;)
1182            break;            break;
1183    
1184            case PT_LAMP:            case PT_LAMP:
1185            OK = chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt;            OK = prop->chartype == ucp_Lu || prop->chartype == ucp_Ll ||
1186                prop->chartype == ucp_Lt;
1187            break;            break;
1188    
1189            case PT_GC:            case PT_GC:
1190            OK = category == code[3];            OK = _pcre_ucp_gentype[prop->chartype] == code[3];
1191            break;            break;
1192    
1193            case PT_PC:            case PT_PC:
1194            OK = chartype == code[3];            OK = prop->chartype == code[3];
1195            break;            break;
1196    
1197            case PT_SC:            case PT_SC:
1198            OK = script == code[3];            OK = prop->script == code[3];
1199              break;
1200    
1201              /* These are specials for combination cases. */
1202    
1203              case PT_ALNUM:
1204              OK = _pcre_ucp_gentype[prop->chartype] == ucp_L ||
1205                   _pcre_ucp_gentype[prop->chartype] == ucp_N;
1206              break;
1207    
1208              case PT_SPACE:    /* Perl space */
1209              OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z ||
1210                   c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR;
1211              break;
1212    
1213              case PT_PXSPACE:  /* POSIX space */
1214              OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z ||
1215                   c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
1216                   c == CHAR_FF || c == CHAR_CR;
1217              break;
1218    
1219              case PT_WORD:
1220              OK = _pcre_ucp_gentype[prop->chartype] == ucp_L ||
1221                   _pcre_ucp_gentype[prop->chartype] == ucp_N ||
1222                   c == CHAR_UNDERSCORE;
1223            break;            break;
1224    
1225            /* Should never occur, but keep compilers from grumbling. */            /* Should never occur, but keep compilers from grumbling. */
# Line 1029  for (;;) Line 1248  for (;;)
1248        case OP_EXTUNI_EXTRA + OP_TYPEPOSPLUS:        case OP_EXTUNI_EXTRA + OP_TYPEPOSPLUS:
1249        count = current_state->count;  /* Already matched */        count = current_state->count;  /* Already matched */
1250        if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }        if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
1251        if (clen > 0 && _pcre_ucp_findprop(c, &chartype, &script) != ucp_M)        if (clen > 0 && UCD_CATEGORY(c) != ucp_M)
1252          {          {
1253          const uschar *nptr = ptr + clen;          const uschar *nptr = ptr + clen;
1254          int ncount = 0;          int ncount = 0;
# Line 1043  for (;;) Line 1262  for (;;)
1262            int nd;            int nd;
1263            int ndlen = 1;            int ndlen = 1;
1264            GETCHARLEN(nd, nptr, ndlen);            GETCHARLEN(nd, nptr, ndlen);
1265            if (_pcre_ucp_findprop(nd, &chartype, &script) != ucp_M) break;            if (UCD_CATEGORY(nd) != ucp_M) break;
1266            ncount++;            ncount++;
1267            nptr += ndlen;            nptr += ndlen;
1268            }            }
# Line 1064  for (;;) Line 1283  for (;;)
1283          int ncount = 0;          int ncount = 0;
1284          switch (c)          switch (c)
1285            {            {
1286              case 0x000b:
1287              case 0x000c:
1288              case 0x0085:
1289              case 0x2028:
1290              case 0x2029:
1291              if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break;
1292              goto ANYNL01;
1293    
1294            case 0x000d:            case 0x000d:
1295            if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1;            if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1;
1296            /* Fall through */            /* Fall through */
1297    
1298              ANYNL01:
1299              case 0x000a:
1300              if (count > 0 && codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSPLUS)
1301                {
1302                active_count--;           /* Remove non-match possibility */
1303                next_active_state--;
1304                }
1305              count++;
1306              ADD_NEW_DATA(-state_offset, count, ncount);
1307              break;
1308    
1309              default:
1310              break;
1311              }
1312            }
1313          break;
1314    
1315          /*-----------------------------------------------------------------*/
1316          case OP_VSPACE_EXTRA + OP_TYPEPLUS:
1317          case OP_VSPACE_EXTRA + OP_TYPEMINPLUS:
1318          case OP_VSPACE_EXTRA + OP_TYPEPOSPLUS:
1319          count = current_state->count;  /* Already matched */
1320          if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
1321          if (clen > 0)
1322            {
1323            BOOL OK;
1324            switch (c)
1325              {
1326            case 0x000a:            case 0x000a:
1327            case 0x000b:            case 0x000b:
1328            case 0x000c:            case 0x000c:
1329              case 0x000d:
1330            case 0x0085:            case 0x0085:
1331            case 0x2028:            case 0x2028:
1332            case 0x2029:            case 0x2029:
1333            if (count > 0 && codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSPLUS)            OK = TRUE;
1334              break;
1335    
1336              default:
1337              OK = FALSE;
1338              break;
1339              }
1340    
1341            if (OK == (d == OP_VSPACE))
1342              {
1343              if (count > 0 && codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSPLUS)
1344              {              {
1345              active_count--;           /* Remove non-match possibility */              active_count--;           /* Remove non-match possibility */
1346              next_active_state--;              next_active_state--;
1347              }              }
1348            count++;            count++;
1349            ADD_NEW_DATA(-state_offset, count, ncount);            ADD_NEW_DATA(-state_offset, count, 0);
1350              }
1351            }
1352          break;
1353    
1354          /*-----------------------------------------------------------------*/
1355          case OP_HSPACE_EXTRA + OP_TYPEPLUS:
1356          case OP_HSPACE_EXTRA + OP_TYPEMINPLUS:
1357          case OP_HSPACE_EXTRA + OP_TYPEPOSPLUS:
1358          count = current_state->count;  /* Already matched */
1359          if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
1360          if (clen > 0)
1361            {
1362            BOOL OK;
1363            switch (c)
1364              {
1365              case 0x09:      /* HT */
1366              case 0x20:      /* SPACE */
1367              case 0xa0:      /* NBSP */
1368              case 0x1680:    /* OGHAM SPACE MARK */
1369              case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1370              case 0x2000:    /* EN QUAD */
1371              case 0x2001:    /* EM QUAD */
1372              case 0x2002:    /* EN SPACE */
1373              case 0x2003:    /* EM SPACE */
1374              case 0x2004:    /* THREE-PER-EM SPACE */
1375              case 0x2005:    /* FOUR-PER-EM SPACE */
1376              case 0x2006:    /* SIX-PER-EM SPACE */
1377              case 0x2007:    /* FIGURE SPACE */
1378              case 0x2008:    /* PUNCTUATION SPACE */
1379              case 0x2009:    /* THIN SPACE */
1380              case 0x200A:    /* HAIR SPACE */
1381              case 0x202f:    /* NARROW NO-BREAK SPACE */
1382              case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1383              case 0x3000:    /* IDEOGRAPHIC SPACE */
1384              OK = TRUE;
1385            break;            break;
1386    
1387            default:            default:
1388              OK = FALSE;
1389            break;            break;
1390            }            }
1391    
1392            if (OK == (d == OP_HSPACE))
1393              {
1394              if (count > 0 && codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSPLUS)
1395                {
1396                active_count--;           /* Remove non-match possibility */
1397                next_active_state--;
1398                }
1399              count++;
1400              ADD_NEW_DATA(-state_offset, count, 0);
1401              }
1402          }          }
1403        break;        break;
1404    
# Line 1106  for (;;) Line 1421  for (;;)
1421        if (clen > 0)        if (clen > 0)
1422          {          {
1423          BOOL OK;          BOOL OK;
1424          int category = _pcre_ucp_findprop(c, &chartype, &script);          const ucd_record * prop = GET_UCD(c);
1425          switch(code[2])          switch(code[2])
1426            {            {
1427            case PT_ANY:            case PT_ANY:
# Line 1114  for (;;) Line 1429  for (;;)
1429            break;            break;
1430    
1431            case PT_LAMP:            case PT_LAMP:
1432            OK = chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt;            OK = prop->chartype == ucp_Lu || prop->chartype == ucp_Ll ||
1433                prop->chartype == ucp_Lt;
1434            break;            break;
1435    
1436            case PT_GC:            case PT_GC:
1437            OK = category == code[3];            OK = _pcre_ucp_gentype[prop->chartype] == code[3];
1438            break;            break;
1439    
1440            case PT_PC:            case PT_PC:
1441            OK = chartype == code[3];            OK = prop->chartype == code[3];
1442            break;            break;
1443    
1444            case PT_SC:            case PT_SC:
1445            OK = script == code[3];            OK = prop->script == code[3];
1446              break;
1447    
1448              /* These are specials for combination cases. */
1449    
1450              case PT_ALNUM:
1451              OK = _pcre_ucp_gentype[prop->chartype] == ucp_L ||
1452                   _pcre_ucp_gentype[prop->chartype] == ucp_N;
1453              break;
1454    
1455              case PT_SPACE:    /* Perl space */
1456              OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z ||
1457                   c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR;
1458              break;
1459    
1460              case PT_PXSPACE:  /* POSIX space */
1461              OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z ||
1462                   c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
1463                   c == CHAR_FF || c == CHAR_CR;
1464              break;
1465    
1466              case PT_WORD:
1467              OK = _pcre_ucp_gentype[prop->chartype] == ucp_L ||
1468                   _pcre_ucp_gentype[prop->chartype] == ucp_N ||
1469                   c == CHAR_UNDERSCORE;
1470            break;            break;
1471    
1472            /* Should never occur, but keep compilers from grumbling. */            /* Should never occur, but keep compilers from grumbling. */
# Line 1164  for (;;) Line 1504  for (;;)
1504        QS2:        QS2:
1505    
1506        ADD_ACTIVE(state_offset + 2, 0);        ADD_ACTIVE(state_offset + 2, 0);
1507        if (clen > 0 && _pcre_ucp_findprop(c, &chartype, &script) != ucp_M)        if (clen > 0 && UCD_CATEGORY(c) != ucp_M)
1508          {          {
1509          const uschar *nptr = ptr + clen;          const uschar *nptr = ptr + clen;
1510          int ncount = 0;          int ncount = 0;
# Line 1179  for (;;) Line 1519  for (;;)
1519            int nd;            int nd;
1520            int ndlen = 1;            int ndlen = 1;
1521            GETCHARLEN(nd, nptr, ndlen);            GETCHARLEN(nd, nptr, ndlen);
1522            if (_pcre_ucp_findprop(nd, &chartype, &script) != ucp_M) break;            if (UCD_CATEGORY(nd) != ucp_M) break;
1523            ncount++;            ncount++;
1524            nptr += ndlen;            nptr += ndlen;
1525            }            }
# Line 1207  for (;;) Line 1547  for (;;)
1547          int ncount = 0;          int ncount = 0;
1548          switch (c)          switch (c)
1549            {            {
1550              case 0x000b:
1551              case 0x000c:
1552              case 0x0085:
1553              case 0x2028:
1554              case 0x2029:
1555              if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break;
1556              goto ANYNL02;
1557    
1558            case 0x000d:            case 0x000d:
1559            if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1;            if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1;
1560            /* Fall through */            /* Fall through */
1561    
1562              ANYNL02:
1563              case 0x000a:
1564              if (codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSSTAR ||
1565                  codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSQUERY)
1566                {
1567                active_count--;           /* Remove non-match possibility */
1568                next_active_state--;
1569                }
1570              ADD_NEW_DATA(-(state_offset + count), 0, ncount);
1571              break;
1572    
1573              default:
1574              break;
1575              }
1576            }
1577          break;
1578    
1579          /*-----------------------------------------------------------------*/
1580          case OP_VSPACE_EXTRA + OP_TYPEQUERY:
1581          case OP_VSPACE_EXTRA + OP_TYPEMINQUERY:
1582          case OP_VSPACE_EXTRA + OP_TYPEPOSQUERY:
1583          count = 2;
1584          goto QS4;
1585    
1586          case OP_VSPACE_EXTRA + OP_TYPESTAR:
1587          case OP_VSPACE_EXTRA + OP_TYPEMINSTAR:
1588          case OP_VSPACE_EXTRA + OP_TYPEPOSSTAR:
1589          count = 0;
1590    
1591          QS4:
1592          ADD_ACTIVE(state_offset + 2, 0);
1593          if (clen > 0)
1594            {
1595            BOOL OK;
1596            switch (c)
1597              {
1598            case 0x000a:            case 0x000a:
1599            case 0x000b:            case 0x000b:
1600            case 0x000c:            case 0x000c:
1601              case 0x000d:
1602            case 0x0085:            case 0x0085:
1603            case 0x2028:            case 0x2028:
1604            case 0x2029:            case 0x2029:
1605            if (codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSSTAR ||            OK = TRUE;
1606                codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSQUERY)            break;
1607    
1608              default:
1609              OK = FALSE;
1610              break;
1611              }
1612            if (OK == (d == OP_VSPACE))
1613              {
1614              if (codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSSTAR ||
1615                  codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSQUERY)
1616              {              {
1617              active_count--;           /* Remove non-match possibility */              active_count--;           /* Remove non-match possibility */
1618              next_active_state--;              next_active_state--;
1619              }              }
1620            ADD_NEW_DATA(-(state_offset + count), 0, ncount);            ADD_NEW_DATA(-(state_offset + count), 0, 0);
1621              }
1622            }
1623          break;
1624    
1625          /*-----------------------------------------------------------------*/
1626          case OP_HSPACE_EXTRA + OP_TYPEQUERY:
1627          case OP_HSPACE_EXTRA + OP_TYPEMINQUERY:
1628          case OP_HSPACE_EXTRA + OP_TYPEPOSQUERY:
1629          count = 2;
1630          goto QS5;
1631    
1632          case OP_HSPACE_EXTRA + OP_TYPESTAR:
1633          case OP_HSPACE_EXTRA + OP_TYPEMINSTAR:
1634          case OP_HSPACE_EXTRA + OP_TYPEPOSSTAR:
1635          count = 0;
1636    
1637          QS5:
1638          ADD_ACTIVE(state_offset + 2, 0);
1639          if (clen > 0)
1640            {
1641            BOOL OK;
1642            switch (c)
1643              {
1644              case 0x09:      /* HT */
1645              case 0x20:      /* SPACE */
1646              case 0xa0:      /* NBSP */
1647              case 0x1680:    /* OGHAM SPACE MARK */
1648              case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1649              case 0x2000:    /* EN QUAD */
1650              case 0x2001:    /* EM QUAD */
1651              case 0x2002:    /* EN SPACE */
1652              case 0x2003:    /* EM SPACE */
1653              case 0x2004:    /* THREE-PER-EM SPACE */
1654              case 0x2005:    /* FOUR-PER-EM SPACE */
1655              case 0x2006:    /* SIX-PER-EM SPACE */
1656              case 0x2007:    /* FIGURE SPACE */
1657              case 0x2008:    /* PUNCTUATION SPACE */
1658              case 0x2009:    /* THIN SPACE */
1659              case 0x200A:    /* HAIR SPACE */
1660              case 0x202f:    /* NARROW NO-BREAK SPACE */
1661              case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1662              case 0x3000:    /* IDEOGRAPHIC SPACE */
1663              OK = TRUE;
1664            break;            break;
1665    
1666            default:            default:
1667              OK = FALSE;
1668            break;            break;
1669            }            }
1670    
1671            if (OK == (d == OP_HSPACE))
1672              {
1673              if (codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSSTAR ||
1674                  codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSQUERY)
1675                {
1676                active_count--;           /* Remove non-match possibility */
1677                next_active_state--;
1678                }
1679              ADD_NEW_DATA(-(state_offset + count), 0, 0);
1680              }
1681          }          }
1682        break;        break;
1683    
# Line 1242  for (;;) Line 1693  for (;;)
1693        if (clen > 0)        if (clen > 0)
1694          {          {
1695          BOOL OK;          BOOL OK;
1696          int category = _pcre_ucp_findprop(c, &chartype, &script);          const ucd_record * prop = GET_UCD(c);
1697          switch(code[4])          switch(code[4])
1698            {            {
1699            case PT_ANY:            case PT_ANY:
# Line 1250  for (;;) Line 1701  for (;;)
1701            break;            break;
1702    
1703            case PT_LAMP:            case PT_LAMP:
1704            OK = chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt;            OK = prop->chartype == ucp_Lu || prop->chartype == ucp_Ll ||
1705                prop->chartype == ucp_Lt;
1706            break;            break;
1707    
1708            case PT_GC:            case PT_GC:
1709            OK = category == code[5];            OK = _pcre_ucp_gentype[prop->chartype] == code[5];
1710            break;            break;
1711    
1712            case PT_PC:            case PT_PC:
1713            OK = chartype == code[5];            OK = prop->chartype == code[5];
1714            break;            break;
1715    
1716            case PT_SC:            case PT_SC:
1717            OK = script == code[5];            OK = prop->script == code[5];
1718              break;
1719    
1720              /* These are specials for combination cases. */
1721    
1722              case PT_ALNUM:
1723              OK = _pcre_ucp_gentype[prop->chartype] == ucp_L ||
1724                   _pcre_ucp_gentype[prop->chartype] == ucp_N;
1725              break;
1726    
1727              case PT_SPACE:    /* Perl space */
1728              OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z ||
1729                   c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR;
1730              break;
1731    
1732              case PT_PXSPACE:  /* POSIX space */
1733              OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z ||
1734                   c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
1735                   c == CHAR_FF || c == CHAR_CR;
1736              break;
1737    
1738              case PT_WORD:
1739              OK = _pcre_ucp_gentype[prop->chartype] == ucp_L ||
1740                   _pcre_ucp_gentype[prop->chartype] == ucp_N ||
1741                   c == CHAR_UNDERSCORE;
1742            break;            break;
1743    
1744            /* Should never occur, but keep compilers from grumbling. */            /* Should never occur, but keep compilers from grumbling. */
# Line 1295  for (;;) Line 1771  for (;;)
1771        if (codevalue != OP_EXTUNI_EXTRA + OP_TYPEEXACT)        if (codevalue != OP_EXTUNI_EXTRA + OP_TYPEEXACT)
1772          { ADD_ACTIVE(state_offset + 4, 0); }          { ADD_ACTIVE(state_offset + 4, 0); }
1773        count = current_state->count;  /* Number already matched */        count = current_state->count;  /* Number already matched */
1774        if (clen > 0 && _pcre_ucp_findprop(c, &chartype, &script) != ucp_M)        if (clen > 0 && UCD_CATEGORY(c) != ucp_M)
1775          {          {
1776          const uschar *nptr = ptr + clen;          const uschar *nptr = ptr + clen;
1777          int ncount = 0;          int ncount = 0;
# Line 1309  for (;;) Line 1785  for (;;)
1785            int nd;            int nd;
1786            int ndlen = 1;            int ndlen = 1;
1787            GETCHARLEN(nd, nptr, ndlen);            GETCHARLEN(nd, nptr, ndlen);
1788            if (_pcre_ucp_findprop(nd, &chartype, &script) != ucp_M) break;            if (UCD_CATEGORY(nd) != ucp_M) break;
1789            ncount++;            ncount++;
1790            nptr += ndlen;            nptr += ndlen;
1791            }            }
# Line 1334  for (;;) Line 1810  for (;;)
1810          int ncount = 0;          int ncount = 0;
1811          switch (c)          switch (c)
1812            {            {
1813              case 0x000b:
1814              case 0x000c:
1815              case 0x0085:
1816              case 0x2028:
1817              case 0x2029:
1818              if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break;
1819              goto ANYNL03;
1820    
1821            case 0x000d:            case 0x000d:
1822            if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1;            if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1;
1823            /* Fall through */            /* Fall through */
1824    
1825              ANYNL03:
1826              case 0x000a:
1827              if (codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSUPTO)
1828                {
1829                active_count--;           /* Remove non-match possibility */
1830                next_active_state--;
1831                }
1832              if (++count >= GET2(code, 1))
1833                { ADD_NEW_DATA(-(state_offset + 4), 0, ncount); }
1834              else
1835                { ADD_NEW_DATA(-state_offset, count, ncount); }
1836              break;
1837    
1838              default:
1839              break;
1840              }
1841            }
1842          break;
1843    
1844          /*-----------------------------------------------------------------*/
1845          case OP_VSPACE_EXTRA + OP_TYPEEXACT:
1846          case OP_VSPACE_EXTRA + OP_TYPEUPTO:
1847          case OP_VSPACE_EXTRA + OP_TYPEMINUPTO:
1848          case OP_VSPACE_EXTRA + OP_TYPEPOSUPTO:
1849          if (codevalue != OP_VSPACE_EXTRA + OP_TYPEEXACT)
1850            { ADD_ACTIVE(state_offset + 4, 0); }
1851          count = current_state->count;  /* Number already matched */
1852          if (clen > 0)
1853            {
1854            BOOL OK;
1855            switch (c)
1856              {
1857            case 0x000a:            case 0x000a:
1858            case 0x000b:            case 0x000b:
1859            case 0x000c:            case 0x000c:
1860              case 0x000d:
1861            case 0x0085:            case 0x0085:
1862            case 0x2028:            case 0x2028:
1863            case 0x2029:            case 0x2029:
1864            if (codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSUPTO)            OK = TRUE;
1865              break;
1866    
1867              default:
1868              OK = FALSE;
1869              }
1870    
1871            if (OK == (d == OP_VSPACE))
1872              {
1873              if (codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSUPTO)
1874              {              {
1875              active_count--;           /* Remove non-match possibility */              active_count--;           /* Remove non-match possibility */
1876              next_active_state--;              next_active_state--;
1877              }              }
1878            if (++count >= GET2(code, 1))            if (++count >= GET2(code, 1))
1879              { ADD_NEW_DATA(-(state_offset + 4), 0, ncount); }              { ADD_NEW_DATA(-(state_offset + 4), 0, 0); }
1880            else            else
1881              { ADD_NEW_DATA(-state_offset, count, ncount); }              { ADD_NEW_DATA(-state_offset, count, 0); }
1882              }
1883            }
1884          break;
1885    
1886          /*-----------------------------------------------------------------*/
1887          case OP_HSPACE_EXTRA + OP_TYPEEXACT:
1888          case OP_HSPACE_EXTRA + OP_TYPEUPTO:
1889          case OP_HSPACE_EXTRA + OP_TYPEMINUPTO:
1890          case OP_HSPACE_EXTRA + OP_TYPEPOSUPTO:
1891          if (codevalue != OP_HSPACE_EXTRA + OP_TYPEEXACT)
1892            { ADD_ACTIVE(state_offset + 4, 0); }
1893          count = current_state->count;  /* Number already matched */
1894          if (clen > 0)
1895            {
1896            BOOL OK;
1897            switch (c)
1898              {
1899              case 0x09:      /* HT */
1900              case 0x20:      /* SPACE */
1901              case 0xa0:      /* NBSP */
1902              case 0x1680:    /* OGHAM SPACE MARK */
1903              case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1904              case 0x2000:    /* EN QUAD */
1905              case 0x2001:    /* EM QUAD */
1906              case 0x2002:    /* EN SPACE */
1907              case 0x2003:    /* EM SPACE */
1908              case 0x2004:    /* THREE-PER-EM SPACE */
1909              case 0x2005:    /* FOUR-PER-EM SPACE */
1910              case 0x2006:    /* SIX-PER-EM SPACE */
1911              case 0x2007:    /* FIGURE SPACE */
1912              case 0x2008:    /* PUNCTUATION SPACE */
1913              case 0x2009:    /* THIN SPACE */
1914              case 0x200A:    /* HAIR SPACE */
1915              case 0x202f:    /* NARROW NO-BREAK SPACE */
1916              case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1917              case 0x3000:    /* IDEOGRAPHIC SPACE */
1918              OK = TRUE;
1919            break;            break;
1920    
1921            default:            default:
1922              OK = FALSE;
1923            break;            break;
1924            }            }
1925    
1926            if (OK == (d == OP_HSPACE))
1927              {
1928              if (codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSUPTO)
1929                {
1930                active_count--;           /* Remove non-match possibility */
1931                next_active_state--;
1932                }
1933              if (++count >= GET2(code, 1))
1934                { ADD_NEW_DATA(-(state_offset + 4), 0, 0); }
1935              else
1936                { ADD_NEW_DATA(-state_offset, count, 0); }
1937              }
1938          }          }
1939        break;        break;
1940    
# Line 1386  for (;;) Line 1965  for (;;)
1965            other case of the character. */            other case of the character. */
1966    
1967  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
1968            othercase = _pcre_ucp_othercase(c);            othercase = UCD_OTHERCASE(c);
1969  #else  #else
1970            othercase = NOTACHAR;            othercase = NOTACHAR;
1971  #endif  #endif
# Line 1411  for (;;) Line 1990  for (;;)
1990        to wait for them to pass before continuing. */        to wait for them to pass before continuing. */
1991    
1992        case OP_EXTUNI:        case OP_EXTUNI:
1993        if (clen > 0 && _pcre_ucp_findprop(c, &chartype, &script) != ucp_M)        if (clen > 0 && UCD_CATEGORY(c) != ucp_M)
1994          {          {
1995          const uschar *nptr = ptr + clen;          const uschar *nptr = ptr + clen;
1996          int ncount = 0;          int ncount = 0;
# Line 1419  for (;;) Line 1998  for (;;)
1998            {            {
1999            int nclen = 1;            int nclen = 1;
2000            GETCHARLEN(c, nptr, nclen);            GETCHARLEN(c, nptr, nclen);
2001            if (_pcre_ucp_findprop(c, &chartype, &script) != ucp_M) break;            if (UCD_CATEGORY(c) != ucp_M) break;
2002            ncount++;            ncount++;
2003            nptr += nclen;            nptr += nclen;
2004            }            }
# Line 1436  for (;;) Line 2015  for (;;)
2015        case OP_ANYNL:        case OP_ANYNL:
2016        if (clen > 0) switch(c)        if (clen > 0) switch(c)
2017          {          {
         case 0x000a:  
2018          case 0x000b:          case 0x000b:
2019          case 0x000c:          case 0x000c:
2020          case 0x0085:          case 0x0085:
2021          case 0x2028:          case 0x2028:
2022          case 0x2029:          case 0x2029:
2023            if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break;
2024    
2025            case 0x000a:
2026          ADD_NEW(state_offset + 1, 0);          ADD_NEW(state_offset + 1, 0);
2027          break;          break;
2028    
2029          case 0x000d:          case 0x000d:
2030          if (ptr + 1 < end_subject && ptr[1] == 0x0a)          if (ptr + 1 < end_subject && ptr[1] == 0x0a)
2031            {            {
# Line 1458  for (;;) Line 2040  for (;;)
2040        break;        break;
2041    
2042        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
2043          case OP_NOT_VSPACE:
2044          if (clen > 0) switch(c)
2045            {
2046            case 0x000a:
2047            case 0x000b:
2048            case 0x000c:
2049            case 0x000d:
2050            case 0x0085:
2051            case 0x2028:
2052            case 0x2029:
2053            break;
2054    
2055            default:
2056            ADD_NEW(state_offset + 1, 0);
2057            break;
2058            }
2059          break;
2060    
2061          /*-----------------------------------------------------------------*/
2062          case OP_VSPACE:
2063          if (clen > 0) switch(c)
2064            {
2065            case 0x000a:
2066            case 0x000b:
2067            case 0x000c:
2068            case 0x000d:
2069            case 0x0085:
2070            case 0x2028:
2071            case 0x2029:
2072            ADD_NEW(state_offset + 1, 0);
2073            break;
2074    
2075            default: break;
2076            }
2077          break;
2078    
2079          /*-----------------------------------------------------------------*/
2080          case OP_NOT_HSPACE:
2081          if (clen > 0) switch(c)
2082            {
2083            case 0x09:      /* HT */
2084            case 0x20:      /* SPACE */
2085            case 0xa0:      /* NBSP */
2086            case 0x1680:    /* OGHAM SPACE MARK */
2087            case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
2088            case 0x2000:    /* EN QUAD */
2089            case 0x2001:    /* EM QUAD */
2090            case 0x2002:    /* EN SPACE */
2091            case 0x2003:    /* EM SPACE */
2092            case 0x2004:    /* THREE-PER-EM SPACE */
2093            case 0x2005:    /* FOUR-PER-EM SPACE */
2094            case 0x2006:    /* SIX-PER-EM SPACE */
2095            case 0x2007:    /* FIGURE SPACE */
2096            case 0x2008:    /* PUNCTUATION SPACE */
2097            case 0x2009:    /* THIN SPACE */
2098            case 0x200A:    /* HAIR SPACE */
2099            case 0x202f:    /* NARROW NO-BREAK SPACE */
2100            case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
2101            case 0x3000:    /* IDEOGRAPHIC SPACE */
2102            break;
2103    
2104            default:
2105            ADD_NEW(state_offset + 1, 0);
2106            break;
2107            }
2108          break;
2109    
2110          /*-----------------------------------------------------------------*/
2111          case OP_HSPACE:
2112          if (clen > 0) switch(c)
2113            {
2114            case 0x09:      /* HT */
2115            case 0x20:      /* SPACE */
2116            case 0xa0:      /* NBSP */
2117            case 0x1680:    /* OGHAM SPACE MARK */
2118            case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
2119            case 0x2000:    /* EN QUAD */
2120            case 0x2001:    /* EM QUAD */
2121            case 0x2002:    /* EN SPACE */
2122            case 0x2003:    /* EM SPACE */
2123            case 0x2004:    /* THREE-PER-EM SPACE */
2124            case 0x2005:    /* FOUR-PER-EM SPACE */
2125            case 0x2006:    /* SIX-PER-EM SPACE */
2126            case 0x2007:    /* FIGURE SPACE */
2127            case 0x2008:    /* PUNCTUATION SPACE */
2128            case 0x2009:    /* THIN SPACE */
2129            case 0x200A:    /* HAIR SPACE */
2130            case 0x202f:    /* NARROW NO-BREAK SPACE */
2131            case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
2132            case 0x3000:    /* IDEOGRAPHIC SPACE */
2133            ADD_NEW(state_offset + 1, 0);
2134            break;
2135            }
2136          break;
2137    
2138          /*-----------------------------------------------------------------*/
2139        /* Match a negated single character. This is only used for one-byte        /* Match a negated single character. This is only used for one-byte
2140        characters, that is, we know that d < 256. The character we are        characters, that is, we know that d < 256. The character we are
2141        checking (c) can be multibyte. */        checking (c) can be multibyte. */
# Line 1488  for (;;) Line 2166  for (;;)
2166            if (utf8 && d >= 128)            if (utf8 && d >= 128)
2167              {              {
2168  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2169              otherd = _pcre_ucp_othercase(d);              otherd = UCD_OTHERCASE(d);
2170  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2171              }              }
2172            else            else
# Line 1526  for (;;) Line 2204  for (;;)
2204            if (utf8 && d >= 128)            if (utf8 && d >= 128)
2205              {              {
2206  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2207              otherd = _pcre_ucp_othercase(d);              otherd = UCD_OTHERCASE(d);
2208  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2209              }              }
2210            else            else
# Line 1562  for (;;) Line 2240  for (;;)
2240            if (utf8 && d >= 128)            if (utf8 && d >= 128)
2241              {              {
2242  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2243              otherd = _pcre_ucp_othercase(d);              otherd = UCD_OTHERCASE(d);
2244  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2245              }              }
2246            else            else
# Line 1594  for (;;) Line 2272  for (;;)
2272            if (utf8 && d >= 128)            if (utf8 && d >= 128)
2273              {              {
2274  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2275              otherd = _pcre_ucp_othercase(d);              otherd = UCD_OTHERCASE(d);
2276  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2277              }              }
2278            else            else
# Line 1629  for (;;) Line 2307  for (;;)
2307            if (utf8 && d >= 128)            if (utf8 && d >= 128)
2308              {              {
2309  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2310              otherd = _pcre_ucp_othercase(d);              otherd = UCD_OTHERCASE(d);
2311  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2312              }              }
2313            else            else
# Line 1690  for (;;) Line 2368  for (;;)
2368          points to the byte after the end of the class. If there is a          points to the byte after the end of the class. If there is a
2369          quantifier, this is where it will be. */          quantifier, this is where it will be. */
2370    
2371          next_state_offset = ecode - start_code;          next_state_offset = (int)(ecode - start_code);
2372    
2373          switch (*ecode)          switch (*ecode)
2374            {            {
# Line 1737  for (;;) Line 2415  for (;;)
2415    
2416  /* ========================================================================== */  /* ========================================================================== */
2417        /* These are the opcodes for fancy brackets of various kinds. We have        /* These are the opcodes for fancy brackets of various kinds. We have
2418        to use recursion in order to handle them. */        to use recursion in order to handle them. The "always failing" assertion
2419          (?!) is optimised to OP_FAIL when compiling, so we have to support that,
2420          though the other "backtracking verbs" are not supported. */
2421    
2422          case OP_FAIL:
2423          forced_fail++;    /* Count FAILs for multiple states */
2424          break;
2425    
2426        case OP_ASSERT:        case OP_ASSERT:
2427        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
# Line 1755  for (;;) Line 2439  for (;;)
2439            md,                                   /* static match data */            md,                                   /* static match data */
2440            code,                                 /* this subexpression's code */            code,                                 /* this subexpression's code */
2441            ptr,                                  /* where we currently are */            ptr,                                  /* where we currently are */
2442            ptr - start_subject,                  /* start offset */            (int)(ptr - start_subject),           /* start offset */
2443            local_offsets,                        /* offset vector */            local_offsets,                        /* offset vector */
2444            sizeof(local_offsets)/sizeof(int),    /* size of same */            sizeof(local_offsets)/sizeof(int),    /* size of same */
2445            local_workspace,                      /* workspace vector */            local_workspace,                      /* workspace vector */
# Line 1764  for (;;) Line 2448  for (;;)
2448            rlevel,                               /* function recursion level */            rlevel,                               /* function recursion level */
2449            recursing);                           /* pass on regex recursion */            recursing);                           /* pass on regex recursion */
2450    
2451            if (rc == PCRE_ERROR_DFA_UITEM) return rc;
2452          if ((rc >= 0) == (codevalue == OP_ASSERT || codevalue == OP_ASSERTBACK))          if ((rc >= 0) == (codevalue == OP_ASSERT || codevalue == OP_ASSERTBACK))
2453              { ADD_ACTIVE(endasscode + LINK_SIZE + 1 - start_code, 0); }              { ADD_ACTIVE((int)(endasscode + LINK_SIZE + 1 - start_code), 0); }
2454          }          }
2455        break;        break;
2456    
# Line 1775  for (;;) Line 2460  for (;;)
2460          {          {
2461          int local_offsets[1000];          int local_offsets[1000];
2462          int local_workspace[1000];          int local_workspace[1000];
2463          int condcode = code[LINK_SIZE+1];          int codelink = GET(code, 1);
2464            int condcode;
2465    
2466            /* Because of the way auto-callout works during compile, a callout item
2467            is inserted between OP_COND and an assertion condition. This does not
2468            happen for the other conditions. */
2469    
2470            if (code[LINK_SIZE+1] == OP_CALLOUT)
2471              {
2472              rrc = 0;
2473              if (pcre_callout != NULL)
2474                {
2475                pcre_callout_block cb;
2476                cb.version          = 1;   /* Version 1 of the callout block */
2477                cb.callout_number   = code[LINK_SIZE+2];
2478                cb.offset_vector    = offsets;
2479                cb.subject          = (PCRE_SPTR)start_subject;
2480                cb.subject_length   = (int)(end_subject - start_subject);
2481                cb.start_match      = (int)(current_subject - start_subject);
2482                cb.current_position = (int)(ptr - start_subject);
2483                cb.pattern_position = GET(code, LINK_SIZE + 3);
2484                cb.next_item_length = GET(code, 3 + 2*LINK_SIZE);
2485                cb.capture_top      = 1;
2486                cb.capture_last     = -1;
2487                cb.callout_data     = md->callout_data;
2488                if ((rrc = (*pcre_callout)(&cb)) < 0) return rrc;   /* Abandon */
2489                }
2490              if (rrc > 0) break;                      /* Fail this thread */
2491              code += _pcre_OP_lengths[OP_CALLOUT];    /* Skip callout data */
2492              }
2493    
2494            condcode = code[LINK_SIZE+1];
2495    
2496          /* Back reference conditions are not supported */          /* Back reference conditions are not supported */
2497    
2498          if (condcode == OP_CREF) return PCRE_ERROR_DFA_UCOND;          if (condcode == OP_CREF || condcode == OP_NCREF)
2499              return PCRE_ERROR_DFA_UCOND;
2500    
2501          /* The DEFINE condition is always false */          /* The DEFINE condition is always false */
2502    
2503          if (condcode == OP_DEF)          if (condcode == OP_DEF)
2504            {            { ADD_ACTIVE(state_offset + codelink + LINK_SIZE + 1, 0); }
           ADD_ACTIVE(state_offset + GET(code, 1) + LINK_SIZE + 1, 0);  
           }  
2505    
2506          /* The only supported version of OP_RREF is for the value RREF_ANY,          /* The only supported version of OP_RREF is for the value RREF_ANY,
2507          which means "test if in any recursion". We can't test for specifically          which means "test if in any recursion". We can't test for specifically
2508          recursed groups. */          recursed groups. */
2509    
2510          else if (condcode == OP_RREF)          else if (condcode == OP_RREF || condcode == OP_NRREF)
2511            {            {
2512            int value = GET2(code, LINK_SIZE+2);            int value = GET2(code, LINK_SIZE+2);
2513            if (value != RREF_ANY) return PCRE_ERROR_DFA_UCOND;            if (value != RREF_ANY) return PCRE_ERROR_DFA_UCOND;
2514            if (recursing > 0) { ADD_ACTIVE(state_offset + LINK_SIZE + 4, 0); }            if (recursing > 0)
2515              else { ADD_ACTIVE(state_offset + GET(code, 1) + LINK_SIZE + 1, 0); }              { ADD_ACTIVE(state_offset + LINK_SIZE + 4, 0); }
2516              else { ADD_ACTIVE(state_offset + codelink + LINK_SIZE + 1, 0); }
2517            }            }
2518    
2519          /* Otherwise, the condition is an assertion */          /* Otherwise, the condition is an assertion */
# Line 1814  for (;;) Line 2530  for (;;)
2530              md,                                   /* fixed match data */              md,                                   /* fixed match data */
2531              asscode,                              /* this subexpression's code */              asscode,                              /* this subexpression's code */
2532              ptr,                                  /* where we currently are */              ptr,                                  /* where we currently are */
2533              ptr - start_subject,                  /* start offset */              (int)(ptr - start_subject),           /* start offset */
2534              local_offsets,                        /* offset vector */              local_offsets,                        /* offset vector */
2535              sizeof(local_offsets)/sizeof(int),    /* size of same */              sizeof(local_offsets)/sizeof(int),    /* size of same */
2536              local_workspace,                      /* workspace vector */              local_workspace,                      /* workspace vector */
# Line 1823  for (;;) Line 2539  for (;;)
2539              rlevel,                               /* function recursion level */              rlevel,                               /* function recursion level */
2540              recursing);                           /* pass on regex recursion */              recursing);                           /* pass on regex recursion */
2541    
2542              if (rc == PCRE_ERROR_DFA_UITEM) return rc;
2543            if ((rc >= 0) ==            if ((rc >= 0) ==
2544                  (condcode == OP_ASSERT || condcode == OP_ASSERTBACK))                  (condcode == OP_ASSERT || condcode == OP_ASSERTBACK))
2545              { ADD_ACTIVE(endasscode + LINK_SIZE + 1 - start_code, 0); }              { ADD_ACTIVE((int)(endasscode + LINK_SIZE + 1 - start_code), 0); }
2546            else            else
2547              { ADD_ACTIVE(state_offset + GET(code, 1) + LINK_SIZE + 1, 0); }              { ADD_ACTIVE(state_offset + codelink + LINK_SIZE + 1, 0); }
2548            }            }
2549          }          }
2550        break;        break;
# Line 1846  for (;;) Line 2563  for (;;)
2563            md,                                   /* fixed match data */            md,                                   /* fixed match data */
2564            start_code + GET(code, 1),            /* this subexpression's code */            start_code + GET(code, 1),            /* this subexpression's code */
2565            ptr,                                  /* where we currently are */            ptr,                                  /* where we currently are */
2566            ptr - start_subject,                  /* start offset */            (int)(ptr - start_subject),           /* start offset */
2567            local_offsets,                        /* offset vector */            local_offsets,                        /* offset vector */
2568            sizeof(local_offsets)/sizeof(int),    /* size of same */            sizeof(local_offsets)/sizeof(int),    /* size of same */
2569            local_workspace,                      /* workspace vector */            local_workspace,                      /* workspace vector */
# Line 1898  for (;;) Line 2615  for (;;)
2615            md,                                   /* fixed match data */            md,                                   /* fixed match data */
2616            code,                                 /* this subexpression's code */            code,                                 /* this subexpression's code */
2617            ptr,                                  /* where we currently are */            ptr,                                  /* where we currently are */
2618            ptr - start_subject,                  /* start offset */            (int)(ptr - start_subject),           /* start offset */
2619            local_offsets,                        /* offset vector */            local_offsets,                        /* offset vector */
2620            sizeof(local_offsets)/sizeof(int),    /* size of same */            sizeof(local_offsets)/sizeof(int),    /* size of same */
2621            local_workspace,                      /* workspace vector */            local_workspace,                      /* workspace vector */
# Line 1915  for (;;) Line 2632  for (;;)
2632    
2633            do { end_subpattern += GET(end_subpattern, 1); }            do { end_subpattern += GET(end_subpattern, 1); }
2634              while (*end_subpattern == OP_ALT);              while (*end_subpattern == OP_ALT);
2635            next_state_offset = end_subpattern - start_code + LINK_SIZE + 1;            next_state_offset =
2636                (int)(end_subpattern - start_code + LINK_SIZE + 1);
2637    
2638            /* If the end of this subpattern is KETRMAX or KETRMIN, we must            /* If the end of this subpattern is KETRMAX or KETRMIN, we must
2639            arrange for the repeat state also to be added to the relevant list.            arrange for the repeat state also to be added to the relevant list.
# Line 1923  for (;;) Line 2641  for (;;)
2641    
2642            repeat_state_offset = (*end_subpattern == OP_KETRMAX ||            repeat_state_offset = (*end_subpattern == OP_KETRMAX ||
2643                                   *end_subpattern == OP_KETRMIN)?                                   *end_subpattern == OP_KETRMIN)?
2644              end_subpattern - start_code - GET(end_subpattern, 1) : -1;              (int)(end_subpattern - start_code - GET(end_subpattern, 1)) : -1;
2645    
2646            /* If we have matched an empty string, add the next state at the            /* If we have matched an empty string, add the next state at the
2647            current character pointer. This is important so that the duplicate            current character pointer. This is important so that the duplicate
# Line 1979  for (;;) Line 2697  for (;;)
2697        /* Handle callouts */        /* Handle callouts */
2698    
2699        case OP_CALLOUT:        case OP_CALLOUT:
2700          rrc = 0;
2701        if (pcre_callout != NULL)        if (pcre_callout != NULL)
2702          {          {
         int rrc;  
2703          pcre_callout_block cb;          pcre_callout_block cb;
2704          cb.version          = 1;   /* Version 1 of the callout block */          cb.version          = 1;   /* Version 1 of the callout block */
2705          cb.callout_number   = code[1];          cb.callout_number   = code[1];
2706          cb.offset_vector    = offsets;          cb.offset_vector    = offsets;
2707          cb.subject          = (PCRE_SPTR)start_subject;          cb.subject          = (PCRE_SPTR)start_subject;
2708          cb.subject_length   = end_subject - start_subject;          cb.subject_length   = (int)(end_subject - start_subject);
2709          cb.start_match      = current_subject - start_subject;          cb.start_match      = (int)(current_subject - start_subject);
2710          cb.current_position = ptr - start_subject;          cb.current_position = (int)(ptr - start_subject);
2711          cb.pattern_position = GET(code, 2);          cb.pattern_position = GET(code, 2);
2712          cb.next_item_length = GET(code, 2 + LINK_SIZE);          cb.next_item_length = GET(code, 2 + LINK_SIZE);
2713          cb.capture_top      = 1;          cb.capture_top      = 1;
2714          cb.capture_last     = -1;          cb.capture_last     = -1;
2715          cb.callout_data     = md->callout_data;          cb.callout_data     = md->callout_data;
2716          if ((rrc = (*pcre_callout)(&cb)) < 0) return rrc;   /* Abandon */          if ((rrc = (*pcre_callout)(&cb)) < 0) return rrc;   /* Abandon */
         if (rrc == 0) { ADD_ACTIVE(state_offset + 2 + 2*LINK_SIZE, 0); }  
2717          }          }
2718          if (rrc == 0)
2719            { ADD_ACTIVE(state_offset + _pcre_OP_lengths[OP_CALLOUT], 0); }
2720        break;        break;
2721    
2722    
# Line 2013  for (;;) Line 2732  for (;;)
2732    /* We have finished the processing at the current subject character. If no    /* We have finished the processing at the current subject character. If no
2733    new states have been set for the next character, we have found all the    new states have been set for the next character, we have found all the
2734    matches that we are going to find. If we are at the top level and partial    matches that we are going to find. If we are at the top level and partial
2735    matching has been requested, check for appropriate conditions. */    matching has been requested, check for appropriate conditions.
2736    
2737      The "forced_ fail" variable counts the number of (*F) encountered for the
2738      character. If it is equal to the original active_count (saved in
2739      workspace[1]) it means that (*F) was found on every active state. In this
2740      case we don't want to give a partial match.
2741    
2742      The "could_continue" variable is true if a state could have continued but
2743      for the fact that the end of the subject was reached. */
2744    
2745    if (new_count <= 0)    if (new_count <= 0)
2746      {      {
2747      if (match_count < 0 &&                     /* No matches found */      if (rlevel == 1 &&                               /* Top level, and */
2748          rlevel == 1 &&                         /* Top level match function */          could_continue &&                            /* Some could go on */
2749          (md->moptions & PCRE_PARTIAL) != 0 &&  /* Want partial matching */          forced_fail != workspace[1] &&               /* Not all forced fail & */
2750            (                                            /* either... */
2751            (md->moptions & PCRE_PARTIAL_HARD) != 0      /* Hard partial */
2752            ||                                           /* or... */
2753            ((md->moptions & PCRE_PARTIAL_SOFT) != 0 &&  /* Soft partial and */
2754             match_count < 0)                            /* no matches */
2755            ) &&                                         /* And... */
2756          ptr >= end_subject &&                  /* Reached end of subject */          ptr >= end_subject &&                  /* Reached end of subject */
2757          ptr > current_subject)                 /* Matched non-empty string */          ptr > md->start_used_ptr)              /* Inspected non-empty string */
2758        {        {
2759        if (offsetcount >= 2)        if (offsetcount >= 2)
2760          {          {
2761          offsets[0] = current_subject - start_subject;          offsets[0] = (int)(md->start_used_ptr - start_subject);
2762          offsets[1] = end_subject - start_subject;          offsets[1] = (int)(end_subject - start_subject);
2763          }          }
2764        match_count = PCRE_ERROR_PARTIAL;        match_count = PCRE_ERROR_PARTIAL;
2765        }        }
# Line 2080  Returns: > 0 => number of match Line 2813  Returns: > 0 => number of match
2813                   < -1 => some kind of unexpected problem                   < -1 => some kind of unexpected problem
2814  */  */
2815    
2816  PCRE_EXP_DEFN int  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
2817  pcre_dfa_exec(const pcre *argument_re, const pcre_extra *extra_data,  pcre_dfa_exec(const pcre *argument_re, const pcre_extra *extra_data,
2818    const char *subject, int length, int start_offset, int options, int *offsets,    const char *subject, int length, int start_offset, int options, int *offsets,
2819    int offsetcount, int *workspace, int wscount)    int offsetcount, int *workspace, int wscount)
# Line 2111  if (re == NULL || subject == NULL || wor Line 2844  if (re == NULL || subject == NULL || wor
2844     (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;     (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;
2845  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;
2846  if (wscount < 20) return PCRE_ERROR_DFA_WSSIZE;  if (wscount < 20) return PCRE_ERROR_DFA_WSSIZE;
2847    if (start_offset < 0 || start_offset > length) return PCRE_ERROR_BADOFFSET;
2848    
2849  /* We need to find the pointer to any study data before we test for byte  /* We need to find the pointer to any study data before we test for byte
2850  flipping, so we scan the extra_data block first. This may set two fields in the  flipping, so we scan the extra_data block first. This may set two fields in the
# Line 2167  md->start_code = (const uschar *)argumen Line 2901  md->start_code = (const uschar *)argumen
2901      re->name_table_offset + re->name_count * re->name_entry_size;      re->name_table_offset + re->name_count * re->name_entry_size;
2902  md->start_subject = (const unsigned char *)subject;  md->start_subject = (const unsigned char *)subject;
2903  md->end_subject = end_subject;  md->end_subject = end_subject;
2904    md->start_offset = start_offset;
2905  md->moptions = options;  md->moptions = options;
2906  md->poptions = re->options;  md->poptions = re->options;
2907    
2908    /* If the BSR option is not set at match time, copy what was set
2909    at compile time. */
2910    
2911    if ((md->moptions & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) == 0)
2912      {
2913      if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0)
2914        md->moptions |= re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE);
2915    #ifdef BSR_ANYCRLF
2916      else md->moptions |= PCRE_BSR_ANYCRLF;
2917    #endif
2918      }
2919    
2920  /* Handle different types of newline. The three bits give eight cases. If  /* Handle different types of newline. The three bits give eight cases. If
2921  nothing is set at run time, whatever was used at compile time applies. */  nothing is set at run time, whatever was used at compile time applies. */
2922    
# Line 2177  switch ((((options & PCRE_NEWLINE_BITS) Line 2924  switch ((((options & PCRE_NEWLINE_BITS)
2924           PCRE_NEWLINE_BITS)           PCRE_NEWLINE_BITS)
2925    {    {
2926    case 0: newline = NEWLINE; break;   /* Compile-time default */    case 0: newline = NEWLINE; break;   /* Compile-time default */
2927    case PCRE_NEWLINE_CR: newline = '\r'; break;    case PCRE_NEWLINE_CR: newline = CHAR_CR; break;
2928    case PCRE_NEWLINE_LF: newline = '\n'; break;    case PCRE_NEWLINE_LF: newline = CHAR_NL; break;
2929    case PCRE_NEWLINE_CR+    case PCRE_NEWLINE_CR+
2930         PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break;         PCRE_NEWLINE_LF: newline = (CHAR_CR << 8) | CHAR_NL; break;
2931    case PCRE_NEWLINE_ANY: newline = -1; break;    case PCRE_NEWLINE_ANY: newline = -1; break;
2932    case PCRE_NEWLINE_ANYCRLF: newline = -2; break;    case PCRE_NEWLINE_ANYCRLF: newline = -2; break;
2933    default: return PCRE_ERROR_BADNEWLINE;    default: return PCRE_ERROR_BADNEWLINE;
# Line 2220  if (utf8 && (options & PCRE_NO_UTF8_CHEC Line 2967  if (utf8 && (options & PCRE_NO_UTF8_CHEC
2967      return PCRE_ERROR_BADUTF8;      return PCRE_ERROR_BADUTF8;
2968    if (start_offset > 0 && start_offset < length)    if (start_offset > 0 && start_offset < length)
2969      {      {
2970      int tb = ((uschar *)subject)[start_offset];      int tb = ((USPTR)subject)[start_offset] & 0xc0;
2971      if (tb > 127)      if (tb == 0x80) return PCRE_ERROR_BADUTF8_OFFSET;
       {  
       tb &= 0xc0;  
       if (tb != 0 && tb != 0xc0) return PCRE_ERROR_BADUTF8_OFFSET;  
       }  
2972      }      }
2973    }    }
2974  #endif  #endif
# Line 2240  if (md->tables == NULL) md->tables = _pc Line 2983  if (md->tables == NULL) md->tables = _pc
2983  used in a loop when finding where to start. */  used in a loop when finding where to start. */
2984    
2985  lcc = md->tables + lcc_offset;  lcc = md->tables + lcc_offset;
2986  startline = (re->options & PCRE_STARTLINE) != 0;  startline = (re->flags & PCRE_STARTLINE) != 0;
2987  firstline = (re->options & PCRE_FIRSTLINE) != 0;  firstline = (re->options & PCRE_FIRSTLINE) != 0;
2988    
2989  /* Set up the first character to match, if available. The first_byte value is  /* Set up the first character to match, if available. The first_byte value is
# Line 2251  studied, there may be a bitmap of possib Line 2994  studied, there may be a bitmap of possib
2994    
2995  if (!anchored)  if (!anchored)
2996    {    {
2997    if ((re->options & PCRE_FIRSTSET) != 0)    if ((re->flags & PCRE_FIRSTSET) != 0)
2998      {      {
2999      first_byte = re->first_byte & 255;      first_byte = re->first_byte & 255;
3000      if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)      if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)
# Line 2259  if (!anchored) Line 3002  if (!anchored)
3002      }      }
3003    else    else
3004      {      {
3005      if (startline && study != NULL &&      if (!startline && study != NULL &&
3006           (study->options & PCRE_STUDY_MAPPED) != 0)           (study->flags & PCRE_STUDY_MAPPED) != 0)
3007        start_bits = study->start_bits;        start_bits = study->start_bits;
3008      }      }
3009    }    }
# Line 2268  if (!anchored) Line 3011  if (!anchored)
3011  /* For anchored or unanchored matches, there may be a "last known required  /* For anchored or unanchored matches, there may be a "last known required
3012  character" set. */  character" set. */
3013    
3014  if ((re->options & PCRE_REQCHSET) != 0)  if ((re->flags & PCRE_REQCHSET) != 0)
3015    {    {
3016    req_byte = re->req_byte & 255;    req_byte = re->req_byte & 255;
3017    req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;    req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;
# Line 2276  if ((re->options & PCRE_REQCHSET) != 0) Line 3019  if ((re->options & PCRE_REQCHSET) != 0)
3019    }    }
3020    
3021  /* Call the main matching function, looping for a non-anchored regex after a  /* Call the main matching function, looping for a non-anchored regex after a
3022  failed match. Unless restarting, optimize by moving to the first match  failed match. If not restarting, perform certain optimizations at the start of
3023  character if possible, when not anchored. Then unless wanting a partial match,  a match. */
 check for a required later character. */  
3024    
3025  for (;;)  for (;;)
3026    {    {
# Line 2288  for (;;) Line 3030  for (;;)
3030      {      {
3031      const uschar *save_end_subject = end_subject;      const uschar *save_end_subject = end_subject;
3032    
3033      /* Advance to a unique first char if possible. If firstline is TRUE, the      /* If firstline is TRUE, the start of the match is constrained to the first
3034      start of the match is constrained to the first line of a multiline string.      line of a multiline string. Implement this by temporarily adjusting
3035      Implement this by temporarily adjusting end_subject so that we stop      end_subject so that we stop scanning at a newline. If the match fails at
3036      scanning at a newline. If the match fails at the newline, later code breaks      the newline, later code breaks this loop. */
     this loop. */  
3037    
3038      if (firstline)      if (firstline)
3039        {        {
3040        const uschar *t = current_subject;        USPTR t = current_subject;
3041    #ifdef SUPPORT_UTF8
3042          if (utf8)
3043            {
3044            while (t < md->end_subject && !IS_NEWLINE(t))
3045              {
3046              t++;
3047              while (t < end_subject && (*t & 0xc0) == 0x80) t++;
3048              }
3049            }
3050          else
3051    #endif
3052        while (t < md->end_subject && !IS_NEWLINE(t)) t++;        while (t < md->end_subject && !IS_NEWLINE(t)) t++;
3053        end_subject = t;        end_subject = t;
3054        }        }
3055    
3056      if (first_byte >= 0)      /* There are some optimizations that avoid running the match if a known
3057        starting point is not found. However, there is an option that disables
3058        these, for testing and for ensuring that all callouts do actually occur. */
3059    
3060        if ((options & PCRE_NO_START_OPTIMIZE) == 0)
3061        {        {
3062        if (first_byte_caseless)        /* Advance to a known first byte. */
         while (current_subject < end_subject &&  
                lcc[*current_subject] != first_byte)  
           current_subject++;  
       else  
         while (current_subject < end_subject && *current_subject != first_byte)  
           current_subject++;  
       }  
3063    
3064      /* Or to just after a linebreak for a multiline match if possible */        if (first_byte >= 0)
3065            {
3066            if (first_byte_caseless)
3067              while (current_subject < end_subject &&
3068                     lcc[*current_subject] != first_byte)
3069                current_subject++;
3070            else
3071              while (current_subject < end_subject &&
3072                     *current_subject != first_byte)
3073                current_subject++;
3074            }
3075    
3076      else if (startline)        /* Or to just after a linebreak for a multiline match if possible */
3077        {  
3078        if (current_subject > md->start_subject + start_offset)        else if (startline)
3079          {          {
3080          while (current_subject <= end_subject && !WAS_NEWLINE(current_subject))          if (current_subject > md->start_subject + start_offset)
3081            current_subject++;            {
3082    #ifdef SUPPORT_UTF8
3083              if (utf8)
3084                {
3085                while (current_subject < end_subject &&
3086                       !WAS_NEWLINE(current_subject))
3087                  {
3088                  current_subject++;
3089                  while(current_subject < end_subject &&
3090                        (*current_subject & 0xc0) == 0x80)
3091                    current_subject++;
3092                  }
3093                }
3094              else
3095    #endif
3096              while (current_subject < end_subject && !WAS_NEWLINE(current_subject))
3097                current_subject++;
3098    
3099          /* If we have just passed a CR and the newline option is ANY or            /* If we have just passed a CR and the newline option is ANY or
3100          ANYCRLF, and we are now at a LF, advance the match position by one more            ANYCRLF, and we are now at a LF, advance the match position by one
3101          character. */            more character. */
3102    
3103          if (current_subject[-1] == '\r' &&            if (current_subject[-1] == CHAR_CR &&
3104               (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&                 (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&
3105               current_subject < end_subject &&                 current_subject < end_subject &&
3106               *current_subject == '\n')                 *current_subject == CHAR_NL)
3107            current_subject++;              current_subject++;
3108              }
3109          }          }
       }  
3110    
3111      /* Or to a non-unique first char after study */        /* Or to a non-unique first char after study */
3112    
3113      else if (start_bits != NULL)        else if (start_bits != NULL)
       {  
       while (current_subject < end_subject)  
3114          {          {
3115          register unsigned int c = *current_subject;          while (current_subject < end_subject)
3116          if ((start_bits[c/8] & (1 << (c&7))) == 0) current_subject++;            {
3117              register unsigned int c = *current_subject;
3118              if ((start_bits[c/8] & (1 << (c&7))) == 0)
3119                {
3120                current_subject++;
3121    #ifdef SUPPORT_UTF8
3122                if (utf8)
3123                  while(current_subject < end_subject &&
3124                        (*current_subject & 0xc0) == 0x80) current_subject++;
3125    #endif
3126                }
3127            else break;            else break;
3128              }
3129          }          }
3130        }        }
3131    
3132      /* Restore fudged end_subject */      /* Restore fudged end_subject */
3133    
3134      end_subject = save_end_subject;      end_subject = save_end_subject;
     }  
3135    
3136    /* If req_byte is set, we know that that character must appear in the subject      /* The following two optimizations are disabled for partial matching or if
3137    for the match to succeed. If the first character is set, req_byte must be      disabling is explicitly requested (and of course, by the test above, this
3138    later in the subject; otherwise the test starts at the match point. This      code is not obeyed when restarting after a partial match). */
   optimization can save a huge amount of work 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 /^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.  
   */  
   
   if (req_byte >= 0 &&  
       end_subject - current_subject < REQ_BYTE_MAX &&  
       (options & PCRE_PARTIAL) == 0)  
     {  
     register const uschar *p = current_subject + ((first_byte >= 0)? 1 : 0);  
3139    
3140      /* We don't need to repeat the search if we haven't yet reached the      if ((options & PCRE_NO_START_OPTIMIZE) == 0 &&
3141      place we found it at last time. */          (options & (PCRE_PARTIAL_HARD|PCRE_PARTIAL_SOFT)) == 0)
   
     if (p > req_byte_ptr)  
3142        {        {
3143        if (req_byte_caseless)        /* If the pattern was studied, a minimum subject length may be set. This
3144          {        is a lower bound; no actual string of that length may actually match the
3145          while (p < end_subject)        pattern. Although the value is, strictly, in characters, we treat it as
3146            {        bytes to avoid spending too much time in this optimization. */
3147            register int pp = *p++;  
3148            if (pp == req_byte || pp == req_byte2) { p--; break; }        if (study != NULL && (study->flags & PCRE_STUDY_MINLEN) != 0 &&
3149            }            (pcre_uint32)(end_subject - current_subject) < study->minlength)
3150          }          return PCRE_ERROR_NOMATCH;
3151        else  
3152          /* If req_byte is set, we know that that character must appear in the
3153          subject for the match to succeed. If the first character is set, req_byte
3154          must be later in the subject; otherwise the test starts at the match
3155          point. This optimization can save a huge amount of work in patterns with
3156          nested unlimited repeats that aren't going to match. Writing separate
3157          code for cased/caseless versions makes it go faster, as does using an
3158          autoincrement and backing off on a match.
3159    
3160          HOWEVER: when the subject string is very, very long, searching to its end
3161          can take a long time, and give bad performance on quite ordinary
3162          patterns. This showed up when somebody was matching /^C/ on a 32-megabyte
3163          string... so we don't do this when the string is sufficiently long. */
3164    
3165          if (req_byte >= 0 && end_subject - current_subject < REQ_BYTE_MAX)
3166          {          {
3167          while (p < end_subject)          register const uschar *p = current_subject + ((first_byte >= 0)? 1 : 0);
3168    
3169            /* We don't need to repeat the search if we haven't yet reached the
3170            place we found it at last time. */
3171    
3172            if (p > req_byte_ptr)
3173            {            {
3174            if (*p++ == req_byte) { p--; break; }            if (req_byte_caseless)
3175            }              {
3176          }              while (p < end_subject)
3177                  {
3178                  register int pp = *p++;
3179                  if (pp == req_byte || pp == req_byte2) { p--; break; }
3180                  }
3181                }
3182              else
3183                {
3184                while (p < end_subject)
3185                  {
3186                  if (*p++ == req_byte) { p--; break; }
3187                  }
3188                }
3189    
3190        /* If we can't find the required character, break the matching loop,            /* If we can't find the required character, break the matching loop,
3191        which will cause a return or PCRE_ERROR_NOMATCH. */            which will cause a return or PCRE_ERROR_NOMATCH. */
3192    
3193        if (p >= end_subject) break;            if (p >= end_subject) break;
3194    
3195        /* If we have found the required character, save the point where we            /* If we have found the required character, save the point where we
3196        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
3197        the start hasn't passed this character yet. */            the start hasn't passed this character yet. */
3198    
3199        req_byte_ptr = p;            req_byte_ptr = p;
3200              }
3201            }
3202        }        }
3203      }      }   /* End of optimizations that are done when not restarting */
3204    
3205    /* OK, now we can do the business */    /* OK, now we can do the business */
3206    
3207      md->start_used_ptr = current_subject;
3208    
3209    rc = internal_dfa_exec(    rc = internal_dfa_exec(
3210      md,                                /* fixed match data */      md,                                /* fixed match data */
3211      md->start_code,                    /* this subexpression's code */      md->start_code,                    /* this subexpression's code */
# Line 2438  for (;;) Line 3236  for (;;)
3236      }      }
3237    if (current_subject > end_subject) break;    if (current_subject > end_subject) break;
3238    
3239    /* If we have just passed a CR and the newline option is CRLF or ANY or    /* If we have just passed a CR and we are now at a LF, and the pattern does
3240    ANYCRLF, and we are now at a LF, advance the match position by one more    not contain any explicit matches for \r or \n, and the newline option is CRLF
3241    character. */    or ANY or ANYCRLF, advance the match position by one more character. */
3242    
3243    if (current_subject[-1] == '\r' &&    if (current_subject[-1] == CHAR_CR &&
3244         (md->nltype == NLTYPE_ANY ||        current_subject < end_subject &&
3245          md->nltype == NLTYPE_ANYCRLF ||        *current_subject == CHAR_NL &&
3246          md->nllen == 2) &&        (re->flags & PCRE_HASCRORLF) == 0 &&
3247         current_subject < end_subject &&          (md->nltype == NLTYPE_ANY ||
3248         *current_subject == '\n')           md->nltype == NLTYPE_ANYCRLF ||
3249             md->nllen == 2))
3250      current_subject++;      current_subject++;
3251    
3252    }   /* "Bumpalong" loop */    }   /* "Bumpalong" loop */

Legend:
Removed from v.152  
changed lines
  Added in v.567

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12