/[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 130 by ph10, Mon Mar 26 15:09:47 2007 UTC revision 680 by ph10, Tue Sep 6 09:15:54 2011 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-2011 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, 0, 0, 0,                 /* \Z, \z, Opt, ^, $                      */    0, 0,                          /* \P, \p                                 */
122      0, 0, 0, 0, 0,                 /* \R, \H, \h, \V, \v                     */
123      0,                             /* \X                                     */
124      0, 0, 0, 0, 0, 0,              /* \Z, \z, ^, ^M, $, $M                   */
125    1,                             /* Char                                   */    1,                             /* Char                                   */
126    1,                             /* Charnc                                 */    1,                             /* Chari                                  */
127    1,                             /* not                                    */    1,                             /* not                                    */
128      1,                             /* noti                                   */
129    /* Positive single-char repeats                                          */    /* Positive single-char repeats                                          */
130    1, 1, 1, 1, 1, 1,              /* *, *?, +, +?, ?, ??                    */    1, 1, 1, 1, 1, 1,              /* *, *?, +, +?, ?, ??                    */
131    3, 3, 3,                       /* upto, minupto, exact                   */    3, 3, 3,                       /* upto, minupto, exact                   */
132    1, 1, 1, 3,                    /* *+, ++, ?+, upto+                      */    1, 1, 1, 3,                    /* *+, ++, ?+, upto+                      */
133      1, 1, 1, 1, 1, 1,              /* *I, *?I, +I, +?I, ?I, ??I              */
134      3, 3, 3,                       /* upto I, minupto I, exact I             */
135      1, 1, 1, 3,                    /* *+I, ++I, ?+I, upto+I                  */
136    /* Negative single-char repeats - only for chars < 256                   */    /* Negative single-char repeats - only for chars < 256                   */
137    1, 1, 1, 1, 1, 1,              /* NOT *, *?, +, +?, ?, ??                */    1, 1, 1, 1, 1, 1,              /* NOT *, *?, +, +?, ?, ??                */
138    3, 3, 3,                       /* NOT upto, minupto, exact               */    3, 3, 3,                       /* NOT upto, minupto, exact               */
139    1, 1, 1, 3,                    /* NOT *+, ++, ?+, updo+                  */    1, 1, 1, 3,                    /* NOT *+, ++, ?+, upto+                  */
140      1, 1, 1, 1, 1, 1,              /* NOT *I, *?I, +I, +?I, ?I, ??I          */
141      3, 3, 3,                       /* NOT upto I, minupto I, exact I         */
142      1, 1, 1, 3,                    /* NOT *+I, ++I, ?+I, upto+I              */
143    /* Positive type repeats                                                 */    /* Positive type repeats                                                 */
144    1, 1, 1, 1, 1, 1,              /* Type *, *?, +, +?, ?, ??               */    1, 1, 1, 1, 1, 1,              /* Type *, *?, +, +?, ?, ??               */
145    3, 3, 3,                       /* Type upto, minupto, exact              */    3, 3, 3,                       /* Type upto, minupto, exact              */
# Line 104  static uschar coptable[] = { Line 151  static uschar coptable[] = {
151    0,                             /* NCLASS                                 */    0,                             /* NCLASS                                 */
152    0,                             /* XCLASS - variable length               */    0,                             /* XCLASS - variable length               */
153    0,                             /* REF                                    */    0,                             /* REF                                    */
154      0,                             /* REFI                                   */
155    0,                             /* RECURSE                                */    0,                             /* RECURSE                                */
156    0,                             /* CALLOUT                                */    0,                             /* CALLOUT                                */
157    0,                             /* Alt                                    */    0,                             /* Alt                                    */
158    0,                             /* Ket                                    */    0,                             /* Ket                                    */
159    0,                             /* KetRmax                                */    0,                             /* KetRmax                                */
160    0,                             /* KetRmin                                */    0,                             /* KetRmin                                */
161      0,                             /* KetRpos                                */
162      0,                             /* Reverse                                */
163    0,                             /* Assert                                 */    0,                             /* Assert                                 */
164    0,                             /* Assert not                             */    0,                             /* Assert not                             */
165    0,                             /* Assert behind                          */    0,                             /* Assert behind                          */
166    0,                             /* Assert behind not                      */    0,                             /* Assert behind not                      */
167      0, 0, 0, 0, 0, 0,              /* ONCE, BRA, BRAPOS, CBRA, CBRAPOS, COND */
168      0, 0, 0, 0, 0,                 /* SBRA, SBRAPOS, SCBRA, SCBRAPOS, SCOND  */
169      0, 0,                          /* CREF, NCREF                            */
170      0, 0,                          /* RREF, NRREF                            */
171      0,                             /* DEF                                    */
172      0, 0, 0,                       /* BRAZERO, BRAMINZERO, BRAPOSZERO        */
173      0, 0, 0,                       /* MARK, PRUNE, PRUNE_ARG                 */
174      0, 0, 0, 0,                    /* SKIP, SKIP_ARG, THEN, THEN_ARG         */
175      0, 0, 0, 0,                    /* COMMIT, FAIL, ACCEPT, ASSERT_ACCEPT    */
176      0, 0                           /* CLOSE, SKIPZERO  */
177    };
178    
179    /* This table identifies those opcodes that inspect a character. It is used to
180    remember the fact that a character could have been inspected when the end of
181    the subject is reached. ***NOTE*** If the start of this table is modified, the
182    two tables that follow must also be modified. */
183    
184    static const uschar poptable[] = {
185      0,                             /* End                                    */
186      0, 0, 0, 1, 1,                 /* \A, \G, \K, \B, \b                     */
187      1, 1, 1, 1, 1, 1,              /* \D, \d, \S, \s, \W, \w                 */
188      1, 1, 1,                       /* Any, AllAny, Anybyte                   */
189      1, 1,                          /* \P, \p                                 */
190      1, 1, 1, 1, 1,                 /* \R, \H, \h, \V, \v                     */
191      1,                             /* \X                                     */
192      0, 0, 0, 0, 0, 0,              /* \Z, \z, ^, ^M, $, $M                   */
193      1,                             /* Char                                   */
194      1,                             /* Chari                                  */
195      1,                             /* not                                    */
196      1,                             /* noti                                   */
197      /* Positive single-char repeats                                          */
198      1, 1, 1, 1, 1, 1,              /* *, *?, +, +?, ?, ??                    */
199      1, 1, 1,                       /* upto, minupto, exact                   */
200      1, 1, 1, 1,                    /* *+, ++, ?+, upto+                      */
201      1, 1, 1, 1, 1, 1,              /* *I, *?I, +I, +?I, ?I, ??I              */
202      1, 1, 1,                       /* upto I, minupto I, exact I             */
203      1, 1, 1, 1,                    /* *+I, ++I, ?+I, upto+I                  */
204      /* Negative single-char repeats - only for chars < 256                   */
205      1, 1, 1, 1, 1, 1,              /* NOT *, *?, +, +?, ?, ??                */
206      1, 1, 1,                       /* NOT upto, minupto, exact               */
207      1, 1, 1, 1,                    /* NOT *+, ++, ?+, upto+                  */
208      1, 1, 1, 1, 1, 1,              /* NOT *I, *?I, +I, +?I, ?I, ??I          */
209      1, 1, 1,                       /* NOT upto I, minupto I, exact I         */
210      1, 1, 1, 1,                    /* NOT *+I, ++I, ?+I, upto+I              */
211      /* Positive type repeats                                                 */
212      1, 1, 1, 1, 1, 1,              /* Type *, *?, +, +?, ?, ??               */
213      1, 1, 1,                       /* Type upto, minupto, exact              */
214      1, 1, 1, 1,                    /* Type *+, ++, ?+, upto+                 */
215      /* Character class & ref repeats                                         */
216      1, 1, 1, 1, 1, 1,              /* *, *?, +, +?, ?, ??                    */
217      1, 1,                          /* CRRANGE, CRMINRANGE                    */
218      1,                             /* CLASS                                  */
219      1,                             /* NCLASS                                 */
220      1,                             /* XCLASS - variable length               */
221      0,                             /* REF                                    */
222      0,                             /* REFI                                   */
223      0,                             /* RECURSE                                */
224      0,                             /* CALLOUT                                */
225      0,                             /* Alt                                    */
226      0,                             /* Ket                                    */
227      0,                             /* KetRmax                                */
228      0,                             /* KetRmin                                */
229      0,                             /* KetRpos                                */
230    0,                             /* Reverse                                */    0,                             /* Reverse                                */
231    0, 0, 0, 0,                    /* ONCE, BRA, CBRA, COND                  */    0,                             /* Assert                                 */
232    0, 0, 0,                       /* SBRA, SCBRA, SCOND                     */    0,                             /* Assert not                             */
233    0,                             /* CREF                                   */    0,                             /* Assert behind                          */
234    0,                             /* RREF                                   */    0,                             /* Assert behind not                      */
235      0, 0, 0, 0, 0, 0,              /* ONCE, BRA, BRAPOS, CBRA, CBRAPOS, COND */
236      0, 0, 0, 0, 0,                 /* SBRA, SBRAPOS, SCBRA, SCBRAPOS, SCOND  */
237      0, 0,                          /* CREF, NCREF                            */
238      0, 0,                          /* RREF, NRREF                            */
239    0,                             /* DEF                                    */    0,                             /* DEF                                    */
240    0, 0                           /* BRAZERO, BRAMINZERO                    */    0, 0, 0,                       /* BRAZERO, BRAMINZERO, BRAPOSZERO        */
241      0, 0, 0,                       /* MARK, PRUNE, PRUNE_ARG                 */
242      0, 0, 0, 0,                    /* SKIP, SKIP_ARG, THEN, THEN_ARG         */
243      0, 0, 0, 0,                    /* COMMIT, FAIL, ACCEPT, ASSERT_ACCEPT    */
244      0, 0                           /* CLOSE, SKIPZERO                        */
245  };  };
246    
247  /* 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,
248  and \w */  and \w */
249    
250  static uschar toptable1[] = {  static const uschar toptable1[] = {
251    0, 0, 0, 0, 0,    0, 0, 0, 0, 0, 0,
252    ctype_digit, ctype_digit,    ctype_digit, ctype_digit,
253    ctype_space, ctype_space,    ctype_space, ctype_space,
254    ctype_word,  ctype_word,    ctype_word,  ctype_word,
255    0                               /* OP_ANY */    0, 0                            /* OP_ANY, OP_ALLANY */
256  };  };
257    
258  static uschar toptable2[] = {  static const uschar toptable2[] = {
259    0, 0, 0, 0, 0,    0, 0, 0, 0, 0, 0,
260    ctype_digit, 0,    ctype_digit, 0,
261    ctype_space, 0,    ctype_space, 0,
262    ctype_word,  0,    ctype_word,  0,
263    1                               /* OP_ANY */    1, 1                            /* OP_ANY, OP_ALLANY */
264  };  };
265    
266    
# Line 151  these structures in, is a vector of ints Line 272  these structures in, is a vector of ints
272  typedef struct stateblock {  typedef struct stateblock {
273    int offset;                     /* Offset to opcode */    int offset;                     /* Offset to opcode */
274    int count;                      /* Count for repeats */    int count;                      /* Count for repeats */
   int ims;                        /* ims flag bits */  
275    int data;                       /* Some use extra data */    int data;                       /* Some use extra data */
276  } stateblock;  } stateblock;
277    
278  #define INTS_PER_STATEBLOCK  (sizeof(stateblock)/sizeof(int))  #define INTS_PER_STATEBLOCK  (sizeof(stateblock)/sizeof(int))
279    
280    
281  #ifdef DEBUG  #ifdef PCRE_DEBUG
282  /*************************************************  /*************************************************
283  *             Print character string             *  *             Print character string             *
284  *************************************************/  *************************************************/
# Line 207  Arguments: Line 327  Arguments:
327    offsetcount       size of same    offsetcount       size of same
328    workspace         vector of workspace    workspace         vector of workspace
329    wscount           size of same    wscount           size of same
   ims               the current ims flags  
330    rlevel            function call recursion level    rlevel            function call recursion level
   recursing         regex recursive call level  
331    
332  Returns:            > 0 =>  Returns:            > 0 => number of match offset pairs placed in offsets
333                      = 0 =>                      = 0 => offsets overflowed; longest matches are present
334                       -1 => failed to match                       -1 => failed to match
335                     < -1 => some kind of unexpected problem                     < -1 => some kind of unexpected problem
336    
# Line 224  for the current character, one for the f Line 342  for the current character, one for the f
342      { \      { \
343      next_active_state->offset = (x); \      next_active_state->offset = (x); \
344      next_active_state->count  = (y); \      next_active_state->count  = (y); \
     next_active_state->ims    = ims; \  
345      next_active_state++; \      next_active_state++; \
346      DPRINTF(("%.*sADD_ACTIVE(%d,%d)\n", rlevel*2-2, SP, (x), (y))); \      DPRINTF(("%.*sADD_ACTIVE(%d,%d)\n", rlevel*2-2, SP, (x), (y))); \
347      } \      } \
# Line 235  for the current character, one for the f Line 352  for the current character, one for the f
352      { \      { \
353      next_active_state->offset = (x); \      next_active_state->offset = (x); \
354      next_active_state->count  = (y); \      next_active_state->count  = (y); \
     next_active_state->ims    = ims; \  
355      next_active_state->data   = (z); \      next_active_state->data   = (z); \
356      next_active_state++; \      next_active_state++; \
357      DPRINTF(("%.*sADD_ACTIVE_DATA(%d,%d,%d)\n", rlevel*2-2, SP, (x), (y), (z))); \      DPRINTF(("%.*sADD_ACTIVE_DATA(%d,%d,%d)\n", rlevel*2-2, SP, (x), (y), (z))); \
# Line 247  for the current character, one for the f Line 363  for the current character, one for the f
363      { \      { \
364      next_new_state->offset = (x); \      next_new_state->offset = (x); \
365      next_new_state->count  = (y); \      next_new_state->count  = (y); \
     next_new_state->ims    = ims; \  
366      next_new_state++; \      next_new_state++; \
367      DPRINTF(("%.*sADD_NEW(%d,%d)\n", rlevel*2-2, SP, (x), (y))); \      DPRINTF(("%.*sADD_NEW(%d,%d)\n", rlevel*2-2, SP, (x), (y))); \
368      } \      } \
# Line 258  for the current character, one for the f Line 373  for the current character, one for the f
373      { \      { \
374      next_new_state->offset = (x); \      next_new_state->offset = (x); \
375      next_new_state->count  = (y); \      next_new_state->count  = (y); \
     next_new_state->ims    = ims; \  
376      next_new_state->data   = (z); \      next_new_state->data   = (z); \
377      next_new_state++; \      next_new_state++; \
378      DPRINTF(("%.*sADD_NEW_DATA(%d,%d,%d)\n", rlevel*2-2, SP, (x), (y), (z))); \      DPRINTF(("%.*sADD_NEW_DATA(%d,%d,%d)\n", rlevel*2-2, SP, (x), (y), (z))); \
# Line 277  internal_dfa_exec( Line 391  internal_dfa_exec(
391    int offsetcount,    int offsetcount,
392    int *workspace,    int *workspace,
393    int wscount,    int wscount,
394    int ims,    int  rlevel)
   int  rlevel,  
   int  recursing)  
395  {  {
396  stateblock *active_states, *new_states, *temp_states;  stateblock *active_states, *new_states, *temp_states;
397  stateblock *next_active_state, *next_new_state;  stateblock *next_active_state, *next_new_state;
# Line 288  const uschar *ctypes, *lcc, *fcc; Line 400  const uschar *ctypes, *lcc, *fcc;
400  const uschar *ptr;  const uschar *ptr;
401  const uschar *end_code, *first_op;  const uschar *end_code, *first_op;
402    
403    dfa_recursion_info new_recursive;
404    
405  int active_count, new_count, match_count;  int active_count, new_count, match_count;
406    
407  /* Some fields in the md block are frequently referenced, so we load them into  /* Some fields in the md block are frequently referenced, so we load them into
# Line 311  wscount = (wscount - (wscount % (INTS_PE Line 425  wscount = (wscount - (wscount % (INTS_PE
425            (2 * INTS_PER_STATEBLOCK);            (2 * INTS_PER_STATEBLOCK);
426    
427  DPRINTF(("\n%.*s---------------------\n"  DPRINTF(("\n%.*s---------------------\n"
428    "%.*sCall to internal_dfa_exec f=%d r=%d\n",    "%.*sCall to internal_dfa_exec f=%d\n",
429    rlevel*2-2, SP, rlevel*2-2, SP, rlevel, recursing));    rlevel*2-2, SP, rlevel*2-2, SP, rlevel));
430    
431  ctypes = md->tables + ctypes_offset;  ctypes = md->tables + ctypes_offset;
432  lcc = md->tables + lcc_offset;  lcc = md->tables + lcc_offset;
# Line 325  next_new_state = new_states = active_sta Line 439  next_new_state = new_states = active_sta
439  new_count = 0;  new_count = 0;
440    
441  first_op = this_start_code + 1 + LINK_SIZE +  first_op = this_start_code + 1 + LINK_SIZE +
442    ((*this_start_code == OP_CBRA || *this_start_code == OP_SCBRA)? 2:0);    ((*this_start_code == OP_CBRA || *this_start_code == OP_SCBRA ||
443        *this_start_code == OP_CBRAPOS || *this_start_code == OP_SCBRAPOS)? 2:0);
444    
445  /* The first thing in any (sub) pattern is a bracket of some sort. Push all  /* The first thing in any (sub) pattern is a bracket of some sort. Push all
446  the alternative states onto the list, and find out where the end is. This  the alternative states onto the list, and find out where the end is. This
# Line 374  if (*first_op == OP_REVERSE) Line 489  if (*first_op == OP_REVERSE)
489    
490      {      {
491      gone_back = (current_subject - max_back < start_subject)?      gone_back = (current_subject - max_back < start_subject)?
492        current_subject - start_subject : max_back;        (int)(current_subject - start_subject) : max_back;
493      current_subject -= gone_back;      current_subject -= gone_back;
494      }      }
495    
496      /* Save the earliest consulted character */
497    
498      if (current_subject < md->start_used_ptr)
499        md->start_used_ptr = current_subject;
500    
501    /* Now we can process the individual branches. */    /* Now we can process the individual branches. */
502    
503    end_code = this_start_code;    end_code = this_start_code;
# Line 386  if (*first_op == OP_REVERSE) Line 506  if (*first_op == OP_REVERSE)
506      int back = GET(end_code, 2+LINK_SIZE);      int back = GET(end_code, 2+LINK_SIZE);
507      if (back <= gone_back)      if (back <= gone_back)
508        {        {
509        int bstate = end_code - start_code + 2 + 2*LINK_SIZE;        int bstate = (int)(end_code - start_code + 2 + 2*LINK_SIZE);
510        ADD_NEW_DATA(-bstate, 0, gone_back - back);        ADD_NEW_DATA(-bstate, 0, gone_back - back);
511        }        }
512      end_code += GET(end_code, 1);      end_code += GET(end_code, 1);
# Line 419  else Line 539  else
539    else    else
540      {      {
541      int length = 1 + LINK_SIZE +      int length = 1 + LINK_SIZE +
542        ((*this_start_code == OP_CBRA || *this_start_code == OP_SCBRA)? 2:0);        ((*this_start_code == OP_CBRA || *this_start_code == OP_SCBRA ||
543            *this_start_code == OP_CBRAPOS || *this_start_code == OP_SCBRAPOS)?
544            2:0);
545      do      do
546        {        {
547        ADD_NEW(end_code - start_code + length, 0);        ADD_NEW((int)(end_code - start_code + length), 0);
548        end_code += GET(end_code, 1);        end_code += GET(end_code, 1);
549        length = 1 + LINK_SIZE;        length = 1 + LINK_SIZE;
550        }        }
# Line 442  for (;;) Line 564  for (;;)
564    int i, j;    int i, j;
565    int clen, dlen;    int clen, dlen;
566    unsigned int c, d;    unsigned int c, d;
567      int forced_fail = 0;
568      BOOL could_continue = FALSE;
569    
570    /* 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
571    new state list. */    new state list. */
# Line 455  for (;;) Line 579  for (;;)
579    workspace[0] ^= 1;              /* Remember for the restarting feature */    workspace[0] ^= 1;              /* Remember for the restarting feature */
580    workspace[1] = active_count;    workspace[1] = active_count;
581    
582  #ifdef DEBUG  #ifdef PCRE_DEBUG
583    printf("%.*sNext character: rest of subject = \"", rlevel*2-2, SP);    printf("%.*sNext character: rest of subject = \"", rlevel*2-2, SP);
584    pchars((uschar *)ptr, strlen((char *)ptr), stdout);    pchars((uschar *)ptr, strlen((char *)ptr), stdout);
585    printf("\"\n");    printf("\"\n");
# Line 497  for (;;) Line 621  for (;;)
621    for (i = 0; i < active_count; i++)    for (i = 0; i < active_count; i++)
622      {      {
623      stateblock *current_state = active_states + i;      stateblock *current_state = active_states + i;
624        BOOL caseless = FALSE;
625      const uschar *code;      const uschar *code;
626      int state_offset = current_state->offset;      int state_offset = current_state->offset;
627      int count, codevalue;      int count, codevalue, rrc;
     int chartype, script;  
628    
629  #ifdef DEBUG  #ifdef PCRE_DEBUG
630      printf ("%.*sProcessing state %d c=", rlevel*2-2, SP, state_offset);      printf ("%.*sProcessing state %d c=", rlevel*2-2, SP, state_offset);
631      if (clen == 0) printf("EOL\n");      if (clen == 0) printf("EOL\n");
632        else if (c > 32 && c < 127) printf("'%c'\n", c);        else if (c > 32 && c < 127) printf("'%c'\n", c);
633          else printf("0x%02x\n", c);          else printf("0x%02x\n", c);
634  #endif  #endif
635    
     /* This variable is referred to implicity in the ADD_xxx macros. */  
   
     ims = current_state->ims;  
   
636      /* A negative offset is a special case meaning "hold off going to this      /* A negative offset is a special case meaning "hold off going to this
637      (negated) state until the number of characters in the data field have      (negated) state until the number of characters in the data field have
638      been skipped". */      been skipped". */
# Line 532  for (;;) Line 652  for (;;)
652          }          }
653        }        }
654    
655      /* 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.
656        See the note at the head of this module about the possibility of improving
657        performance here. */
658    
659      for (j = 0; j < i; j++)      for (j = 0; j < i; j++)
660        {        {
# Line 549  for (;;) Line 671  for (;;)
671      code = start_code + state_offset;      code = start_code + state_offset;
672      codevalue = *code;      codevalue = *code;
673    
674        /* If this opcode inspects a character, but we are at the end of the
675        subject, remember the fact for use when testing for a partial match. */
676    
677        if (clen == 0 && poptable[codevalue] != 0)
678          could_continue = TRUE;
679    
680      /* 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
681      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
682      is wrong, because sometimes zero repetitions of the subject are      is wrong, because sometimes zero repetitions of the subject are
683      permitted.      permitted.
684    
685      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
686      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
687      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
688      \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.
689      opcodes. */      */
690    
691      if (coptable[codevalue] > 0)      if (coptable[codevalue] > 0)
692        {        {
# Line 576  for (;;) Line 704  for (;;)
704            case OP_PROP: codevalue += OP_PROP_EXTRA; break;            case OP_PROP: codevalue += OP_PROP_EXTRA; break;
705            case OP_ANYNL: codevalue += OP_ANYNL_EXTRA; break;            case OP_ANYNL: codevalue += OP_ANYNL_EXTRA; break;
706            case OP_EXTUNI: codevalue += OP_EXTUNI_EXTRA; break;            case OP_EXTUNI: codevalue += OP_EXTUNI_EXTRA; break;
707              case OP_NOT_HSPACE:
708              case OP_HSPACE: codevalue += OP_HSPACE_EXTRA; break;
709              case OP_NOT_VSPACE:
710              case OP_VSPACE: codevalue += OP_VSPACE_EXTRA; break;
711            default: break;            default: break;
712            }            }
713          }          }
# Line 591  for (;;) Line 723  for (;;)
723    
724      switch (codevalue)      switch (codevalue)
725        {        {
726    /* ========================================================================== */
727          /* These cases are never obeyed. This is a fudge that causes a compile-
728          time error if the vectors coptable or poptable, which are indexed by
729          opcode, are not the correct length. It seems to be the only way to do
730          such a check at compile time, as the sizeof() operator does not work
731          in the C preprocessor. */
732    
733          case OP_TABLE_LENGTH:
734          case OP_TABLE_LENGTH +
735            ((sizeof(coptable) == OP_TABLE_LENGTH) &&
736             (sizeof(poptable) == OP_TABLE_LENGTH)):
737          break;
738    
739  /* ========================================================================== */  /* ========================================================================== */
740        /* 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
741        on with the next opcode. Otherwise, unless we have an empty string and        on with the next opcode. For repeating opcodes, also add the repeat
742        PCRE_NOTEMPTY is set, save the match data, shifting up all previous        state. Note that KETRPOS will always be encountered at the end of the
743          subpattern, because the possessive subpattern repeats are always handled
744          using recursive calls. Thus, it never adds any new states.
745    
746          At the end of the (sub)pattern, unless we have an empty string and
747          PCRE_NOTEMPTY is set, or PCRE_NOTEMPTY_ATSTART is set and we are at the
748          start of the subject, save the match data, shifting up all previous
749        matches so we always have the longest first. */        matches so we always have the longest first. */
750    
751        case OP_KET:        case OP_KET:
752        case OP_KETRMIN:        case OP_KETRMIN:
753        case OP_KETRMAX:        case OP_KETRMAX:
754          case OP_KETRPOS:
755        if (code != end_code)        if (code != end_code)
756          {          {
757          ADD_ACTIVE(state_offset + 1 + LINK_SIZE, 0);          ADD_ACTIVE(state_offset + 1 + LINK_SIZE, 0);
# Line 609  for (;;) Line 760  for (;;)
760            ADD_ACTIVE(state_offset - GET(code, 1), 0);            ADD_ACTIVE(state_offset - GET(code, 1), 0);
761            }            }
762          }          }
763        else if (ptr > current_subject || (md->moptions & PCRE_NOTEMPTY) == 0)        else
764          {          {
765          if (match_count < 0) match_count = (offsetcount >= 2)? 1 : 0;          if (ptr > current_subject ||
766            else if (match_count > 0 && ++match_count * 2 >= offsetcount)              ((md->moptions & PCRE_NOTEMPTY) == 0 &&
767              match_count = 0;                ((md->moptions & PCRE_NOTEMPTY_ATSTART) == 0 ||
768          count = ((match_count == 0)? offsetcount : match_count * 2) - 2;                  current_subject > start_subject + md->start_offset)))
769          if (count > 0) memmove(offsets + 2, offsets, count * sizeof(int));            {
770          if (offsetcount >= 2)            if (match_count < 0) match_count = (offsetcount >= 2)? 1 : 0;
771            {              else if (match_count > 0 && ++match_count * 2 > offsetcount)
772            offsets[0] = current_subject - start_subject;                match_count = 0;
773            offsets[1] = ptr - start_subject;            count = ((match_count == 0)? offsetcount : match_count * 2) - 2;
774            DPRINTF(("%.*sSet matched string = \"%.*s\"\n", rlevel*2-2, SP,            if (count > 0) memmove(offsets + 2, offsets, count * sizeof(int));
775              offsets[1] - offsets[0], current_subject));            if (offsetcount >= 2)
776            }              {
777          if ((md->moptions & PCRE_DFA_SHORTEST) != 0)              offsets[0] = (int)(current_subject - start_subject);
778            {              offsets[1] = (int)(ptr - start_subject);
779            DPRINTF(("%.*sEnd of internal_dfa_exec %d: returning %d\n"              DPRINTF(("%.*sSet matched string = \"%.*s\"\n", rlevel*2-2, SP,
780              "%.*s---------------------\n\n", rlevel*2-2, SP, rlevel,                offsets[1] - offsets[0], current_subject));
781              match_count, rlevel*2-2, SP));              }
782            return match_count;            if ((md->moptions & PCRE_DFA_SHORTEST) != 0)
783                {
784                DPRINTF(("%.*sEnd of internal_dfa_exec %d: returning %d\n"
785                  "%.*s---------------------\n\n", rlevel*2-2, SP, rlevel,
786                  match_count, rlevel*2-2, SP));
787                return match_count;
788                }
789            }            }
790          }          }
791        break;        break;
# Line 640  for (;;) Line 797  for (;;)
797        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
798        case OP_ALT:        case OP_ALT:
799        do { code += GET(code, 1); } while (*code == OP_ALT);        do { code += GET(code, 1); } while (*code == OP_ALT);
800        ADD_ACTIVE(code - start_code, 0);        ADD_ACTIVE((int)(code - start_code), 0);
801        break;        break;
802    
803        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
# Line 648  for (;;) Line 805  for (;;)
805        case OP_SBRA:        case OP_SBRA:
806        do        do
807          {          {
808          ADD_ACTIVE(code - start_code + 1 + LINK_SIZE, 0);          ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE), 0);
809          code += GET(code, 1);          code += GET(code, 1);
810          }          }
811        while (*code == OP_ALT);        while (*code == OP_ALT);
# Line 657  for (;;) Line 814  for (;;)
814        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
815        case OP_CBRA:        case OP_CBRA:
816        case OP_SCBRA:        case OP_SCBRA:
817        ADD_ACTIVE(code - start_code + 3 + LINK_SIZE,  0);        ADD_ACTIVE((int)(code - start_code + 3 + LINK_SIZE),  0);
818        code += GET(code, 1);        code += GET(code, 1);
819        while (*code == OP_ALT)        while (*code == OP_ALT)
820          {          {
821          ADD_ACTIVE(code - start_code + 1 + LINK_SIZE,  0);          ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE),  0);
822          code += GET(code, 1);          code += GET(code, 1);
823          }          }
824        break;        break;
# Line 672  for (;;) Line 829  for (;;)
829        ADD_ACTIVE(state_offset + 1, 0);        ADD_ACTIVE(state_offset + 1, 0);
830        code += 1 + GET(code, 2);        code += 1 + GET(code, 2);
831        while (*code == OP_ALT) code += GET(code, 1);        while (*code == OP_ALT) code += GET(code, 1);
832        ADD_ACTIVE(code - start_code + 1 + LINK_SIZE, 0);        ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE), 0);
833          break;
834    
835          /*-----------------------------------------------------------------*/
836          case OP_SKIPZERO:
837          code += 1 + GET(code, 2);
838          while (*code == OP_ALT) code += GET(code, 1);
839          ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE), 0);
840        break;        break;
841    
842        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
843        case OP_CIRC:        case OP_CIRC:
844        if ((ptr == start_subject && (md->moptions & PCRE_NOTBOL) == 0) ||        if (ptr == start_subject && (md->moptions & PCRE_NOTBOL) == 0)
           ((ims & PCRE_MULTILINE) != 0 &&  
             ptr != end_subject &&  
             WAS_NEWLINE(ptr)))  
845          { ADD_ACTIVE(state_offset + 1, 0); }          { ADD_ACTIVE(state_offset + 1, 0); }
846        break;        break;
847    
848        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
849        case OP_EOD:        case OP_CIRCM:
850        if (ptr >= end_subject) { ADD_ACTIVE(state_offset + 1, 0); }        if ((ptr == start_subject && (md->moptions & PCRE_NOTBOL) == 0) ||
851              (ptr != end_subject && WAS_NEWLINE(ptr)))
852            { ADD_ACTIVE(state_offset + 1, 0); }
853        break;        break;
854    
855        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
856        case OP_OPT:        case OP_EOD:
857        ims = code[1];        if (ptr >= end_subject)
858        ADD_ACTIVE(state_offset + 2, 0);          {
859            if ((md->moptions & PCRE_PARTIAL_HARD) != 0)
860              could_continue = TRUE;
861            else { ADD_ACTIVE(state_offset + 1, 0); }
862            }
863        break;        break;
864    
865        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
# Line 714  for (;;) Line 881  for (;;)
881    
882        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
883        case OP_ANY:        case OP_ANY:
884        if (clen > 0 && ((ims & PCRE_DOTALL) != 0 || !IS_NEWLINE(ptr)))        if (clen > 0 && !IS_NEWLINE(ptr))
885            { ADD_NEW(state_offset + 1, 0); }
886          break;
887    
888          /*-----------------------------------------------------------------*/
889          case OP_ALLANY:
890          if (clen > 0)
891          { ADD_NEW(state_offset + 1, 0); }          { ADD_NEW(state_offset + 1, 0); }
892        break;        break;
893    
894        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
895        case OP_EODN:        case OP_EODN:
896        if (clen == 0 || (IS_NEWLINE(ptr) && ptr == end_subject - md->nllen))        if (clen == 0 && (md->moptions & PCRE_PARTIAL_HARD) != 0)
897            could_continue = TRUE;
898          else if (clen == 0 || (IS_NEWLINE(ptr) && ptr == end_subject - md->nllen))
899          { ADD_ACTIVE(state_offset + 1, 0); }          { ADD_ACTIVE(state_offset + 1, 0); }
900        break;        break;
901    
# Line 728  for (;;) Line 903  for (;;)
903        case OP_DOLL:        case OP_DOLL:
904        if ((md->moptions & PCRE_NOTEOL) == 0)        if ((md->moptions & PCRE_NOTEOL) == 0)
905          {          {
906          if (clen == 0 ||          if (clen == 0 && (md->moptions & PCRE_PARTIAL_HARD) != 0)
907              (IS_NEWLINE(ptr) &&            could_continue = TRUE;
908                 ((ims & PCRE_MULTILINE) != 0 || ptr == end_subject - md->nllen)          else if (clen == 0 ||
909                ((md->poptions & PCRE_DOLLAR_ENDONLY) == 0 && IS_NEWLINE(ptr) &&
910                   (ptr == end_subject - md->nllen)
911              ))              ))
912            { ADD_ACTIVE(state_offset + 1, 0); }            { ADD_ACTIVE(state_offset + 1, 0); }
913          }          }
914        else if ((ims & PCRE_MULTILINE) != 0 && IS_NEWLINE(ptr))        break;
915    
916          /*-----------------------------------------------------------------*/
917          case OP_DOLLM:
918          if ((md->moptions & PCRE_NOTEOL) == 0)
919            {
920            if (clen == 0 && (md->moptions & PCRE_PARTIAL_HARD) != 0)
921              could_continue = TRUE;
922            else if (clen == 0 ||
923                ((md->poptions & PCRE_DOLLAR_ENDONLY) == 0 && IS_NEWLINE(ptr)))
924              { ADD_ACTIVE(state_offset + 1, 0); }
925            }
926          else if (IS_NEWLINE(ptr))
927          { ADD_ACTIVE(state_offset + 1, 0); }          { ADD_ACTIVE(state_offset + 1, 0); }
928        break;        break;
929    
# Line 766  for (;;) Line 955  for (;;)
955          if (ptr > start_subject)          if (ptr > start_subject)
956            {            {
957            const uschar *temp = ptr - 1;            const uschar *temp = ptr - 1;
958              if (temp < md->start_used_ptr) md->start_used_ptr = temp;
959  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
960            if (utf8) BACKCHAR(temp);            if (utf8) BACKCHAR(temp);
961  #endif  #endif
962            GETCHARTEST(d, temp);            GETCHARTEST(d, temp);
963    #ifdef SUPPORT_UCP
964              if ((md->poptions & PCRE_UCP) != 0)
965                {
966                if (d == '_') left_word = TRUE; else
967                  {
968                  int cat = UCD_CATEGORY(d);
969                  left_word = (cat == ucp_L || cat == ucp_N);
970                  }
971                }
972              else
973    #endif
974            left_word = d < 256 && (ctypes[d] & ctype_word) != 0;            left_word = d < 256 && (ctypes[d] & ctype_word) != 0;
975            }            }
976          else left_word = 0;          else left_word = FALSE;
977    
978          if (clen > 0) right_word = c < 256 && (ctypes[c] & ctype_word) != 0;          if (clen > 0)
979            else right_word = 0;            {
980    #ifdef SUPPORT_UCP
981              if ((md->poptions & PCRE_UCP) != 0)
982                {
983                if (c == '_') right_word = TRUE; else
984                  {
985                  int cat = UCD_CATEGORY(c);
986                  right_word = (cat == ucp_L || cat == ucp_N);
987                  }
988                }
989              else
990    #endif
991              right_word = c < 256 && (ctypes[c] & ctype_word) != 0;
992              }
993            else right_word = FALSE;
994    
995          if ((left_word == right_word) == (codevalue == OP_NOT_WORD_BOUNDARY))          if ((left_word == right_word) == (codevalue == OP_NOT_WORD_BOUNDARY))
996            { ADD_ACTIVE(state_offset + 1, 0); }            { ADD_ACTIVE(state_offset + 1, 0); }
# Line 783  for (;;) Line 998  for (;;)
998        break;        break;
999    
1000    
 #ifdef SUPPORT_UCP  
   
1001        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
1002        /* Check the next character by Unicode property. We will get here only        /* Check the next character by Unicode property. We will get here only
1003        if the support is in the binary; otherwise a compile-time error occurs.        if the support is in the binary; otherwise a compile-time error occurs.
1004        */        */
1005    
1006    #ifdef SUPPORT_UCP
1007        case OP_PROP:        case OP_PROP:
1008        case OP_NOTPROP:        case OP_NOTPROP:
1009        if (clen > 0)        if (clen > 0)
1010          {          {
1011          BOOL OK;          BOOL OK;
1012          int category = _pcre_ucp_findprop(c, &chartype, &script);          const ucd_record * prop = GET_UCD(c);
1013          switch(code[1])          switch(code[1])
1014            {            {
1015            case PT_ANY:            case PT_ANY:
# Line 803  for (;;) Line 1017  for (;;)
1017            break;            break;
1018    
1019            case PT_LAMP:            case PT_LAMP:
1020            OK = chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt;            OK = prop->chartype == ucp_Lu || prop->chartype == ucp_Ll ||
1021                   prop->chartype == ucp_Lt;
1022            break;            break;
1023    
1024            case PT_GC:            case PT_GC:
1025            OK = category == code[2];            OK = _pcre_ucp_gentype[prop->chartype] == code[2];
1026            break;            break;
1027    
1028            case PT_PC:            case PT_PC:
1029            OK = chartype == code[2];            OK = prop->chartype == code[2];
1030            break;            break;
1031    
1032            case PT_SC:            case PT_SC:
1033            OK = script == code[2];            OK = prop->script == code[2];
1034              break;
1035    
1036              /* These are specials for combination cases. */
1037    
1038              case PT_ALNUM:
1039              OK = _pcre_ucp_gentype[prop->chartype] == ucp_L ||
1040                   _pcre_ucp_gentype[prop->chartype] == ucp_N;
1041              break;
1042    
1043              case PT_SPACE:    /* Perl space */
1044              OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z ||
1045                   c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR;
1046              break;
1047    
1048              case PT_PXSPACE:  /* POSIX space */
1049              OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z ||
1050                   c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
1051                   c == CHAR_FF || c == CHAR_CR;
1052              break;
1053    
1054              case PT_WORD:
1055              OK = _pcre_ucp_gentype[prop->chartype] == ucp_L ||
1056                   _pcre_ucp_gentype[prop->chartype] == ucp_N ||
1057                   c == CHAR_UNDERSCORE;
1058            break;            break;
1059    
1060            /* Should never occur, but keep compilers from grumbling. */            /* Should never occur, but keep compilers from grumbling. */
# Line 835  for (;;) Line 1074  for (;;)
1074  /* ========================================================================== */  /* ========================================================================== */
1075        /* These opcodes likewise inspect the subject character, but have an        /* These opcodes likewise inspect the subject character, but have an
1076        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:
1077        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,
1078        OP_NOT_WORDCHAR. The value is loaded into d. */        OP_WORDCHAR, OP_NOT_WORDCHAR. The value is loaded into d. */
1079    
1080        case OP_TYPEPLUS:        case OP_TYPEPLUS:
1081        case OP_TYPEMINPLUS:        case OP_TYPEMINPLUS:
# Line 847  for (;;) Line 1086  for (;;)
1086          {          {
1087          if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||          if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
1088              (c < 256 &&              (c < 256 &&
1089                (d != OP_ANY ||                (d != OP_ANY || !IS_NEWLINE(ptr)) &&
                (ims & PCRE_DOTALL) != 0 ||  
                !IS_NEWLINE(ptr)  
               ) &&  
1090                ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))                ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
1091            {            {
1092            if (count > 0 && codevalue == OP_TYPEPOSPLUS)            if (count > 0 && codevalue == OP_TYPEPOSPLUS)
# Line 873  for (;;) Line 1109  for (;;)
1109          {          {
1110          if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||          if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
1111              (c < 256 &&              (c < 256 &&
1112                (d != OP_ANY ||                (d != OP_ANY || !IS_NEWLINE(ptr)) &&
                (ims & PCRE_DOTALL) != 0 ||  
                !IS_NEWLINE(ptr)  
               ) &&  
1113                ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))                ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
1114            {            {
1115            if (codevalue == OP_TYPEPOSQUERY)            if (codevalue == OP_TYPEPOSQUERY)
# Line 898  for (;;) Line 1131  for (;;)
1131          {          {
1132          if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||          if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
1133              (c < 256 &&              (c < 256 &&
1134                (d != OP_ANY ||                (d != OP_ANY || !IS_NEWLINE(ptr)) &&
                (ims & PCRE_DOTALL) != 0 ||  
                !IS_NEWLINE(ptr)  
               ) &&  
1135                ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))                ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
1136            {            {
1137            if (codevalue == OP_TYPEPOSSTAR)            if (codevalue == OP_TYPEPOSSTAR)
# Line 921  for (;;) Line 1151  for (;;)
1151          {          {
1152          if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||          if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
1153              (c < 256 &&              (c < 256 &&
1154                (d != OP_ANY ||                (d != OP_ANY || !IS_NEWLINE(ptr)) &&
                (ims & PCRE_DOTALL) != 0 ||  
                !IS_NEWLINE(ptr)  
               ) &&  
1155                ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))                ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
1156            {            {
1157            if (++count >= GET2(code, 1))            if (++count >= GET2(code, 1))
# Line 945  for (;;) Line 1172  for (;;)
1172          {          {
1173          if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||          if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
1174              (c < 256 &&              (c < 256 &&
1175                (d != OP_ANY ||                (d != OP_ANY || !IS_NEWLINE(ptr)) &&
                (ims & PCRE_DOTALL) != 0 ||  
                !IS_NEWLINE(ptr)  
               ) &&  
1176                ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))                ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
1177            {            {
1178            if (codevalue == OP_TYPEPOSUPTO)            if (codevalue == OP_TYPEPOSUPTO)
# Line 970  for (;;) Line 1194  for (;;)
1194        argument. It keeps the code above fast for the other cases. The argument        argument. It keeps the code above fast for the other cases. The argument
1195        is in the d variable. */        is in the d variable. */
1196    
1197    #ifdef SUPPORT_UCP
1198        case OP_PROP_EXTRA + OP_TYPEPLUS:        case OP_PROP_EXTRA + OP_TYPEPLUS:
1199        case OP_PROP_EXTRA + OP_TYPEMINPLUS:        case OP_PROP_EXTRA + OP_TYPEMINPLUS:
1200        case OP_PROP_EXTRA + OP_TYPEPOSPLUS:        case OP_PROP_EXTRA + OP_TYPEPOSPLUS:
# Line 978  for (;;) Line 1203  for (;;)
1203        if (clen > 0)        if (clen > 0)
1204          {          {
1205          BOOL OK;          BOOL OK;
1206          int category = _pcre_ucp_findprop(c, &chartype, &script);          const ucd_record * prop = GET_UCD(c);
1207          switch(code[2])          switch(code[2])
1208            {            {
1209            case PT_ANY:            case PT_ANY:
# Line 986  for (;;) Line 1211  for (;;)
1211            break;            break;
1212    
1213            case PT_LAMP:            case PT_LAMP:
1214            OK = chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt;            OK = prop->chartype == ucp_Lu || prop->chartype == ucp_Ll ||
1215                prop->chartype == ucp_Lt;
1216            break;            break;
1217    
1218            case PT_GC:            case PT_GC:
1219            OK = category == code[3];            OK = _pcre_ucp_gentype[prop->chartype] == code[3];
1220            break;            break;
1221    
1222            case PT_PC:            case PT_PC:
1223            OK = chartype == code[3];            OK = prop->chartype == code[3];
1224            break;            break;
1225    
1226            case PT_SC:            case PT_SC:
1227            OK = script == code[3];            OK = prop->script == code[3];
1228              break;
1229    
1230              /* These are specials for combination cases. */
1231    
1232              case PT_ALNUM:
1233              OK = _pcre_ucp_gentype[prop->chartype] == ucp_L ||
1234                   _pcre_ucp_gentype[prop->chartype] == ucp_N;
1235              break;
1236    
1237              case PT_SPACE:    /* Perl space */
1238              OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z ||
1239                   c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR;
1240              break;
1241    
1242              case PT_PXSPACE:  /* POSIX space */
1243              OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z ||
1244                   c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
1245                   c == CHAR_FF || c == CHAR_CR;
1246              break;
1247    
1248              case PT_WORD:
1249              OK = _pcre_ucp_gentype[prop->chartype] == ucp_L ||
1250                   _pcre_ucp_gentype[prop->chartype] == ucp_N ||
1251                   c == CHAR_UNDERSCORE;
1252            break;            break;
1253    
1254            /* Should never occur, but keep compilers from grumbling. */            /* Should never occur, but keep compilers from grumbling. */
# Line 1027  for (;;) Line 1277  for (;;)
1277        case OP_EXTUNI_EXTRA + OP_TYPEPOSPLUS:        case OP_EXTUNI_EXTRA + OP_TYPEPOSPLUS:
1278        count = current_state->count;  /* Already matched */        count = current_state->count;  /* Already matched */
1279        if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }        if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
1280        if (clen > 0 && _pcre_ucp_findprop(c, &chartype, &script) != ucp_M)        if (clen > 0 && UCD_CATEGORY(c) != ucp_M)
1281          {          {
1282          const uschar *nptr = ptr + clen;          const uschar *nptr = ptr + clen;
1283          int ncount = 0;          int ncount = 0;
# Line 1041  for (;;) Line 1291  for (;;)
1291            int nd;            int nd;
1292            int ndlen = 1;            int ndlen = 1;
1293            GETCHARLEN(nd, nptr, ndlen);            GETCHARLEN(nd, nptr, ndlen);
1294            if (_pcre_ucp_findprop(nd, &chartype, &script) != ucp_M) break;            if (UCD_CATEGORY(nd) != ucp_M) break;
1295            ncount++;            ncount++;
1296            nptr += ndlen;            nptr += ndlen;
1297            }            }
# Line 1049  for (;;) Line 1299  for (;;)
1299          ADD_NEW_DATA(-state_offset, count, ncount);          ADD_NEW_DATA(-state_offset, count, ncount);
1300          }          }
1301        break;        break;
1302    #endif
1303    
1304        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
1305        case OP_ANYNL_EXTRA + OP_TYPEPLUS:        case OP_ANYNL_EXTRA + OP_TYPEPLUS:
# Line 1061  for (;;) Line 1312  for (;;)
1312          int ncount = 0;          int ncount = 0;
1313          switch (c)          switch (c)
1314            {            {
1315              case 0x000b:
1316              case 0x000c:
1317              case 0x0085:
1318              case 0x2028:
1319              case 0x2029:
1320              if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break;
1321              goto ANYNL01;
1322    
1323            case 0x000d:            case 0x000d:
1324            if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1;            if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1;
1325            /* Fall through */            /* Fall through */
1326    
1327              ANYNL01:
1328              case 0x000a:
1329              if (count > 0 && codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSPLUS)
1330                {
1331                active_count--;           /* Remove non-match possibility */
1332                next_active_state--;
1333                }
1334              count++;
1335              ADD_NEW_DATA(-state_offset, count, ncount);
1336              break;
1337    
1338              default:
1339              break;
1340              }
1341            }
1342          break;
1343    
1344          /*-----------------------------------------------------------------*/
1345          case OP_VSPACE_EXTRA + OP_TYPEPLUS:
1346          case OP_VSPACE_EXTRA + OP_TYPEMINPLUS:
1347          case OP_VSPACE_EXTRA + OP_TYPEPOSPLUS:
1348          count = current_state->count;  /* Already matched */
1349          if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
1350          if (clen > 0)
1351            {
1352            BOOL OK;
1353            switch (c)
1354              {
1355            case 0x000a:            case 0x000a:
1356            case 0x000b:            case 0x000b:
1357            case 0x000c:            case 0x000c:
1358              case 0x000d:
1359            case 0x0085:            case 0x0085:
1360            case 0x2028:            case 0x2028:
1361            case 0x2029:            case 0x2029:
1362            if (count > 0 && codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSPLUS)            OK = TRUE;
1363              break;
1364    
1365              default:
1366              OK = FALSE;
1367              break;
1368              }
1369    
1370            if (OK == (d == OP_VSPACE))
1371              {
1372              if (count > 0 && codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSPLUS)
1373              {              {
1374              active_count--;           /* Remove non-match possibility */              active_count--;           /* Remove non-match possibility */
1375              next_active_state--;              next_active_state--;
1376              }              }
1377            count++;            count++;
1378            ADD_NEW_DATA(-state_offset, count, ncount);            ADD_NEW_DATA(-state_offset, count, 0);
1379              }
1380            }
1381          break;
1382    
1383          /*-----------------------------------------------------------------*/
1384          case OP_HSPACE_EXTRA + OP_TYPEPLUS:
1385          case OP_HSPACE_EXTRA + OP_TYPEMINPLUS:
1386          case OP_HSPACE_EXTRA + OP_TYPEPOSPLUS:
1387          count = current_state->count;  /* Already matched */
1388          if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
1389          if (clen > 0)
1390            {
1391            BOOL OK;
1392            switch (c)
1393              {
1394              case 0x09:      /* HT */
1395              case 0x20:      /* SPACE */
1396              case 0xa0:      /* NBSP */
1397              case 0x1680:    /* OGHAM SPACE MARK */
1398              case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1399              case 0x2000:    /* EN QUAD */
1400              case 0x2001:    /* EM QUAD */
1401              case 0x2002:    /* EN SPACE */
1402              case 0x2003:    /* EM SPACE */
1403              case 0x2004:    /* THREE-PER-EM SPACE */
1404              case 0x2005:    /* FOUR-PER-EM SPACE */
1405              case 0x2006:    /* SIX-PER-EM SPACE */
1406              case 0x2007:    /* FIGURE SPACE */
1407              case 0x2008:    /* PUNCTUATION SPACE */
1408              case 0x2009:    /* THIN SPACE */
1409              case 0x200A:    /* HAIR SPACE */
1410              case 0x202f:    /* NARROW NO-BREAK SPACE */
1411              case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1412              case 0x3000:    /* IDEOGRAPHIC SPACE */
1413              OK = TRUE;
1414            break;            break;
1415    
1416            default:            default:
1417              OK = FALSE;
1418            break;            break;
1419            }            }
1420    
1421            if (OK == (d == OP_HSPACE))
1422              {
1423              if (count > 0 && codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSPLUS)
1424                {
1425                active_count--;           /* Remove non-match possibility */
1426                next_active_state--;
1427                }
1428              count++;
1429              ADD_NEW_DATA(-state_offset, count, 0);
1430              }
1431          }          }
1432        break;        break;
1433    
1434        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
1435    #ifdef SUPPORT_UCP
1436        case OP_PROP_EXTRA + OP_TYPEQUERY:        case OP_PROP_EXTRA + OP_TYPEQUERY:
1437        case OP_PROP_EXTRA + OP_TYPEMINQUERY:        case OP_PROP_EXTRA + OP_TYPEMINQUERY:
1438        case OP_PROP_EXTRA + OP_TYPEPOSQUERY:        case OP_PROP_EXTRA + OP_TYPEPOSQUERY:
# Line 1102  for (;;) Line 1450  for (;;)
1450        if (clen > 0)        if (clen > 0)
1451          {          {
1452          BOOL OK;          BOOL OK;
1453          int category = _pcre_ucp_findprop(c, &chartype, &script);          const ucd_record * prop = GET_UCD(c);
1454          switch(code[2])          switch(code[2])
1455            {            {
1456            case PT_ANY:            case PT_ANY:
# Line 1110  for (;;) Line 1458  for (;;)
1458            break;            break;
1459    
1460            case PT_LAMP:            case PT_LAMP:
1461            OK = chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt;            OK = prop->chartype == ucp_Lu || prop->chartype == ucp_Ll ||
1462                prop->chartype == ucp_Lt;
1463            break;            break;
1464    
1465            case PT_GC:            case PT_GC:
1466            OK = category == code[3];            OK = _pcre_ucp_gentype[prop->chartype] == code[3];
1467            break;            break;
1468    
1469            case PT_PC:            case PT_PC:
1470            OK = chartype == code[3];            OK = prop->chartype == code[3];
1471            break;            break;
1472    
1473            case PT_SC:            case PT_SC:
1474            OK = script == code[3];            OK = prop->script == code[3];
1475              break;
1476    
1477              /* These are specials for combination cases. */
1478    
1479              case PT_ALNUM:
1480              OK = _pcre_ucp_gentype[prop->chartype] == ucp_L ||
1481                   _pcre_ucp_gentype[prop->chartype] == ucp_N;
1482              break;
1483    
1484              case PT_SPACE:    /* Perl space */
1485              OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z ||
1486                   c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR;
1487              break;
1488    
1489              case PT_PXSPACE:  /* POSIX space */
1490              OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z ||
1491                   c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
1492                   c == CHAR_FF || c == CHAR_CR;
1493              break;
1494    
1495              case PT_WORD:
1496              OK = _pcre_ucp_gentype[prop->chartype] == ucp_L ||
1497                   _pcre_ucp_gentype[prop->chartype] == ucp_N ||
1498                   c == CHAR_UNDERSCORE;
1499            break;            break;
1500    
1501            /* Should never occur, but keep compilers from grumbling. */            /* Should never occur, but keep compilers from grumbling. */
# Line 1160  for (;;) Line 1533  for (;;)
1533        QS2:        QS2:
1534    
1535        ADD_ACTIVE(state_offset + 2, 0);        ADD_ACTIVE(state_offset + 2, 0);
1536        if (clen > 0 && _pcre_ucp_findprop(c, &chartype, &script) != ucp_M)        if (clen > 0 && UCD_CATEGORY(c) != ucp_M)
1537          {          {
1538          const uschar *nptr = ptr + clen;          const uschar *nptr = ptr + clen;
1539          int ncount = 0;          int ncount = 0;
# Line 1175  for (;;) Line 1548  for (;;)
1548            int nd;            int nd;
1549            int ndlen = 1;            int ndlen = 1;
1550            GETCHARLEN(nd, nptr, ndlen);            GETCHARLEN(nd, nptr, ndlen);
1551            if (_pcre_ucp_findprop(nd, &chartype, &script) != ucp_M) break;            if (UCD_CATEGORY(nd) != ucp_M) break;
1552            ncount++;            ncount++;
1553            nptr += ndlen;            nptr += ndlen;
1554            }            }
1555          ADD_NEW_DATA(-(state_offset + count), 0, ncount);          ADD_NEW_DATA(-(state_offset + count), 0, ncount);
1556          }          }
1557        break;        break;
1558    #endif
1559    
1560        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
1561        case OP_ANYNL_EXTRA + OP_TYPEQUERY:        case OP_ANYNL_EXTRA + OP_TYPEQUERY:
# Line 1202  for (;;) Line 1576  for (;;)
1576          int ncount = 0;          int ncount = 0;
1577          switch (c)          switch (c)
1578            {            {
1579              case 0x000b:
1580              case 0x000c:
1581              case 0x0085:
1582              case 0x2028:
1583              case 0x2029:
1584              if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break;
1585              goto ANYNL02;
1586    
1587            case 0x000d:            case 0x000d:
1588            if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1;            if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1;
1589            /* Fall through */            /* Fall through */
1590    
1591              ANYNL02:
1592              case 0x000a:
1593              if (codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSSTAR ||
1594                  codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSQUERY)
1595                {
1596                active_count--;           /* Remove non-match possibility */
1597                next_active_state--;
1598                }
1599              ADD_NEW_DATA(-(state_offset + count), 0, ncount);
1600              break;
1601    
1602              default:
1603              break;
1604              }
1605            }
1606          break;
1607    
1608          /*-----------------------------------------------------------------*/
1609          case OP_VSPACE_EXTRA + OP_TYPEQUERY:
1610          case OP_VSPACE_EXTRA + OP_TYPEMINQUERY:
1611          case OP_VSPACE_EXTRA + OP_TYPEPOSQUERY:
1612          count = 2;
1613          goto QS4;
1614    
1615          case OP_VSPACE_EXTRA + OP_TYPESTAR:
1616          case OP_VSPACE_EXTRA + OP_TYPEMINSTAR:
1617          case OP_VSPACE_EXTRA + OP_TYPEPOSSTAR:
1618          count = 0;
1619    
1620          QS4:
1621          ADD_ACTIVE(state_offset + 2, 0);
1622          if (clen > 0)
1623            {
1624            BOOL OK;
1625            switch (c)
1626              {
1627            case 0x000a:            case 0x000a:
1628            case 0x000b:            case 0x000b:
1629            case 0x000c:            case 0x000c:
1630              case 0x000d:
1631            case 0x0085:            case 0x0085:
1632            case 0x2028:            case 0x2028:
1633            case 0x2029:            case 0x2029:
1634            if (codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSSTAR ||            OK = TRUE;
1635                codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSQUERY)            break;
1636    
1637              default:
1638              OK = FALSE;
1639              break;
1640              }
1641            if (OK == (d == OP_VSPACE))
1642              {
1643              if (codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSSTAR ||
1644                  codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSQUERY)
1645              {              {
1646              active_count--;           /* Remove non-match possibility */              active_count--;           /* Remove non-match possibility */
1647              next_active_state--;              next_active_state--;
1648              }              }
1649            ADD_NEW_DATA(-(state_offset + count), 0, ncount);            ADD_NEW_DATA(-(state_offset + count), 0, 0);
1650              }
1651            }
1652          break;
1653    
1654          /*-----------------------------------------------------------------*/
1655          case OP_HSPACE_EXTRA + OP_TYPEQUERY:
1656          case OP_HSPACE_EXTRA + OP_TYPEMINQUERY:
1657          case OP_HSPACE_EXTRA + OP_TYPEPOSQUERY:
1658          count = 2;
1659          goto QS5;
1660    
1661          case OP_HSPACE_EXTRA + OP_TYPESTAR:
1662          case OP_HSPACE_EXTRA + OP_TYPEMINSTAR:
1663          case OP_HSPACE_EXTRA + OP_TYPEPOSSTAR:
1664          count = 0;
1665    
1666          QS5:
1667          ADD_ACTIVE(state_offset + 2, 0);
1668          if (clen > 0)
1669            {
1670            BOOL OK;
1671            switch (c)
1672              {
1673              case 0x09:      /* HT */
1674              case 0x20:      /* SPACE */
1675              case 0xa0:      /* NBSP */
1676              case 0x1680:    /* OGHAM SPACE MARK */
1677              case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1678              case 0x2000:    /* EN QUAD */
1679              case 0x2001:    /* EM QUAD */
1680              case 0x2002:    /* EN SPACE */
1681              case 0x2003:    /* EM SPACE */
1682              case 0x2004:    /* THREE-PER-EM SPACE */
1683              case 0x2005:    /* FOUR-PER-EM SPACE */
1684              case 0x2006:    /* SIX-PER-EM SPACE */
1685              case 0x2007:    /* FIGURE SPACE */
1686              case 0x2008:    /* PUNCTUATION SPACE */
1687              case 0x2009:    /* THIN SPACE */
1688              case 0x200A:    /* HAIR SPACE */
1689              case 0x202f:    /* NARROW NO-BREAK SPACE */
1690              case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1691              case 0x3000:    /* IDEOGRAPHIC SPACE */
1692              OK = TRUE;
1693            break;            break;
1694    
1695            default:            default:
1696              OK = FALSE;
1697            break;            break;
1698            }            }
1699    
1700            if (OK == (d == OP_HSPACE))
1701              {
1702              if (codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSSTAR ||
1703                  codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSQUERY)
1704                {
1705                active_count--;           /* Remove non-match possibility */
1706                next_active_state--;
1707                }
1708              ADD_NEW_DATA(-(state_offset + count), 0, 0);
1709              }
1710          }          }
1711        break;        break;
1712    
1713        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
1714    #ifdef SUPPORT_UCP
1715        case OP_PROP_EXTRA + OP_TYPEEXACT:        case OP_PROP_EXTRA + OP_TYPEEXACT:
1716        case OP_PROP_EXTRA + OP_TYPEUPTO:        case OP_PROP_EXTRA + OP_TYPEUPTO:
1717        case OP_PROP_EXTRA + OP_TYPEMINUPTO:        case OP_PROP_EXTRA + OP_TYPEMINUPTO:
# Line 1236  for (;;) Line 1722  for (;;)
1722        if (clen > 0)        if (clen > 0)
1723          {          {
1724          BOOL OK;          BOOL OK;
1725          int category = _pcre_ucp_findprop(c, &chartype, &script);          const ucd_record * prop = GET_UCD(c);
1726          switch(code[4])          switch(code[4])
1727            {            {
1728            case PT_ANY:            case PT_ANY:
# Line 1244  for (;;) Line 1730  for (;;)
1730            break;            break;
1731    
1732            case PT_LAMP:            case PT_LAMP:
1733            OK = chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt;            OK = prop->chartype == ucp_Lu || prop->chartype == ucp_Ll ||
1734                prop->chartype == ucp_Lt;
1735            break;            break;
1736    
1737            case PT_GC:            case PT_GC:
1738            OK = category == code[5];            OK = _pcre_ucp_gentype[prop->chartype] == code[5];
1739            break;            break;
1740    
1741            case PT_PC:            case PT_PC:
1742            OK = chartype == code[5];            OK = prop->chartype == code[5];
1743            break;            break;
1744    
1745            case PT_SC:            case PT_SC:
1746            OK = script == code[5];            OK = prop->script == code[5];
1747            break;            break;
1748    
1749            /* Should never occur, but keep compilers from grumbling. */            /* These are specials for combination cases. */
1750    
1751            default:            case PT_ALNUM:
1752              OK = _pcre_ucp_gentype[prop->chartype] == ucp_L ||
1753                   _pcre_ucp_gentype[prop->chartype] == ucp_N;
1754              break;
1755    
1756              case PT_SPACE:    /* Perl space */
1757              OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z ||
1758                   c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR;
1759              break;
1760    
1761              case PT_PXSPACE:  /* POSIX space */
1762              OK = _pcre_ucp_gentype[prop->chartype] == ucp_Z ||
1763                   c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
1764                   c == CHAR_FF || c == CHAR_CR;
1765              break;
1766    
1767              case PT_WORD:
1768              OK = _pcre_ucp_gentype[prop->chartype] == ucp_L ||
1769                   _pcre_ucp_gentype[prop->chartype] == ucp_N ||
1770                   c == CHAR_UNDERSCORE;
1771              break;
1772    
1773              /* Should never occur, but keep compilers from grumbling. */
1774    
1775              default:
1776            OK = codevalue != OP_PROP;            OK = codevalue != OP_PROP;
1777            break;            break;
1778            }            }
# Line 1289  for (;;) Line 1800  for (;;)
1800        if (codevalue != OP_EXTUNI_EXTRA + OP_TYPEEXACT)        if (codevalue != OP_EXTUNI_EXTRA + OP_TYPEEXACT)
1801          { ADD_ACTIVE(state_offset + 4, 0); }          { ADD_ACTIVE(state_offset + 4, 0); }
1802        count = current_state->count;  /* Number already matched */        count = current_state->count;  /* Number already matched */
1803        if (clen > 0 && _pcre_ucp_findprop(c, &chartype, &script) != ucp_M)        if (clen > 0 && UCD_CATEGORY(c) != ucp_M)
1804          {          {
1805          const uschar *nptr = ptr + clen;          const uschar *nptr = ptr + clen;
1806          int ncount = 0;          int ncount = 0;
# Line 1303  for (;;) Line 1814  for (;;)
1814            int nd;            int nd;
1815            int ndlen = 1;            int ndlen = 1;
1816            GETCHARLEN(nd, nptr, ndlen);            GETCHARLEN(nd, nptr, ndlen);
1817            if (_pcre_ucp_findprop(nd, &chartype, &script) != ucp_M) break;            if (UCD_CATEGORY(nd) != ucp_M) break;
1818            ncount++;            ncount++;
1819            nptr += ndlen;            nptr += ndlen;
1820            }            }
# Line 1313  for (;;) Line 1824  for (;;)
1824            { ADD_NEW_DATA(-state_offset, count, ncount); }            { ADD_NEW_DATA(-state_offset, count, ncount); }
1825          }          }
1826        break;        break;
1827    #endif
1828    
1829        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
1830        case OP_ANYNL_EXTRA + OP_TYPEEXACT:        case OP_ANYNL_EXTRA + OP_TYPEEXACT:
# Line 1327  for (;;) Line 1839  for (;;)
1839          int ncount = 0;          int ncount = 0;
1840          switch (c)          switch (c)
1841            {            {
1842              case 0x000b:
1843              case 0x000c:
1844              case 0x0085:
1845              case 0x2028:
1846              case 0x2029:
1847              if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break;
1848              goto ANYNL03;
1849    
1850            case 0x000d:            case 0x000d:
1851            if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1;            if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1;
1852            /* Fall through */            /* Fall through */
1853    
1854              ANYNL03:
1855              case 0x000a:
1856              if (codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSUPTO)
1857                {
1858                active_count--;           /* Remove non-match possibility */
1859                next_active_state--;
1860                }
1861              if (++count >= GET2(code, 1))
1862                { ADD_NEW_DATA(-(state_offset + 4), 0, ncount); }
1863              else
1864                { ADD_NEW_DATA(-state_offset, count, ncount); }
1865              break;
1866    
1867              default:
1868              break;
1869              }
1870            }
1871          break;
1872    
1873          /*-----------------------------------------------------------------*/
1874          case OP_VSPACE_EXTRA + OP_TYPEEXACT:
1875          case OP_VSPACE_EXTRA + OP_TYPEUPTO:
1876          case OP_VSPACE_EXTRA + OP_TYPEMINUPTO:
1877          case OP_VSPACE_EXTRA + OP_TYPEPOSUPTO:
1878          if (codevalue != OP_VSPACE_EXTRA + OP_TYPEEXACT)
1879            { ADD_ACTIVE(state_offset + 4, 0); }
1880          count = current_state->count;  /* Number already matched */
1881          if (clen > 0)
1882            {
1883            BOOL OK;
1884            switch (c)
1885              {
1886            case 0x000a:            case 0x000a:
1887            case 0x000b:            case 0x000b:
1888            case 0x000c:            case 0x000c:
1889              case 0x000d:
1890            case 0x0085:            case 0x0085:
1891            case 0x2028:            case 0x2028:
1892            case 0x2029:            case 0x2029:
1893            if (codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSUPTO)            OK = TRUE;
1894              break;
1895    
1896              default:
1897              OK = FALSE;
1898              }
1899    
1900            if (OK == (d == OP_VSPACE))
1901              {
1902              if (codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSUPTO)
1903              {              {
1904              active_count--;           /* Remove non-match possibility */              active_count--;           /* Remove non-match possibility */
1905              next_active_state--;              next_active_state--;
1906              }              }
1907            if (++count >= GET2(code, 1))            if (++count >= GET2(code, 1))
1908              { ADD_NEW_DATA(-(state_offset + 4), 0, ncount); }              { ADD_NEW_DATA(-(state_offset + 4), 0, 0); }
1909            else            else
1910              { ADD_NEW_DATA(-state_offset, count, ncount); }              { ADD_NEW_DATA(-state_offset, count, 0); }
1911              }
1912            }
1913          break;
1914    
1915          /*-----------------------------------------------------------------*/
1916          case OP_HSPACE_EXTRA + OP_TYPEEXACT:
1917          case OP_HSPACE_EXTRA + OP_TYPEUPTO:
1918          case OP_HSPACE_EXTRA + OP_TYPEMINUPTO:
1919          case OP_HSPACE_EXTRA + OP_TYPEPOSUPTO:
1920          if (codevalue != OP_HSPACE_EXTRA + OP_TYPEEXACT)
1921            { ADD_ACTIVE(state_offset + 4, 0); }
1922          count = current_state->count;  /* Number already matched */
1923          if (clen > 0)
1924            {
1925            BOOL OK;
1926            switch (c)
1927              {
1928              case 0x09:      /* HT */
1929              case 0x20:      /* SPACE */
1930              case 0xa0:      /* NBSP */
1931              case 0x1680:    /* OGHAM SPACE MARK */
1932              case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1933              case 0x2000:    /* EN QUAD */
1934              case 0x2001:    /* EM QUAD */
1935              case 0x2002:    /* EN SPACE */
1936              case 0x2003:    /* EM SPACE */
1937              case 0x2004:    /* THREE-PER-EM SPACE */
1938              case 0x2005:    /* FOUR-PER-EM SPACE */
1939              case 0x2006:    /* SIX-PER-EM SPACE */
1940              case 0x2007:    /* FIGURE SPACE */
1941              case 0x2008:    /* PUNCTUATION SPACE */
1942              case 0x2009:    /* THIN SPACE */
1943              case 0x200A:    /* HAIR SPACE */
1944              case 0x202f:    /* NARROW NO-BREAK SPACE */
1945              case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1946              case 0x3000:    /* IDEOGRAPHIC SPACE */
1947              OK = TRUE;
1948            break;            break;
1949    
1950            default:            default:
1951              OK = FALSE;
1952            break;            break;
1953            }            }
1954    
1955            if (OK == (d == OP_HSPACE))
1956              {
1957              if (codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSUPTO)
1958                {
1959                active_count--;           /* Remove non-match possibility */
1960                next_active_state--;
1961                }
1962              if (++count >= GET2(code, 1))
1963                { ADD_NEW_DATA(-(state_offset + 4), 0, 0); }
1964              else
1965                { ADD_NEW_DATA(-state_offset, count, 0); }
1966              }
1967          }          }
1968        break;        break;
1969    
# Line 1364  for (;;) Line 1979  for (;;)
1979        break;        break;
1980    
1981        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
1982        case OP_CHARNC:        case OP_CHARI:
1983        if (clen == 0) break;        if (clen == 0) break;
1984    
1985  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1379  for (;;) Line 1994  for (;;)
1994            other case of the character. */            other case of the character. */
1995    
1996  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
1997            othercase = _pcre_ucp_othercase(c);            othercase = UCD_OTHERCASE(c);
1998  #else  #else
1999            othercase = NOTACHAR;            othercase = NOTACHAR;
2000  #endif  #endif
# Line 1404  for (;;) Line 2019  for (;;)
2019        to wait for them to pass before continuing. */        to wait for them to pass before continuing. */
2020    
2021        case OP_EXTUNI:        case OP_EXTUNI:
2022        if (clen > 0 && _pcre_ucp_findprop(c, &chartype, &script) != ucp_M)        if (clen > 0 && UCD_CATEGORY(c) != ucp_M)
2023          {          {
2024          const uschar *nptr = ptr + clen;          const uschar *nptr = ptr + clen;
2025          int ncount = 0;          int ncount = 0;
# Line 1412  for (;;) Line 2027  for (;;)
2027            {            {
2028            int nclen = 1;            int nclen = 1;
2029            GETCHARLEN(c, nptr, nclen);            GETCHARLEN(c, nptr, nclen);
2030            if (_pcre_ucp_findprop(c, &chartype, &script) != ucp_M) break;            if (UCD_CATEGORY(c) != ucp_M) break;
2031            ncount++;            ncount++;
2032            nptr += nclen;            nptr += nclen;
2033            }            }
# Line 1429  for (;;) Line 2044  for (;;)
2044        case OP_ANYNL:        case OP_ANYNL:
2045        if (clen > 0) switch(c)        if (clen > 0) switch(c)
2046          {          {
         case 0x000a:  
2047          case 0x000b:          case 0x000b:
2048          case 0x000c:          case 0x000c:
2049          case 0x0085:          case 0x0085:
2050          case 0x2028:          case 0x2028:
2051          case 0x2029:          case 0x2029:
2052            if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break;
2053    
2054            case 0x000a:
2055          ADD_NEW(state_offset + 1, 0);          ADD_NEW(state_offset + 1, 0);
2056          break;          break;
2057    
2058          case 0x000d:          case 0x000d:
2059          if (ptr + 1 < end_subject && ptr[1] == 0x0a)          if (ptr + 1 < end_subject && ptr[1] == 0x0a)
2060            {            {
# Line 1451  for (;;) Line 2069  for (;;)
2069        break;        break;
2070    
2071        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
2072        /* Match a negated single character. This is only used for one-byte        case OP_NOT_VSPACE:
2073        characters, that is, we know that d < 256. The character we are        if (clen > 0) switch(c)
2074        checking (c) can be multibyte. */          {
2075            case 0x000a:
2076            case 0x000b:
2077            case 0x000c:
2078            case 0x000d:
2079            case 0x0085:
2080            case 0x2028:
2081            case 0x2029:
2082            break;
2083    
2084        case OP_NOT:          default:
2085        if (clen > 0)          ADD_NEW(state_offset + 1, 0);
2086            break;
2087            }
2088          break;
2089    
2090          /*-----------------------------------------------------------------*/
2091          case OP_VSPACE:
2092          if (clen > 0) switch(c)
2093          {          {
2094          unsigned int otherd = ((ims & PCRE_CASELESS) != 0)? fcc[d] : d;          case 0x000a:
2095          if (c != d && c != otherd) { ADD_NEW(state_offset + dlen + 1, 0); }          case 0x000b:
2096            case 0x000c:
2097            case 0x000d:
2098            case 0x0085:
2099            case 0x2028:
2100            case 0x2029:
2101            ADD_NEW(state_offset + 1, 0);
2102            break;
2103    
2104            default: break;
2105            }
2106          break;
2107    
2108          /*-----------------------------------------------------------------*/
2109          case OP_NOT_HSPACE:
2110          if (clen > 0) switch(c)
2111            {
2112            case 0x09:      /* HT */
2113            case 0x20:      /* SPACE */
2114            case 0xa0:      /* NBSP */
2115            case 0x1680:    /* OGHAM SPACE MARK */
2116            case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
2117            case 0x2000:    /* EN QUAD */
2118            case 0x2001:    /* EM QUAD */
2119            case 0x2002:    /* EN SPACE */
2120            case 0x2003:    /* EM SPACE */
2121            case 0x2004:    /* THREE-PER-EM SPACE */
2122            case 0x2005:    /* FOUR-PER-EM SPACE */
2123            case 0x2006:    /* SIX-PER-EM SPACE */
2124            case 0x2007:    /* FIGURE SPACE */
2125            case 0x2008:    /* PUNCTUATION SPACE */
2126            case 0x2009:    /* THIN SPACE */
2127            case 0x200A:    /* HAIR SPACE */
2128            case 0x202f:    /* NARROW NO-BREAK SPACE */
2129            case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
2130            case 0x3000:    /* IDEOGRAPHIC SPACE */
2131            break;
2132    
2133            default:
2134            ADD_NEW(state_offset + 1, 0);
2135            break;
2136          }          }
2137        break;        break;
2138    
2139        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
2140          case OP_HSPACE:
2141          if (clen > 0) switch(c)
2142            {
2143            case 0x09:      /* HT */
2144            case 0x20:      /* SPACE */
2145            case 0xa0:      /* NBSP */
2146            case 0x1680:    /* OGHAM SPACE MARK */
2147            case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
2148            case 0x2000:    /* EN QUAD */
2149            case 0x2001:    /* EM QUAD */
2150            case 0x2002:    /* EN SPACE */
2151            case 0x2003:    /* EM SPACE */
2152            case 0x2004:    /* THREE-PER-EM SPACE */
2153            case 0x2005:    /* FOUR-PER-EM SPACE */
2154            case 0x2006:    /* SIX-PER-EM SPACE */
2155            case 0x2007:    /* FIGURE SPACE */
2156            case 0x2008:    /* PUNCTUATION SPACE */
2157            case 0x2009:    /* THIN SPACE */
2158            case 0x200A:    /* HAIR SPACE */
2159            case 0x202f:    /* NARROW NO-BREAK SPACE */
2160            case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
2161            case 0x3000:    /* IDEOGRAPHIC SPACE */
2162            ADD_NEW(state_offset + 1, 0);
2163            break;
2164            }
2165          break;
2166    
2167          /*-----------------------------------------------------------------*/
2168          /* Match a negated single character casefully. This is only used for
2169          one-byte characters, that is, we know that d < 256. The character we are
2170          checking (c) can be multibyte. */
2171    
2172          case OP_NOT:
2173          if (clen > 0 && c != d) { ADD_NEW(state_offset + dlen + 1, 0); }
2174          break;
2175    
2176          /*-----------------------------------------------------------------*/
2177          /* Match a negated single character caselessly. This is only used for
2178          one-byte characters, that is, we know that d < 256. The character we are
2179          checking (c) can be multibyte. */
2180    
2181          case OP_NOTI:
2182          if (clen > 0 && c != d && c != fcc[d])
2183            { ADD_NEW(state_offset + dlen + 1, 0); }
2184          break;
2185    
2186          /*-----------------------------------------------------------------*/
2187          case OP_PLUSI:
2188          case OP_MINPLUSI:
2189          case OP_POSPLUSI:
2190          case OP_NOTPLUSI:
2191          case OP_NOTMINPLUSI:
2192          case OP_NOTPOSPLUSI:
2193          caseless = TRUE;
2194          codevalue -= OP_STARI - OP_STAR;
2195    
2196          /* Fall through */
2197        case OP_PLUS:        case OP_PLUS:
2198        case OP_MINPLUS:        case OP_MINPLUS:
2199        case OP_POSPLUS:        case OP_POSPLUS:
# Line 1475  for (;;) Line 2205  for (;;)
2205        if (clen > 0)        if (clen > 0)
2206          {          {
2207          unsigned int otherd = NOTACHAR;          unsigned int otherd = NOTACHAR;
2208          if ((ims & PCRE_CASELESS) != 0)          if (caseless)
2209            {            {
2210  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2211            if (utf8 && d >= 128)            if (utf8 && d >= 128)
2212              {              {
2213  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2214              otherd = _pcre_ucp_othercase(d);              otherd = UCD_OTHERCASE(d);
2215  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2216              }              }
2217            else            else
# Line 1503  for (;;) Line 2233  for (;;)
2233        break;        break;
2234    
2235        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
2236          case OP_QUERYI:
2237          case OP_MINQUERYI:
2238          case OP_POSQUERYI:
2239          case OP_NOTQUERYI:
2240          case OP_NOTMINQUERYI:
2241          case OP_NOTPOSQUERYI:
2242          caseless = TRUE;
2243          codevalue -= OP_STARI - OP_STAR;
2244          /* Fall through */
2245        case OP_QUERY:        case OP_QUERY:
2246        case OP_MINQUERY:        case OP_MINQUERY:
2247        case OP_POSQUERY:        case OP_POSQUERY:
# Line 1513  for (;;) Line 2252  for (;;)
2252        if (clen > 0)        if (clen > 0)
2253          {          {
2254          unsigned int otherd = NOTACHAR;          unsigned int otherd = NOTACHAR;
2255          if ((ims & PCRE_CASELESS) != 0)          if (caseless)
2256            {            {
2257  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2258            if (utf8 && d >= 128)            if (utf8 && d >= 128)
2259              {              {
2260  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2261              otherd = _pcre_ucp_othercase(d);              otherd = UCD_OTHERCASE(d);
2262  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2263              }              }
2264            else            else
# Line 1539  for (;;) Line 2278  for (;;)
2278        break;        break;
2279    
2280        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
2281          case OP_STARI:
2282          case OP_MINSTARI:
2283          case OP_POSSTARI:
2284          case OP_NOTSTARI:
2285          case OP_NOTMINSTARI:
2286          case OP_NOTPOSSTARI:
2287          caseless = TRUE;
2288          codevalue -= OP_STARI - OP_STAR;
2289          /* Fall through */
2290        case OP_STAR:        case OP_STAR:
2291        case OP_MINSTAR:        case OP_MINSTAR:
2292        case OP_POSSTAR:        case OP_POSSTAR:
# Line 1549  for (;;) Line 2297  for (;;)
2297        if (clen > 0)        if (clen > 0)
2298          {          {
2299          unsigned int otherd = NOTACHAR;          unsigned int otherd = NOTACHAR;
2300          if ((ims & PCRE_CASELESS) != 0)          if (caseless)
2301            {            {
2302  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2303            if (utf8 && d >= 128)            if (utf8 && d >= 128)
2304              {              {
2305  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2306              otherd = _pcre_ucp_othercase(d);              otherd = UCD_OTHERCASE(d);
2307  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2308              }              }
2309            else            else
# Line 1575  for (;;) Line 2323  for (;;)
2323        break;        break;
2324    
2325        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
2326          case OP_EXACTI:
2327          case OP_NOTEXACTI:
2328          caseless = TRUE;
2329          codevalue -= OP_STARI - OP_STAR;
2330          /* Fall through */
2331        case OP_EXACT:        case OP_EXACT:
2332        case OP_NOTEXACT:        case OP_NOTEXACT:
2333        count = current_state->count;  /* Number already matched */        count = current_state->count;  /* Number already matched */
2334        if (clen > 0)        if (clen > 0)
2335          {          {
2336          unsigned int otherd = NOTACHAR;          unsigned int otherd = NOTACHAR;
2337          if ((ims & PCRE_CASELESS) != 0)          if (caseless)
2338            {            {
2339  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2340            if (utf8 && d >= 128)            if (utf8 && d >= 128)
2341              {              {
2342  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2343              otherd = _pcre_ucp_othercase(d);              otherd = UCD_OTHERCASE(d);
2344  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2345              }              }
2346            else            else
# Line 1605  for (;;) Line 2358  for (;;)
2358        break;        break;
2359    
2360        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
2361          case OP_UPTOI:
2362          case OP_MINUPTOI:
2363          case OP_POSUPTOI:
2364          case OP_NOTUPTOI:
2365          case OP_NOTMINUPTOI:
2366          case OP_NOTPOSUPTOI:
2367          caseless = TRUE;
2368          codevalue -= OP_STARI - OP_STAR;
2369          /* Fall through */
2370        case OP_UPTO:        case OP_UPTO:
2371        case OP_MINUPTO:        case OP_MINUPTO:
2372        case OP_POSUPTO:        case OP_POSUPTO:
# Line 1616  for (;;) Line 2378  for (;;)
2378        if (clen > 0)        if (clen > 0)
2379          {          {
2380          unsigned int otherd = NOTACHAR;          unsigned int otherd = NOTACHAR;
2381          if ((ims & PCRE_CASELESS) != 0)          if (caseless)
2382            {            {
2383  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2384            if (utf8 && d >= 128)            if (utf8 && d >= 128)
2385              {              {
2386  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2387              otherd = _pcre_ucp_othercase(d);              otherd = UCD_OTHERCASE(d);
2388  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2389              }              }
2390            else            else
# Line 1683  for (;;) Line 2445  for (;;)
2445          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
2446          quantifier, this is where it will be. */          quantifier, this is where it will be. */
2447    
2448          next_state_offset = ecode - start_code;          next_state_offset = (int)(ecode - start_code);
2449    
2450          switch (*ecode)          switch (*ecode)
2451            {            {
# Line 1730  for (;;) Line 2492  for (;;)
2492    
2493  /* ========================================================================== */  /* ========================================================================== */
2494        /* These are the opcodes for fancy brackets of various kinds. We have        /* These are the opcodes for fancy brackets of various kinds. We have
2495        to use recursion in order to handle them. */        to use recursion in order to handle them. The "always failing" assertion
2496          (?!) is optimised to OP_FAIL when compiling, so we have to support that,
2497          though the other "backtracking verbs" are not supported. */
2498    
2499          case OP_FAIL:
2500          forced_fail++;    /* Count FAILs for multiple states */
2501          break;
2502    
2503        case OP_ASSERT:        case OP_ASSERT:
2504        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
# Line 1748  for (;;) Line 2516  for (;;)
2516            md,                                   /* static match data */            md,                                   /* static match data */
2517            code,                                 /* this subexpression's code */            code,                                 /* this subexpression's code */
2518            ptr,                                  /* where we currently are */            ptr,                                  /* where we currently are */
2519            ptr - start_subject,                  /* start offset */            (int)(ptr - start_subject),           /* start offset */
2520            local_offsets,                        /* offset vector */            local_offsets,                        /* offset vector */
2521            sizeof(local_offsets)/sizeof(int),    /* size of same */            sizeof(local_offsets)/sizeof(int),    /* size of same */
2522            local_workspace,                      /* workspace vector */            local_workspace,                      /* workspace vector */
2523            sizeof(local_workspace)/sizeof(int),  /* size of same */            sizeof(local_workspace)/sizeof(int),  /* size of same */
2524            ims,                                  /* the current ims flags */            rlevel);                              /* function recursion level */
           rlevel,                               /* function recursion level */  
           recursing);                           /* pass on regex recursion */  
2525    
2526            if (rc == PCRE_ERROR_DFA_UITEM) return rc;
2527          if ((rc >= 0) == (codevalue == OP_ASSERT || codevalue == OP_ASSERTBACK))          if ((rc >= 0) == (codevalue == OP_ASSERT || codevalue == OP_ASSERTBACK))
2528              { ADD_ACTIVE(endasscode + LINK_SIZE + 1 - start_code, 0); }              { ADD_ACTIVE((int)(endasscode + LINK_SIZE + 1 - start_code), 0); }
2529          }          }
2530        break;        break;
2531    
# Line 1768  for (;;) Line 2535  for (;;)
2535          {          {
2536          int local_offsets[1000];          int local_offsets[1000];
2537          int local_workspace[1000];          int local_workspace[1000];
2538          int condcode = code[LINK_SIZE+1];          int codelink = GET(code, 1);
2539            int condcode;
2540    
2541            /* Because of the way auto-callout works during compile, a callout item
2542            is inserted between OP_COND and an assertion condition. This does not
2543            happen for the other conditions. */
2544    
2545            if (code[LINK_SIZE+1] == OP_CALLOUT)
2546              {
2547              rrc = 0;
2548              if (pcre_callout != NULL)
2549                {
2550                pcre_callout_block cb;
2551                cb.version          = 1;   /* Version 1 of the callout block */
2552                cb.callout_number   = code[LINK_SIZE+2];
2553                cb.offset_vector    = offsets;
2554                cb.subject          = (PCRE_SPTR)start_subject;
2555                cb.subject_length   = (int)(end_subject - start_subject);
2556                cb.start_match      = (int)(current_subject - start_subject);
2557                cb.current_position = (int)(ptr - start_subject);
2558                cb.pattern_position = GET(code, LINK_SIZE + 3);
2559                cb.next_item_length = GET(code, 3 + 2*LINK_SIZE);
2560                cb.capture_top      = 1;
2561                cb.capture_last     = -1;
2562                cb.callout_data     = md->callout_data;
2563                cb.mark             = NULL;   /* No (*MARK) support */
2564                if ((rrc = (*pcre_callout)(&cb)) < 0) return rrc;   /* Abandon */
2565                }
2566              if (rrc > 0) break;                      /* Fail this thread */
2567              code += _pcre_OP_lengths[OP_CALLOUT];    /* Skip callout data */
2568              }
2569    
2570            condcode = code[LINK_SIZE+1];
2571    
2572          /* Back reference conditions are not supported */          /* Back reference conditions are not supported */
2573    
2574          if (condcode == OP_CREF) return PCRE_ERROR_DFA_UCOND;          if (condcode == OP_CREF || condcode == OP_NCREF)
2575              return PCRE_ERROR_DFA_UCOND;
2576    
2577          /* The DEFINE condition is always false */          /* The DEFINE condition is always false */
2578    
2579          if (condcode == OP_DEF)          if (condcode == OP_DEF)
2580            {            { ADD_ACTIVE(state_offset + codelink + LINK_SIZE + 1, 0); }
           ADD_ACTIVE(state_offset + GET(code, 1) + LINK_SIZE + 1, 0);  
           }  
2581    
2582          /* 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,
2583          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
2584          recursed groups. */          recursed groups. */
2585    
2586          else if (condcode == OP_RREF)          else if (condcode == OP_RREF || condcode == OP_NRREF)
2587            {            {
2588            int value = GET2(code, LINK_SIZE+2);            int value = GET2(code, LINK_SIZE+2);
2589            if (value != RREF_ANY) return PCRE_ERROR_DFA_UCOND;            if (value != RREF_ANY) return PCRE_ERROR_DFA_UCOND;
2590            if (recursing > 0) { ADD_ACTIVE(state_offset + LINK_SIZE + 4, 0); }            if (md->recursive != NULL)
2591              else { ADD_ACTIVE(state_offset + GET(code, 1) + LINK_SIZE + 1, 0); }              { ADD_ACTIVE(state_offset + LINK_SIZE + 4, 0); }
2592              else { ADD_ACTIVE(state_offset + codelink + LINK_SIZE + 1, 0); }
2593            }            }
2594    
2595          /* Otherwise, the condition is an assertion */          /* Otherwise, the condition is an assertion */
# Line 1807  for (;;) Line 2606  for (;;)
2606              md,                                   /* fixed match data */              md,                                   /* fixed match data */
2607              asscode,                              /* this subexpression's code */              asscode,                              /* this subexpression's code */
2608              ptr,                                  /* where we currently are */              ptr,                                  /* where we currently are */
2609              ptr - start_subject,                  /* start offset */              (int)(ptr - start_subject),           /* start offset */
2610              local_offsets,                        /* offset vector */              local_offsets,                        /* offset vector */
2611              sizeof(local_offsets)/sizeof(int),    /* size of same */              sizeof(local_offsets)/sizeof(int),    /* size of same */
2612              local_workspace,                      /* workspace vector */              local_workspace,                      /* workspace vector */
2613              sizeof(local_workspace)/sizeof(int),  /* size of same */              sizeof(local_workspace)/sizeof(int),  /* size of same */
2614              ims,                                  /* the current ims flags */              rlevel);                              /* function recursion level */
             rlevel,                               /* function recursion level */  
             recursing);                           /* pass on regex recursion */  
2615    
2616              if (rc == PCRE_ERROR_DFA_UITEM) return rc;
2617            if ((rc >= 0) ==            if ((rc >= 0) ==
2618                  (condcode == OP_ASSERT || condcode == OP_ASSERTBACK))                  (condcode == OP_ASSERT || condcode == OP_ASSERTBACK))
2619              { ADD_ACTIVE(endasscode + LINK_SIZE + 1 - start_code, 0); }              { ADD_ACTIVE((int)(endasscode + LINK_SIZE + 1 - start_code), 0); }
2620            else            else
2621              { ADD_ACTIVE(state_offset + GET(code, 1) + LINK_SIZE + 1, 0); }              { ADD_ACTIVE(state_offset + codelink + LINK_SIZE + 1, 0); }
2622            }            }
2623          }          }
2624        break;        break;
# Line 1828  for (;;) Line 2626  for (;;)
2626        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
2627        case OP_RECURSE:        case OP_RECURSE:
2628          {          {
2629            dfa_recursion_info *ri;
2630          int local_offsets[1000];          int local_offsets[1000];
2631          int local_workspace[1000];          int local_workspace[1000];
2632            const uschar *callpat = start_code + GET(code, 1);
2633            int recno = (callpat == md->start_code)? 0 :
2634              GET2(callpat, 1 + LINK_SIZE);
2635          int rc;          int rc;
2636    
2637          DPRINTF(("%.*sStarting regex recursion %d\n", rlevel*2-2, SP,          DPRINTF(("%.*sStarting regex recursion\n", rlevel*2-2, SP));
2638            recursing + 1));  
2639            /* Check for repeating a recursion without advancing the subject
2640            pointer. This should catch convoluted mutual recursions. (Some simple
2641            cases are caught at compile time.) */
2642    
2643            for (ri = md->recursive; ri != NULL; ri = ri->prevrec)
2644              if (recno == ri->group_num && ptr == ri->subject_position)
2645                return PCRE_ERROR_RECURSELOOP;
2646    
2647            /* Remember this recursion and where we started it so as to
2648            catch infinite loops. */
2649    
2650            new_recursive.group_num = recno;
2651            new_recursive.subject_position = ptr;
2652            new_recursive.prevrec = md->recursive;
2653            md->recursive = &new_recursive;
2654    
2655          rc = internal_dfa_exec(          rc = internal_dfa_exec(
2656            md,                                   /* fixed match data */            md,                                   /* fixed match data */
2657            start_code + GET(code, 1),            /* this subexpression's code */            callpat,                              /* this subexpression's code */
2658            ptr,                                  /* where we currently are */            ptr,                                  /* where we currently are */
2659            ptr - start_subject,                  /* start offset */            (int)(ptr - start_subject),           /* start offset */
2660            local_offsets,                        /* offset vector */            local_offsets,                        /* offset vector */
2661            sizeof(local_offsets)/sizeof(int),    /* size of same */            sizeof(local_offsets)/sizeof(int),    /* size of same */
2662            local_workspace,                      /* workspace vector */            local_workspace,                      /* workspace vector */
2663            sizeof(local_workspace)/sizeof(int),  /* size of same */            sizeof(local_workspace)/sizeof(int),  /* size of same */
2664            ims,                                  /* the current ims flags */            rlevel);                              /* function recursion level */
           rlevel,                               /* function recursion level */  
           recursing + 1);                       /* regex recurse level */  
2665    
2666          DPRINTF(("%.*sReturn from regex recursion %d: rc=%d\n", rlevel*2-2, SP,          md->recursive = new_recursive.prevrec;  /* Done this recursion */
2667            recursing + 1, rc));  
2668            DPRINTF(("%.*sReturn from regex recursion: rc=%d\n", rlevel*2-2, SP,
2669              rc));
2670    
2671          /* Ran out of internal offsets */          /* Ran out of internal offsets */
2672    
# Line 1882  for (;;) Line 2699  for (;;)
2699        break;        break;
2700    
2701        /*-----------------------------------------------------------------*/        /*-----------------------------------------------------------------*/
2702          case OP_BRAPOS:
2703          case OP_SBRAPOS:
2704          case OP_CBRAPOS:
2705          case OP_SCBRAPOS:
2706          case OP_BRAPOSZERO:
2707            {
2708            int charcount, matched_count;
2709            const uschar *local_ptr = ptr;
2710            BOOL allow_zero;
2711    
2712            if (codevalue == OP_BRAPOSZERO)
2713              {
2714              allow_zero = TRUE;
2715              codevalue = *(++code);  /* Codevalue will be one of above BRAs */
2716              }
2717            else allow_zero = FALSE;
2718    
2719            /* Loop to match the subpattern as many times as possible as if it were
2720            a complete pattern. */
2721    
2722            for (matched_count = 0;; matched_count++)
2723              {
2724              int local_offsets[2];
2725              int local_workspace[1000];
2726    
2727              int rc = internal_dfa_exec(
2728                md,                                   /* fixed match data */
2729                code,                                 /* this subexpression's code */
2730                local_ptr,                            /* where we currently are */
2731                (int)(ptr - start_subject),           /* start offset */
2732                local_offsets,                        /* offset vector */
2733                sizeof(local_offsets)/sizeof(int),    /* size of same */
2734                local_workspace,                      /* workspace vector */
2735                sizeof(local_workspace)/sizeof(int),  /* size of same */
2736                rlevel);                              /* function recursion level */
2737    
2738              /* Failed to match */
2739    
2740              if (rc < 0)
2741                {
2742                if (rc != PCRE_ERROR_NOMATCH) return rc;
2743                break;
2744                }
2745    
2746              /* Matched: break the loop if zero characters matched. */
2747    
2748              charcount = local_offsets[1] - local_offsets[0];
2749              if (charcount == 0) break;
2750              local_ptr += charcount;    /* Advance temporary position ptr */
2751              }
2752    
2753            /* At this point we have matched the subpattern matched_count
2754            times, and local_ptr is pointing to the character after the end of the
2755            last match. */
2756    
2757            if (matched_count > 0 || allow_zero)
2758              {
2759              const uschar *end_subpattern = code;
2760              int next_state_offset;
2761    
2762              do { end_subpattern += GET(end_subpattern, 1); }
2763                while (*end_subpattern == OP_ALT);
2764              next_state_offset =
2765                (int)(end_subpattern - start_code + LINK_SIZE + 1);
2766    
2767              /* Optimization: if there are no more active states, and there
2768              are no new states yet set up, then skip over the subject string
2769              right here, to save looping. Otherwise, set up the new state to swing
2770              into action when the end of the matched substring is reached. */
2771    
2772              if (i + 1 >= active_count && new_count == 0)
2773                {
2774                ptr = local_ptr;
2775                clen = 0;
2776                ADD_NEW(next_state_offset, 0);
2777                }
2778              else
2779                {
2780                const uschar *p = ptr;
2781                const uschar *pp = local_ptr;
2782                charcount = pp - p;
2783                while (p < pp) if ((*p++ & 0xc0) == 0x80) charcount--;
2784                ADD_NEW_DATA(-next_state_offset, 0, (charcount - 1));
2785                }
2786              }
2787            }
2788          break;
2789    
2790          /*-----------------------------------------------------------------*/
2791        case OP_ONCE:        case OP_ONCE:
2792          {          {
2793          int local_offsets[2];          int local_offsets[2];
# Line 1891  for (;;) Line 2797  for (;;)
2797            md,                                   /* fixed match data */            md,                                   /* fixed match data */
2798            code,                                 /* this subexpression's code */            code,                                 /* this subexpression's code */
2799            ptr,                                  /* where we currently are */            ptr,                                  /* where we currently are */
2800            ptr - start_subject,                  /* start offset */            (int)(ptr - start_subject),           /* start offset */
2801            local_offsets,                        /* offset vector */            local_offsets,                        /* offset vector */
2802            sizeof(local_offsets)/sizeof(int),    /* size of same */            sizeof(local_offsets)/sizeof(int),    /* size of same */
2803            local_workspace,                      /* workspace vector */            local_workspace,                      /* workspace vector */
2804            sizeof(local_workspace)/sizeof(int),  /* size of same */            sizeof(local_workspace)/sizeof(int),  /* size of same */
2805            ims,                                  /* the current ims flags */            rlevel);                              /* function recursion level */
           rlevel,                               /* function recursion level */  
           recursing);                           /* pass on regex recursion */  
2806    
2807          if (rc >= 0)          if (rc >= 0)
2808            {            {
# Line 1908  for (;;) Line 2812  for (;;)
2812    
2813            do { end_subpattern += GET(end_subpattern, 1); }            do { end_subpattern += GET(end_subpattern, 1); }
2814              while (*end_subpattern == OP_ALT);              while (*end_subpattern == OP_ALT);
2815            next_state_offset = end_subpattern - start_code + LINK_SIZE + 1;            next_state_offset =
2816                (int)(end_subpattern - start_code + LINK_SIZE + 1);
2817    
2818            /* If the end of this subpattern is KETRMAX or KETRMIN, we must            /* If the end of this subpattern is KETRMAX or KETRMIN, we must
2819            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 1916  for (;;) Line 2821  for (;;)
2821    
2822            repeat_state_offset = (*end_subpattern == OP_KETRMAX ||            repeat_state_offset = (*end_subpattern == OP_KETRMAX ||
2823                                   *end_subpattern == OP_KETRMIN)?                                   *end_subpattern == OP_KETRMIN)?
2824              end_subpattern - start_code - GET(end_subpattern, 1) : -1;              (int)(end_subpattern - start_code - GET(end_subpattern, 1)) : -1;
2825    
2826            /* 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
2827            current character pointer. This is important so that the duplicate            current character pointer. This is important so that the duplicate
# Line 1931  for (;;) Line 2836  for (;;)
2836            /* Optimization: if there are no more active states, and there            /* Optimization: if there are no more active states, and there
2837            are no new states yet set up, then skip over the subject string            are no new states yet set up, then skip over the subject string
2838            right here, to save looping. Otherwise, set up the new state to swing            right here, to save looping. Otherwise, set up the new state to swing
2839            into action when the end of the substring is reached. */            into action when the end of the matched substring is reached. */
2840    
2841            else if (i + 1 >= active_count && new_count == 0)            else if (i + 1 >= active_count && new_count == 0)
2842              {              {
# Line 1961  for (;;) Line 2866  for (;;)
2866              if (repeat_state_offset >= 0)              if (repeat_state_offset >= 0)
2867                { ADD_NEW_DATA(-repeat_state_offset, 0, (charcount - 1)); }                { ADD_NEW_DATA(-repeat_state_offset, 0, (charcount - 1)); }
2868              }              }
   
2869            }            }
2870          else if (rc != PCRE_ERROR_NOMATCH) return rc;          else if (rc != PCRE_ERROR_NOMATCH) return rc;
2871          }          }
# Line 1972  for (;;) Line 2876  for (;;)
2876        /* Handle callouts */        /* Handle callouts */
2877    
2878        case OP_CALLOUT:        case OP_CALLOUT:
2879          rrc = 0;
2880        if (pcre_callout != NULL)        if (pcre_callout != NULL)
2881          {          {
         int rrc;  
2882          pcre_callout_block cb;          pcre_callout_block cb;
2883          cb.version          = 1;   /* Version 1 of the callout block */          cb.version          = 1;   /* Version 1 of the callout block */
2884          cb.callout_number   = code[1];          cb.callout_number   = code[1];
2885          cb.offset_vector    = offsets;          cb.offset_vector    = offsets;
2886          cb.subject          = (PCRE_SPTR)start_subject;          cb.subject          = (PCRE_SPTR)start_subject;
2887          cb.subject_length   = end_subject - start_subject;          cb.subject_length   = (int)(end_subject - start_subject);
2888          cb.start_match      = current_subject - start_subject;          cb.start_match      = (int)(current_subject - start_subject);
2889          cb.current_position = ptr - start_subject;          cb.current_position = (int)(ptr - start_subject);
2890          cb.pattern_position = GET(code, 2);          cb.pattern_position = GET(code, 2);
2891          cb.next_item_length = GET(code, 2 + LINK_SIZE);          cb.next_item_length = GET(code, 2 + LINK_SIZE);
2892          cb.capture_top      = 1;          cb.capture_top      = 1;
2893          cb.capture_last     = -1;          cb.capture_last     = -1;
2894          cb.callout_data     = md->callout_data;          cb.callout_data     = md->callout_data;
2895            cb.mark             = NULL;   /* No (*MARK) support */
2896          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); }  
2897          }          }
2898          if (rrc == 0)
2899            { ADD_ACTIVE(state_offset + _pcre_OP_lengths[OP_CALLOUT], 0); }
2900        break;        break;
2901    
2902    
# Line 2006  for (;;) Line 2912  for (;;)
2912    /* We have finished the processing at the current subject character. If no    /* We have finished the processing at the current subject character. If no
2913    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
2914    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
2915    matching has been requested, check for appropriate conditions. */    matching has been requested, check for appropriate conditions.
2916    
2917      The "forced_ fail" variable counts the number of (*F) encountered for the
2918      character. If it is equal to the original active_count (saved in
2919      workspace[1]) it means that (*F) was found on every active state. In this
2920      case we don't want to give a partial match.
2921    
2922      The "could_continue" variable is true if a state could have continued but
2923      for the fact that the end of the subject was reached. */
2924    
2925    if (new_count <= 0)    if (new_count <= 0)
2926      {      {
2927      if (match_count < 0 &&                     /* No matches found */      if (rlevel == 1 &&                               /* Top level, and */
2928          rlevel == 1 &&                         /* Top level match function */          could_continue &&                            /* Some could go on */
2929          (md->moptions & PCRE_PARTIAL) != 0 &&  /* Want partial matching */          forced_fail != workspace[1] &&               /* Not all forced fail & */
2930            (                                            /* either... */
2931            (md->moptions & PCRE_PARTIAL_HARD) != 0      /* Hard partial */
2932            ||                                           /* or... */
2933            ((md->moptions & PCRE_PARTIAL_SOFT) != 0 &&  /* Soft partial and */
2934             match_count < 0)                            /* no matches */
2935            ) &&                                         /* And... */
2936          ptr >= end_subject &&                  /* Reached end of subject */          ptr >= end_subject &&                  /* Reached end of subject */
2937          ptr > current_subject)                 /* Matched non-empty string */          ptr > md->start_used_ptr)              /* Inspected non-empty string */
2938        {        {
2939        if (offsetcount >= 2)        if (offsetcount >= 2)
2940          {          {
2941          offsets[0] = current_subject - start_subject;          offsets[0] = (int)(md->start_used_ptr - start_subject);
2942          offsets[1] = end_subject - start_subject;          offsets[1] = (int)(end_subject - start_subject);
2943          }          }
2944        match_count = PCRE_ERROR_PARTIAL;        match_count = PCRE_ERROR_PARTIAL;
2945        }        }
# Line 2073  Returns:          > 0 => number of match Line 2993  Returns:          > 0 => number of match
2993                   < -1 => some kind of unexpected problem                   < -1 => some kind of unexpected problem
2994  */  */
2995    
2996  PCRE_DATA_SCOPE int  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
2997  pcre_dfa_exec(const pcre *argument_re, const pcre_extra *extra_data,  pcre_dfa_exec(const pcre *argument_re, const pcre_extra *extra_data,
2998    const char *subject, int length, int start_offset, int options, int *offsets,    const char *subject, int length, int start_offset, int options, int *offsets,
2999    int offsetcount, int *workspace, int wscount)    int offsetcount, int *workspace, int wscount)
# Line 2104  if (re == NULL || subject == NULL || wor Line 3024  if (re == NULL || subject == NULL || wor
3024     (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;     (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;
3025  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;
3026  if (wscount < 20) return PCRE_ERROR_DFA_WSSIZE;  if (wscount < 20) return PCRE_ERROR_DFA_WSSIZE;
3027    if (start_offset < 0 || start_offset > length) return PCRE_ERROR_BADOFFSET;
3028    
3029  /* 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
3030  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 2160  md->start_code = (const uschar *)argumen Line 3081  md->start_code = (const uschar *)argumen
3081      re->name_table_offset + re->name_count * re->name_entry_size;      re->name_table_offset + re->name_count * re->name_entry_size;
3082  md->start_subject = (const unsigned char *)subject;  md->start_subject = (const unsigned char *)subject;
3083  md->end_subject = end_subject;  md->end_subject = end_subject;
3084    md->start_offset = start_offset;
3085  md->moptions = options;  md->moptions = options;
3086  md->poptions = re->options;  md->poptions = re->options;
3087    
3088    /* If the BSR option is not set at match time, copy what was set
3089    at compile time. */
3090    
3091    if ((md->moptions & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) == 0)
3092      {
3093      if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0)
3094        md->moptions |= re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE);
3095    #ifdef BSR_ANYCRLF
3096      else md->moptions |= PCRE_BSR_ANYCRLF;
3097    #endif
3098      }
3099    
3100  /* Handle different types of newline. The three bits give eight cases. If  /* Handle different types of newline. The three bits give eight cases. If
3101  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. */
3102    
3103  switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : options) &  switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : (pcre_uint32)options) &
3104           PCRE_NEWLINE_BITS)           PCRE_NEWLINE_BITS)
3105    {    {
3106    case 0: newline = NEWLINE; break;   /* Compile-time default */    case 0: newline = NEWLINE; break;   /* Compile-time default */
3107    case PCRE_NEWLINE_CR: newline = '\r'; break;    case PCRE_NEWLINE_CR: newline = CHAR_CR; break;
3108    case PCRE_NEWLINE_LF: newline = '\n'; break;    case PCRE_NEWLINE_LF: newline = CHAR_NL; break;
3109    case PCRE_NEWLINE_CR+    case PCRE_NEWLINE_CR+
3110         PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break;         PCRE_NEWLINE_LF: newline = (CHAR_CR << 8) | CHAR_NL; break;
3111    case PCRE_NEWLINE_ANY: newline = -1; break;    case PCRE_NEWLINE_ANY: newline = -1; break;
3112      case PCRE_NEWLINE_ANYCRLF: newline = -2; break;
3113    default: return PCRE_ERROR_BADNEWLINE;    default: return PCRE_ERROR_BADNEWLINE;
3114    }    }
3115    
3116  if (newline < 0)  if (newline == -2)
3117      {
3118      md->nltype = NLTYPE_ANYCRLF;
3119      }
3120    else if (newline < 0)
3121    {    {
3122    md->nltype = NLTYPE_ANY;    md->nltype = NLTYPE_ANY;
3123    }    }
# Line 2204  back the character offset. */ Line 3143  back the character offset. */
3143  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
3144  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)
3145    {    {
3146    if (_pcre_valid_utf8((uschar *)subject, length) >= 0)    int erroroffset;
3147      return PCRE_ERROR_BADUTF8;    int errorcode = _pcre_valid_utf8((uschar *)subject, length, &erroroffset);
3148    if (start_offset > 0 && start_offset < length)    if (errorcode != 0)
3149      {      {
3150      int tb = ((uschar *)subject)[start_offset];      if (offsetcount >= 2)
     if (tb > 127)  
3151        {        {
3152        tb &= 0xc0;        offsets[0] = erroroffset;
3153        if (tb != 0 && tb != 0xc0) return PCRE_ERROR_BADUTF8_OFFSET;        offsets[1] = errorcode;
3154        }        }
3155        return (errorcode <= PCRE_UTF8_ERR5 && (options & PCRE_PARTIAL_HARD) != 0)?
3156          PCRE_ERROR_SHORTUTF8 : PCRE_ERROR_BADUTF8;
3157      }      }
3158      if (start_offset > 0 && start_offset < length &&
3159            (((USPTR)subject)[start_offset] & 0xc0) == 0x80)
3160        return PCRE_ERROR_BADUTF8_OFFSET;
3161    }    }
3162  #endif  #endif
3163    
# Line 2228  if (md->tables == NULL) md->tables = _pc Line 3171  if (md->tables == NULL) md->tables = _pc
3171  used in a loop when finding where to start. */  used in a loop when finding where to start. */
3172    
3173  lcc = md->tables + lcc_offset;  lcc = md->tables + lcc_offset;
3174  startline = (re->options & PCRE_STARTLINE) != 0;  startline = (re->flags & PCRE_STARTLINE) != 0;
3175  firstline = (re->options & PCRE_FIRSTLINE) != 0;  firstline = (re->options & PCRE_FIRSTLINE) != 0;
3176    
3177  /* 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 2239  studied, there may be a bitmap of possib Line 3182  studied, there may be a bitmap of possib
3182    
3183  if (!anchored)  if (!anchored)
3184    {    {
3185    if ((re->options & PCRE_FIRSTSET) != 0)    if ((re->flags & PCRE_FIRSTSET) != 0)
3186      {      {
3187      first_byte = re->first_byte & 255;      first_byte = re->first_byte & 255;
3188      if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)      if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)
# Line 2247  if (!anchored) Line 3190  if (!anchored)
3190      }      }
3191    else    else
3192      {      {
3193      if (startline && study != NULL &&      if (!startline && study != NULL &&
3194           (study->options & PCRE_STUDY_MAPPED) != 0)           (study->flags & PCRE_STUDY_MAPPED) != 0)
3195        start_bits = study->start_bits;        start_bits = study->start_bits;
3196      }      }
3197    }    }
# Line 2256  if (!anchored) Line 3199  if (!anchored)
3199  /* For anchored or unanchored matches, there may be a "last known required  /* For anchored or unanchored matches, there may be a "last known required
3200  character" set. */  character" set. */
3201    
3202  if ((re->options & PCRE_REQCHSET) != 0)  if ((re->flags & PCRE_REQCHSET) != 0)
3203    {    {
3204    req_byte = re->req_byte & 255;    req_byte = re->req_byte & 255;
3205    req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;    req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;
# Line 2264  if ((re->options & PCRE_REQCHSET) != 0) Line 3207  if ((re->options & PCRE_REQCHSET) != 0)
3207    }    }
3208    
3209  /* 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
3210  failed match. Unless restarting, optimize by moving to the first match  failed match. If not restarting, perform certain optimizations at the start of
3211  character if possible, when not anchored. Then unless wanting a partial match,  a match. */
 check for a required later character. */  
3212    
3213  for (;;)  for (;;)
3214    {    {
# Line 2276  for (;;) Line 3218  for (;;)
3218      {      {
3219      const uschar *save_end_subject = end_subject;      const uschar *save_end_subject = end_subject;
3220    
3221      /* 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
3222      start of the match is constrained to the first line of a multiline string.      line of a multiline string. Implement this by temporarily adjusting
3223      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
3224      scanning at a newline. If the match fails at the newline, later code breaks      the newline, later code breaks this loop. */
     this loop. */  
3225    
3226      if (firstline)      if (firstline)
3227        {        {
3228        const uschar *t = current_subject;        USPTR t = current_subject;
3229    #ifdef SUPPORT_UTF8
3230          if (utf8)
3231            {
3232            while (t < md->end_subject && !IS_NEWLINE(t))
3233              {
3234              t++;
3235              while (t < end_subject && (*t & 0xc0) == 0x80) t++;
3236              }
3237            }
3238          else
3239    #endif
3240        while (t < md->end_subject && !IS_NEWLINE(t)) t++;        while (t < md->end_subject && !IS_NEWLINE(t)) t++;
3241        end_subject = t;        end_subject = t;
3242        }        }
3243    
3244      if (first_byte >= 0)      /* There are some optimizations that avoid running the match if a known
3245        starting point is not found. However, there is an option that disables
3246        these, for testing and for ensuring that all callouts do actually occur.
3247        The option can be set in the regex by (*NO_START_OPT) or passed in
3248        match-time options. */
3249    
3250        if (((options | re->options) & PCRE_NO_START_OPTIMIZE) == 0)
3251        {        {
3252        if (first_byte_caseless)        /* Advance to a known first byte. */
3253          while (current_subject < end_subject &&  
3254                 lcc[*current_subject] != first_byte)        if (first_byte >= 0)
3255            current_subject++;          {
3256        else          if (first_byte_caseless)
3257          while (current_subject < end_subject && *current_subject != first_byte)            while (current_subject < end_subject &&
3258            current_subject++;                   lcc[*current_subject] != first_byte)
3259        }              current_subject++;
3260            else
3261              while (current_subject < end_subject &&
3262                     *current_subject != first_byte)
3263                current_subject++;
3264            }
3265    
3266      /* Or to just after a linebreak for a multiline match if possible */        /* Or to just after a linebreak for a multiline match if possible */
3267    
3268      else if (startline)        else if (startline)
       {  
       if (current_subject > md->start_subject + start_offset)  
3269          {          {
3270          while (current_subject <= end_subject && !WAS_NEWLINE(current_subject))          if (current_subject > md->start_subject + start_offset)
3271            current_subject++;            {
3272    #ifdef SUPPORT_UTF8
3273              if (utf8)
3274                {
3275                while (current_subject < end_subject &&
3276                       !WAS_NEWLINE(current_subject))
3277                  {
3278                  current_subject++;
3279                  while(current_subject < end_subject &&
3280                        (*current_subject & 0xc0) == 0x80)
3281                    current_subject++;
3282                  }
3283                }
3284              else
3285    #endif
3286              while (current_subject < end_subject && !WAS_NEWLINE(current_subject))
3287                current_subject++;
3288    
3289          /* If we have just passed a CR and the newline option is ANY, and we            /* If we have just passed a CR and the newline option is ANY or
3290          are now at a LF, advance the match position by one more character. */            ANYCRLF, and we are now at a LF, advance the match position by one
3291              more character. */
3292          if (current_subject[-1] == '\r' &&  
3293               md->nltype == NLTYPE_ANY &&            if (current_subject[-1] == CHAR_CR &&
3294               current_subject < end_subject &&                 (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&
3295               *current_subject == '\n')                 current_subject < end_subject &&
3296            current_subject++;                 *current_subject == CHAR_NL)
3297                current_subject++;
3298              }
3299          }          }
       }  
3300    
3301      /* Or to a non-unique first char after study */        /* Or to a non-unique first char after study */
3302    
3303      else if (start_bits != NULL)        else if (start_bits != NULL)
       {  
       while (current_subject < end_subject)  
3304          {          {
3305          register unsigned int c = *current_subject;          while (current_subject < end_subject)
3306          if ((start_bits[c/8] & (1 << (c&7))) == 0) current_subject++;            {
3307              register unsigned int c = *current_subject;
3308              if ((start_bits[c/8] & (1 << (c&7))) == 0)
3309                {
3310                current_subject++;
3311    #ifdef SUPPORT_UTF8
3312                if (utf8)
3313                  while(current_subject < end_subject &&
3314                        (*current_subject & 0xc0) == 0x80) current_subject++;
3315    #endif
3316                }
3317            else break;            else break;
3318              }
3319          }          }
3320        }        }
3321    
3322      /* Restore fudged end_subject */      /* Restore fudged end_subject */
3323    
3324      end_subject = save_end_subject;      end_subject = save_end_subject;
     }  
3325    
3326    /* 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
3327    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
3328    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);  
   
     /* We don't need to repeat the search if we haven't yet reached the  
     place we found it at last time. */  
3329    
3330      if (p > req_byte_ptr)      if ((options & PCRE_NO_START_OPTIMIZE) == 0 &&
3331            (options & (PCRE_PARTIAL_HARD|PCRE_PARTIAL_SOFT)) == 0)
3332        {        {
3333        if (req_byte_caseless)        /* If the pattern was studied, a minimum subject length may be set. This
3334          {        is a lower bound; no actual string of that length may actually match the
3335          while (p < end_subject)        pattern. Although the value is, strictly, in characters, we treat it as
3336            {        bytes to avoid spending too much time in this optimization. */
3337            register int pp = *p++;  
3338            if (pp == req_byte || pp == req_byte2) { p--; break; }        if (study != NULL && (study->flags & PCRE_STUDY_MINLEN) != 0 &&
3339            }            (pcre_uint32)(end_subject - current_subject) < study->minlength)
3340          }          return PCRE_ERROR_NOMATCH;
3341        else  
3342          /* If req_byte is set, we know that that character must appear in the
3343          subject for the match to succeed. If the first character is set, req_byte
3344          must be later in the subject; otherwise the test starts at the match
3345          point. This optimization can save a huge amount of work in patterns with
3346          nested unlimited repeats that aren't going to match. Writing separate
3347          code for cased/caseless versions makes it go faster, as does using an
3348          autoincrement and backing off on a match.
3349    
3350          HOWEVER: when the subject string is very, very long, searching to its end
3351          can take a long time, and give bad performance on quite ordinary
3352          patterns. This showed up when somebody was matching /^C/ on a 32-megabyte
3353          string... so we don't do this when the string is sufficiently long. */
3354    
3355          if (req_byte >= 0 && end_subject - current_subject < REQ_BYTE_MAX)
3356          {          {
3357          while (p < end_subject)          register const uschar *p = current_subject + ((first_byte >= 0)? 1 : 0);
3358    
3359            /* We don't need to repeat the search if we haven't yet reached the
3360            place we found it at last time. */
3361    
3362            if (p > req_byte_ptr)
3363            {            {
3364            if (*p++ == req_byte) { p--; break; }            if (req_byte_caseless)
3365            }              {
3366          }              while (p < end_subject)
3367                  {
3368                  register int pp = *p++;
3369                  if (pp == req_byte || pp == req_byte2) { p--; break; }
3370                  }
3371                }
3372              else
3373                {
3374                while (p < end_subject)
3375                  {
3376                  if (*p++ == req_byte) { p--; break; }
3377                  }
3378                }
3379    
3380        /* If we can't find the required character, break the matching loop,            /* If we can't find the required character, break the matching loop,
3381        which will cause a return or PCRE_ERROR_NOMATCH. */            which will cause a return or PCRE_ERROR_NOMATCH. */
3382    
3383        if (p >= end_subject) break;            if (p >= end_subject) break;
3384    
3385        /* If we have found the required character, save the point where we            /* If we have found the required character, save the point where we
3386        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
3387        the start hasn't passed this character yet. */            the start hasn't passed this character yet. */
3388    
3389        req_byte_ptr = p;            req_byte_ptr = p;
3390              }
3391            }
3392        }        }
3393      }      }   /* End of optimizations that are done when not restarting */
3394    
3395    /* OK, now we can do the business */    /* OK, now we can do the business */
3396    
3397      md->start_used_ptr = current_subject;
3398      md->recursive = NULL;
3399    
3400    rc = internal_dfa_exec(    rc = internal_dfa_exec(
3401      md,                                /* fixed match data */      md,                                /* fixed match data */
3402      md->start_code,                    /* this subexpression's code */      md->start_code,                    /* this subexpression's code */
# Line 2404  for (;;) Line 3406  for (;;)
3406      offsetcount,                       /* size of same */      offsetcount,                       /* size of same */
3407      workspace,                         /* workspace vector */      workspace,                         /* workspace vector */
3408      wscount,                           /* size of same */      wscount,                           /* size of same */
3409      re->options & (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL), /* ims flags */      0);                                /* function recurse level */
     0,                                 /* function recurse level */  
     0);                                /* regex recurse level */  
3410    
3411    /* Anything other than "no match" means we are done, always; otherwise, carry    /* Anything other than "no match" means we are done, always; otherwise, carry
3412    on only if not anchored. */    on only if not anchored. */
# Line 2425  for (;;) Line 3425  for (;;)
3425      }      }
3426    if (current_subject > end_subject) break;    if (current_subject > end_subject) break;
3427    
3428    /* If we have just passed a CR and the newline option is CRLF or ANY, and we    /* If we have just passed a CR and we are now at a LF, and the pattern does
3429    are now at a LF, advance the match position by one more character. */    not contain any explicit matches for \r or \n, and the newline option is CRLF
3430      or ANY or ANYCRLF, advance the match position by one more character. */
3431    if (current_subject[-1] == '\r' &&  
3432         (md->nltype == NLTYPE_ANY || md->nllen == 2) &&    if (current_subject[-1] == CHAR_CR &&
3433         current_subject < end_subject &&        current_subject < end_subject &&
3434         *current_subject == '\n')        *current_subject == CHAR_NL &&
3435          (re->flags & PCRE_HASCRORLF) == 0 &&
3436            (md->nltype == NLTYPE_ANY ||
3437             md->nltype == NLTYPE_ANYCRLF ||
3438             md->nllen == 2))
3439      current_subject++;      current_subject++;
3440    
3441    }   /* "Bumpalong" loop */    }   /* "Bumpalong" loop */

Legend:
Removed from v.130  
changed lines
  Added in v.680

  ViewVC Help
Powered by ViewVC 1.1.5