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

Diff of /code/trunk/pcre_exec.c

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

revision 77 by nigel, Sat Feb 24 21:40:45 2007 UTC revision 361 by ph10, Thu Jul 10 16:03:28 2008 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2005 University of Cambridge             Copyright (c) 1997-2008 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 42  POSSIBILITY OF SUCH DAMAGE. Line 42  POSSIBILITY OF SUCH DAMAGE.
42  pattern matching using an NFA algorithm, trying to mimic Perl as closely as  pattern matching using an NFA algorithm, trying to mimic Perl as closely as
43  possible. There are also some static supporting functions. */  possible. There are also some static supporting functions. */
44    
45    #ifdef HAVE_CONFIG_H
46    #include "config.h"
47    #endif
48    
49    #define NLBLOCK md             /* Block containing newline information */
50    #define PSSTART start_subject  /* Field containing processed string start */
51    #define PSEND   end_subject    /* Field containing processed string end */
52    
53  #include "pcre_internal.h"  #include "pcre_internal.h"
54    
55    /* Undefine some potentially clashing cpp symbols */
56    
57  /* Structure for building a chain of data that actually lives on the  #undef min
58  stack, for holding the values of the subject pointer at the start of each  #undef max
 subpattern, so as to detect when an empty string has been matched by a  
 subpattern - to break infinite loops. When NO_RECURSE is set, these blocks  
 are on the heap, not on the stack. */  
   
 typedef struct eptrblock {  
   struct eptrblock *epb_prev;  
   const uschar *epb_saved_eptr;  
 } eptrblock;  
59    
60  /* Flag bits for the match() function */  /* Flag bits for the match() function */
61    
62  #define match_condassert   0x01    /* Called to check a condition assertion */  #define match_condassert     0x01  /* Called to check a condition assertion */
63  #define match_isgroup      0x02    /* Set if start of bracketed group */  #define match_cbegroup       0x02  /* Could-be-empty unlimited repeat group */
64    
65  /* Non-error returns from the match() function. Error returns are externally  /* Non-error returns from the match() function. Error returns are externally
66  defined PCRE_ERROR_xxx codes, which are all negative. */  defined PCRE_ERROR_xxx codes, which are all negative. */
# Line 68  defined PCRE_ERROR_xxx codes, which are Line 68  defined PCRE_ERROR_xxx codes, which are
68  #define MATCH_MATCH        1  #define MATCH_MATCH        1
69  #define MATCH_NOMATCH      0  #define MATCH_NOMATCH      0
70    
71    /* Special internal returns from the match() function. Make them sufficiently
72    negative to avoid the external error codes. */
73    
74    #define MATCH_COMMIT       (-999)
75    #define MATCH_PRUNE        (-998)
76    #define MATCH_SKIP         (-997)
77    #define MATCH_THEN         (-996)
78    
79  /* Maximum number of ints of offset to save on the stack for recursive calls.  /* Maximum number of ints of offset to save on the stack for recursive calls.
80  If the offset vector is bigger, malloc is used. This should be a multiple of 3,  If the offset vector is bigger, malloc is used. This should be a multiple of 3,
81  because the offset vector is always a multiple of 3 long. */  because the offset vector is always a multiple of 3 long. */
# Line 101  Returns:     nothing Line 109  Returns:     nothing
109  static void  static void
110  pchars(const uschar *p, int length, BOOL is_subject, match_data *md)  pchars(const uschar *p, int length, BOOL is_subject, match_data *md)
111  {  {
112  int c;  unsigned int c;
113  if (is_subject && length > md->end_subject - p) length = md->end_subject - p;  if (is_subject && length > md->end_subject - p) length = md->end_subject - p;
114  while (length-- > 0)  while (length-- > 0)
115    if (isprint(c = *(p++))) printf("%c", c); else printf("\\x%02x", c);    if (isprint(c = *(p++))) printf("%c", c); else printf("\\x%02x", c);
# Line 128  Returns:      TRUE if matched Line 136  Returns:      TRUE if matched
136  */  */
137    
138  static BOOL  static BOOL
139  match_ref(int offset, register const uschar *eptr, int length, match_data *md,  match_ref(int offset, register USPTR eptr, int length, match_data *md,
140    unsigned long int ims)    unsigned long int ims)
141  {  {
142  const uschar *p = md->start_subject + md->offset_vector[offset];  USPTR p = md->start_subject + md->offset_vector[offset];
143    
144  #ifdef DEBUG  #ifdef DEBUG
145  if (eptr >= md->end_subject)  if (eptr >= md->end_subject)
# Line 150  printf("\n"); Line 158  printf("\n");
158    
159  if (length > md->end_subject - eptr) return FALSE;  if (length > md->end_subject - eptr) return FALSE;
160    
161  /* Separate the caselesss case for speed */  /* Separate the caseless case for speed. In UTF-8 mode we can only do this
162    properly if Unicode properties are supported. Otherwise, we can check only
163    ASCII characters. */
164    
165  if ((ims & PCRE_CASELESS) != 0)  if ((ims & PCRE_CASELESS) != 0)
166    {    {
167    #ifdef SUPPORT_UTF8
168    #ifdef SUPPORT_UCP
169      if (md->utf8)
170        {
171        USPTR endptr = eptr + length;
172        while (eptr < endptr)
173          {
174          int c, d;
175          GETCHARINC(c, eptr);
176          GETCHARINC(d, p);
177          if (c != d && c != UCD_OTHERCASE(d)) return FALSE;
178          }
179        }
180      else
181    #endif
182    #endif
183    
184      /* The same code works when not in UTF-8 mode and in UTF-8 mode when there
185      is no UCP support. */
186    
187    while (length-- > 0)    while (length-- > 0)
188      if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE;      { if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE; }
189    }    }
190    
191    /* In the caseful case, we can just compare the bytes, whether or not we
192    are in UTF-8 mode. */
193    
194  else  else
195    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }
196    
# Line 169  return TRUE; Line 203  return TRUE;
203  ****************************************************************************  ****************************************************************************
204                     RECURSION IN THE match() FUNCTION                     RECURSION IN THE match() FUNCTION
205    
206  The match() function is highly recursive. Some regular expressions can cause  The match() function is highly recursive, though not every recursive call
207  it to recurse thousands of times. I was writing for Unix, so I just let it  increases the recursive depth. Nevertheless, some regular expressions can cause
208  call itself recursively. This uses the stack for saving everything that has  it to recurse to a great depth. I was writing for Unix, so I just let it call
209  to be saved for a recursive call. On Unix, the stack can be large, and this  itself recursively. This uses the stack for saving everything that has to be
210  works fine.  saved for a recursive call. On Unix, the stack can be large, and this works
211    fine.
212  It turns out that on non-Unix systems there are problems with programs that  
213  use a lot of stack. (This despite the fact that every last chip has oodles  It turns out that on some non-Unix-like systems there are problems with
214  of memory these days, and techniques for extending the stack have been known  programs that use a lot of stack. (This despite the fact that every last chip
215  for decades.) So....  has oodles of memory these days, and techniques for extending the stack have
216    been known for decades.) So....
217    
218  There is a fudge, triggered by defining NO_RECURSE, which avoids recursive  There is a fudge, triggered by defining NO_RECURSE, which avoids recursive
219  calls by keeping local variables that need to be preserved in blocks of memory  calls by keeping local variables that need to be preserved in blocks of memory
220  obtained from malloc instead instead of on the stack. Macros are used to  obtained from malloc() instead instead of on the stack. Macros are used to
221  achieve this so that the actual code doesn't look very different to what it  achieve this so that the actual code doesn't look very different to what it
222  always used to.  always used to.
223    
224    The original heap-recursive code used longjmp(). However, it seems that this
225    can be very slow on some operating systems. Following a suggestion from Stan
226    Switzer, the use of longjmp() has been abolished, at the cost of having to
227    provide a unique number for each call to RMATCH. There is no way of generating
228    a sequence of numbers at compile time in C. I have given them names, to make
229    them stand out more clearly.
230    
231    Crude tests on x86 Linux show a small speedup of around 5-8%. However, on
232    FreeBSD, avoiding longjmp() more than halves the time taken to run the standard
233    tests. Furthermore, not using longjmp() means that local dynamic variables
234    don't have indeterminate values; this has meant that the frame size can be
235    reduced because the result can be "passed back" by straight setting of the
236    variable instead of being passed in the frame.
237  ****************************************************************************  ****************************************************************************
238  ***************************************************************************/  ***************************************************************************/
239    
240    /* Numbers for RMATCH calls. When this list is changed, the code at HEAP_RETURN
241    below must be updated in sync.  */
242    
243  /* These versions of the macros use the stack, as normal */  enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM6,  RM7,  RM8,  RM9,  RM10,
244           RM11,  RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20,
245           RM21,  RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30,
246           RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,
247           RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,
248           RM51,  RM52, RM53, RM54 };
249    
250    /* These versions of the macros use the stack, as normal. There are debugging
251    versions and production versions. Note that the "rw" argument of RMATCH isn't
252    actuall used in this definition. */
253    
254  #ifndef NO_RECURSE  #ifndef NO_RECURSE
255  #define REGISTER register  #define REGISTER register
256  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) rx = match(ra,rb,rc,rd,re,rf,rg)  
257    #ifdef DEBUG
258    #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
259      { \
260      printf("match() called in line %d\n", __LINE__); \
261      rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1); \
262      printf("to line %d\n", __LINE__); \
263      }
264    #define RRETURN(ra) \
265      { \
266      printf("match() returned %d from line %d ", ra, __LINE__); \
267      return ra; \
268      }
269    #else
270    #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
271      rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1)
272  #define RRETURN(ra) return ra  #define RRETURN(ra) return ra
273    #endif
274    
275  #else  #else
276    
277    
278  /* These versions of the macros manage a private stack on the heap. Note  /* These versions of the macros manage a private stack on the heap. Note that
279  that the rd argument of RMATCH isn't actually used. It's the md argument of  the "rd" argument of RMATCH isn't actually used in this definition. It's the md
280  match(), which never changes. */  argument of match(), which never changes. */
281    
282  #define REGISTER  #define REGISTER
283    
284  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg)\  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw)\
285    {\    {\
286    heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\    heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\
287    if (setjmp(frame->Xwhere) == 0)\    frame->Xwhere = rw; \
288      {\    newframe->Xeptr = ra;\
289      newframe->Xeptr = ra;\    newframe->Xecode = rb;\
290      newframe->Xecode = rb;\    newframe->Xmstart = mstart;\
291      newframe->Xoffset_top = rc;\    newframe->Xoffset_top = rc;\
292      newframe->Xims = re;\    newframe->Xims = re;\
293      newframe->Xeptrb = rf;\    newframe->Xeptrb = rf;\
294      newframe->Xflags = rg;\    newframe->Xflags = rg;\
295      newframe->Xprevframe = frame;\    newframe->Xrdepth = frame->Xrdepth + 1;\
296      frame = newframe;\    newframe->Xprevframe = frame;\
297      DPRINTF(("restarting from line %d\n", __LINE__));\    frame = newframe;\
298      goto HEAP_RECURSE;\    DPRINTF(("restarting from line %d\n", __LINE__));\
299      }\    goto HEAP_RECURSE;\
300    else\    L_##rw:\
301      {\    DPRINTF(("jumped back to line %d\n", __LINE__));\
     DPRINTF(("longjumped back to line %d\n", __LINE__));\  
     frame = md->thisframe;\  
     rx = frame->Xresult;\  
     }\  
302    }    }
303    
304  #define RRETURN(ra)\  #define RRETURN(ra)\
# Line 235  match(), which never changes. */ Line 308  match(), which never changes. */
308    (pcre_stack_free)(newframe);\    (pcre_stack_free)(newframe);\
309    if (frame != NULL)\    if (frame != NULL)\
310      {\      {\
311      frame->Xresult = ra;\      rrc = ra;\
312      md->thisframe = frame;\      goto HEAP_RETURN;\
     longjmp(frame->Xwhere, 1);\  
313      }\      }\
314    return ra;\    return ra;\
315    }    }
# Line 252  typedef struct heapframe { Line 324  typedef struct heapframe {
324    
325    const uschar *Xeptr;    const uschar *Xeptr;
326    const uschar *Xecode;    const uschar *Xecode;
327      const uschar *Xmstart;
328    int Xoffset_top;    int Xoffset_top;
329    long int Xims;    long int Xims;
330    eptrblock *Xeptrb;    eptrblock *Xeptrb;
331    int Xflags;    int Xflags;
332      unsigned int Xrdepth;
333    
334    /* Function local variables */    /* Function local variables */
335    
# Line 271  typedef struct heapframe { Line 345  typedef struct heapframe {
345    
346    BOOL Xcur_is_word;    BOOL Xcur_is_word;
347    BOOL Xcondition;    BOOL Xcondition;
   BOOL Xminimize;  
348    BOOL Xprev_is_word;    BOOL Xprev_is_word;
349    
350    unsigned long int Xoriginal_ims;    unsigned long int Xoriginal_ims;
351    
352  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
353    int Xprop_type;    int Xprop_type;
354      int Xprop_value;
355    int Xprop_fail_result;    int Xprop_fail_result;
356    int Xprop_category;    int Xprop_category;
357    int Xprop_chartype;    int Xprop_chartype;
358    int Xprop_othercase;    int Xprop_script;
359    int Xprop_test_against;    int Xoclength;
360    int *Xprop_test_variable;    uschar Xocchars[8];
361  #endif  #endif
362    
363    int Xctype;    int Xctype;
364    int Xfc;    unsigned int Xfc;
365    int Xfi;    int Xfi;
366    int Xlength;    int Xlength;
367    int Xmax;    int Xmax;
# Line 301  typedef struct heapframe { Line 375  typedef struct heapframe {
375    
376    eptrblock Xnewptrb;    eptrblock Xnewptrb;
377    
378    /* Place to pass back result, and where to jump back to */    /* Where to jump back to */
379    
380    int  Xresult;    int Xwhere;
   jmp_buf Xwhere;  
381    
382  } heapframe;  } heapframe;
383    
# Line 320  typedef struct heapframe { Line 393  typedef struct heapframe {
393  *         Match from current position            *  *         Match from current position            *
394  *************************************************/  *************************************************/
395    
396  /* On entry ecode points to the first opcode, and eptr to the first character  /* This function is called recursively in many circumstances. Whenever it
 in the subject string, while eptrb holds the value of eptr at the start of the  
 last bracketed group - used for breaking infinite loops matching zero-length  
 strings. This function is called recursively in many circumstances. Whenever it  
397  returns a negative (error) response, the outer incarnation must also return the  returns a negative (error) response, the outer incarnation must also return the
398  same response.  same response.
399    
# Line 333  performance. Tests using gcc on a SPARC Line 403  performance. Tests using gcc on a SPARC
403  made performance worse.  made performance worse.
404    
405  Arguments:  Arguments:
406     eptr        pointer in subject     eptr        pointer to current character in subject
407     ecode       position in code     ecode       pointer to current position in compiled code
408       mstart      pointer to the current match start position (can be modified
409                     by encountering \K)
410     offset_top  current top pointer     offset_top  current top pointer
411     md          pointer to "static" info for the match     md          pointer to "static" info for the match
412     ims         current /i, /m, and /s options     ims         current /i, /m, and /s options
# Line 342  Arguments: Line 414  Arguments:
414                   brackets - for testing for empty matches                   brackets - for testing for empty matches
415     flags       can contain     flags       can contain
416                   match_condassert - this is an assertion condition                   match_condassert - this is an assertion condition
417                   match_isgroup - this is the start of a bracketed group                   match_cbegroup - this is the start of an unlimited repeat
418                       group that can match an empty string
419       rdepth      the recursion depth
420    
421  Returns:       MATCH_MATCH if matched            )  these values are >= 0  Returns:       MATCH_MATCH if matched            )  these values are >= 0
422                 MATCH_NOMATCH if failed to match  )                 MATCH_NOMATCH if failed to match  )
423                 a negative PCRE_ERROR_xxx value if aborted by an error condition                 a negative PCRE_ERROR_xxx value if aborted by an error condition
424                   (e.g. stopped by recursion limit)                   (e.g. stopped by repeated call or recursion limit)
425  */  */
426    
427  static int  static int
428  match(REGISTER const uschar *eptr, REGISTER const uschar *ecode,  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, const uschar *mstart,
429    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,
430    int flags)    int flags, unsigned int rdepth)
431  {  {
432  /* These variables do not need to be preserved over recursion in this function,  /* These variables do not need to be preserved over recursion in this function,
433  so they can be ordinary variables in all cases. Mark them with "register"  so they can be ordinary variables in all cases. Mark some of them with
434  because they are used a lot in loops. */  "register" because they are used a lot in loops. */
435    
436    register int  rrc;         /* Returns from recursive calls */
437    register int  i;           /* Used for loops not involving calls to RMATCH() */
438    register unsigned int c;   /* Character values not kept over RMATCH() calls */
439    register BOOL utf8;        /* Local copy of UTF-8 flag for speed */
440    
441  register int  rrc;    /* Returns from recursive calls */  BOOL minimize, possessive; /* Quantifier options */
 register int  i;      /* Used for loops not involving calls to RMATCH() */  
 register int  c;      /* Character values not kept over RMATCH() calls */  
 register BOOL utf8;   /* Local copy of UTF-8 flag for speed */  
442    
443  /* When recursion is not being used, all "local" variables that have to be  /* When recursion is not being used, all "local" variables that have to be
444  preserved over calls to RMATCH() are part of a "frame" which is obtained from  preserved over calls to RMATCH() are part of a "frame" which is obtained from
# Line 377  frame->Xprevframe = NULL;            /* Line 453  frame->Xprevframe = NULL;            /*
453    
454  frame->Xeptr = eptr;  frame->Xeptr = eptr;
455  frame->Xecode = ecode;  frame->Xecode = ecode;
456    frame->Xmstart = mstart;
457  frame->Xoffset_top = offset_top;  frame->Xoffset_top = offset_top;
458  frame->Xims = ims;  frame->Xims = ims;
459  frame->Xeptrb = eptrb;  frame->Xeptrb = eptrb;
460  frame->Xflags = flags;  frame->Xflags = flags;
461    frame->Xrdepth = rdepth;
462    
463  /* This is where control jumps back to to effect "recursion" */  /* This is where control jumps back to to effect "recursion" */
464    
# Line 390  HEAP_RECURSE: Line 468  HEAP_RECURSE:
468    
469  #define eptr               frame->Xeptr  #define eptr               frame->Xeptr
470  #define ecode              frame->Xecode  #define ecode              frame->Xecode
471    #define mstart             frame->Xmstart
472  #define offset_top         frame->Xoffset_top  #define offset_top         frame->Xoffset_top
473  #define ims                frame->Xims  #define ims                frame->Xims
474  #define eptrb              frame->Xeptrb  #define eptrb              frame->Xeptrb
475  #define flags              frame->Xflags  #define flags              frame->Xflags
476    #define rdepth             frame->Xrdepth
477    
478  /* Ditto for the local variables */  /* Ditto for the local variables */
479    
# Line 411  HEAP_RECURSE: Line 491  HEAP_RECURSE:
491    
492  #define cur_is_word        frame->Xcur_is_word  #define cur_is_word        frame->Xcur_is_word
493  #define condition          frame->Xcondition  #define condition          frame->Xcondition
 #define minimize           frame->Xminimize  
494  #define prev_is_word       frame->Xprev_is_word  #define prev_is_word       frame->Xprev_is_word
495    
496  #define original_ims       frame->Xoriginal_ims  #define original_ims       frame->Xoriginal_ims
497    
498  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
499  #define prop_type          frame->Xprop_type  #define prop_type          frame->Xprop_type
500    #define prop_value         frame->Xprop_value
501  #define prop_fail_result   frame->Xprop_fail_result  #define prop_fail_result   frame->Xprop_fail_result
502  #define prop_category      frame->Xprop_category  #define prop_category      frame->Xprop_category
503  #define prop_chartype      frame->Xprop_chartype  #define prop_chartype      frame->Xprop_chartype
504  #define prop_othercase     frame->Xprop_othercase  #define prop_script        frame->Xprop_script
505  #define prop_test_against  frame->Xprop_test_against  #define oclength           frame->Xoclength
506  #define prop_test_variable frame->Xprop_test_variable  #define occhars            frame->Xocchars
507  #endif  #endif
508    
509  #define ctype              frame->Xctype  #define ctype              frame->Xctype
# Line 447  HEAP_RECURSE: Line 527  HEAP_RECURSE:
527  get preserved during recursion in the normal way. In this environment, fi and  get preserved during recursion in the normal way. In this environment, fi and
528  i, and fc and c, can be the same variables. */  i, and fc and c, can be the same variables. */
529    
530  #else  #else         /* NO_RECURSE not defined */
531  #define fi i  #define fi i
532  #define fc c  #define fc c
533    
534    
535  #ifdef SUPPORT_UTF8                /* Many of these variables are used ony */  #ifdef SUPPORT_UTF8                /* Many of these variables are used only  */
536  const uschar *charptr;             /* small blocks of the code. My normal  */  const uschar *charptr;             /* in small blocks of the code. My normal */
537  #endif                             /* style of coding would have declared  */  #endif                             /* style of coding would have declared    */
538  const uschar *callpat;             /* them within each of those blocks.    */  const uschar *callpat;             /* them within each of those blocks.      */
539  const uschar *data;                /* However, in order to accommodate the */  const uschar *data;                /* However, in order to accommodate the   */
540  const uschar *next;                /* version of this code that uses an    */  const uschar *next;                /* version of this code that uses an      */
541  const uschar *pp;                  /* external "stack" implemented on the  */  USPTR         pp;                  /* external "stack" implemented on the    */
542  const uschar *prev;                /* heap, it is easier to declare them   */  const uschar *prev;                /* heap, it is easier to declare them all */
543  const uschar *saved_eptr;          /* all here, so the declarations can    */  USPTR         saved_eptr;          /* here, so the declarations can be cut   */
544                                     /* be cut out in a block. The only      */                                     /* out in a block. The only declarations  */
545  recursion_info new_recursive;      /* declarations within blocks below are */  recursion_info new_recursive;      /* within blocks below are for variables  */
546                                     /* for variables that do not have to    */                                     /* that do not have to be preserved over  */
547  BOOL cur_is_word;                  /* be preserved over a recursive call   */  BOOL cur_is_word;                  /* a recursive call to RMATCH().          */
548  BOOL condition;                    /* to RMATCH().                         */  BOOL condition;
 BOOL minimize;  
549  BOOL prev_is_word;  BOOL prev_is_word;
550    
551  unsigned long int original_ims;  unsigned long int original_ims;
552    
553  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
554  int prop_type;  int prop_type;
555    int prop_value;
556  int prop_fail_result;  int prop_fail_result;
557  int prop_category;  int prop_category;
558  int prop_chartype;  int prop_chartype;
559  int prop_othercase;  int prop_script;
560  int prop_test_against;  int oclength;
561  int *prop_test_variable;  uschar occhars[8];
562  #endif  #endif
563    
564  int ctype;  int ctype;
# Line 493  int save_offset1, save_offset2, save_off Line 573  int save_offset1, save_offset2, save_off
573  int stacksave[REC_STACK_SAVE_MAX];  int stacksave[REC_STACK_SAVE_MAX];
574    
575  eptrblock newptrb;  eptrblock newptrb;
576  #endif  #endif     /* NO_RECURSE */
577    
578  /* These statements are here to stop the compiler complaining about unitialized  /* These statements are here to stop the compiler complaining about unitialized
579  variables. */  variables. */
580    
581  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
582    prop_value = 0;
583  prop_fail_result = 0;  prop_fail_result = 0;
 prop_test_against = 0;  
 prop_test_variable = NULL;  
584  #endif  #endif
585    
586  /* OK, now we can get on with the real code of the function. Recursion is  
587  specified by the macros RMATCH and RRETURN. When NO_RECURSE is *not* defined,  /* This label is used for tail recursion, which is used in a few cases even
588  these just turn into a recursive call to match() and a "return", respectively.  when NO_RECURSE is not defined, in order to reduce the amount of stack that is
589  However, RMATCH isn't like a function call because it's quite a complicated  used. Thanks to Ian Taylor for noticing this possibility and sending the
590  macro. It has to be used in one particular way. This shouldn't, however, impact  original patch. */
591  performance when true recursion is being used. */  
592    TAIL_RECURSE:
593    
594    /* OK, now we can get on with the real code of the function. Recursive calls
595    are specified by the macro RMATCH and RRETURN is used to return. When
596    NO_RECURSE is *not* defined, these just turn into a recursive call to match()
597    and a "return", respectively (possibly with some debugging if DEBUG is
598    defined). However, RMATCH isn't like a function call because it's quite a
599    complicated macro. It has to be used in one particular way. This shouldn't,
600    however, impact performance when true recursion is being used. */
601    
602    #ifdef SUPPORT_UTF8
603    utf8 = md->utf8;       /* Local copy of the flag */
604    #else
605    utf8 = FALSE;
606    #endif
607    
608    /* First check that we haven't called match() too many times, or that we
609    haven't exceeded the recursive call limit. */
610    
611  if (md->match_call_count++ >= md->match_limit) RRETURN(PCRE_ERROR_MATCHLIMIT);  if (md->match_call_count++ >= md->match_limit) RRETURN(PCRE_ERROR_MATCHLIMIT);
612    if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT);
613    
614  original_ims = ims;    /* Save for resetting on ')' */  original_ims = ims;    /* Save for resetting on ')' */
 utf8 = md->utf8;       /* Local copy of the flag */  
615    
616  /* At the start of a bracketed group, add the current subject pointer to the  /* At the start of a group with an unlimited repeat that may match an empty
617  stack of such pointers, to be re-instated at the end of the group when we hit  string, the match_cbegroup flag is set. When this is the case, add the current
618  the closing ket. When match() is called in other circumstances, we don't add to  subject pointer to the chain of such remembered pointers, to be checked when we
619  this stack. */  hit the closing ket, in order to break infinite loops that match no characters.
620    When match() is called in other circumstances, don't add to the chain. The
621    match_cbegroup flag must NOT be used with tail recursion, because the memory
622    block that is used is on the stack, so a new one may be required for each
623    match(). */
624    
625  if ((flags & match_isgroup) != 0)  if ((flags & match_cbegroup) != 0)
626    {    {
   newptrb.epb_prev = eptrb;  
627    newptrb.epb_saved_eptr = eptr;    newptrb.epb_saved_eptr = eptr;
628      newptrb.epb_prev = eptrb;
629    eptrb = &newptrb;    eptrb = &newptrb;
630    }    }
631    
632  /* Now start processing the operations. */  /* Now start processing the opcodes. */
633    
634  for (;;)  for (;;)
635    {    {
636      minimize = possessive = FALSE;
637    op = *ecode;    op = *ecode;
   minimize = FALSE;  
638    
639    /* For partial matching, remember if we ever hit the end of the subject after    /* For partial matching, remember if we ever hit the end of the subject after
640    matching at least one subject character. */    matching at least one subject character. */
641    
642    if (md->partial &&    if (md->partial &&
643        eptr >= md->end_subject &&        eptr >= md->end_subject &&
644        eptr > md->start_match)        eptr > mstart)
645      md->hitend = TRUE;      md->hitend = TRUE;
646    
647    /* Opening capturing bracket. If there is space in the offset vector, save    switch(op)
   the current subject position in the working slot at the top of the vector. We  
   mustn't change the current values of the data slot, because they may be set  
   from a previous iteration of this group, and be referred to by a reference  
   inside the group.  
   
   If the bracket fails to match, we need to restore this value and also the  
   values of the final offsets, in case they were set by a previous iteration of  
   the same bracket.  
   
   If there isn't enough space in the offset vector, treat this as if it were a  
   non-capturing bracket. Don't worry about setting the flag for the error case  
   here; that is handled in the code for KET. */  
   
   if (op > OP_BRA)  
648      {      {
649      number = op - OP_BRA;      case OP_FAIL:
650        RRETURN(MATCH_NOMATCH);
     /* For extended extraction brackets (large number), we have to fish out the  
     number from a dummy opcode at the start. */  
651    
652      if (number > EXTRACT_BASIC_MAX)      case OP_PRUNE:
653        number = GET2(ecode, 2+LINK_SIZE);      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
654          ims, eptrb, flags, RM51);
655        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
656        RRETURN(MATCH_PRUNE);
657    
658        case OP_COMMIT:
659        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
660          ims, eptrb, flags, RM52);
661        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
662        RRETURN(MATCH_COMMIT);
663    
664        case OP_SKIP:
665        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
666          ims, eptrb, flags, RM53);
667        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
668        md->start_match_ptr = eptr;   /* Pass back current position */
669        RRETURN(MATCH_SKIP);
670    
671        case OP_THEN:
672        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
673          ims, eptrb, flags, RM54);
674        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
675        RRETURN(MATCH_THEN);
676    
677        /* Handle a capturing bracket. If there is space in the offset vector, save
678        the current subject position in the working slot at the top of the vector.
679        We mustn't change the current values of the data slot, because they may be
680        set from a previous iteration of this group, and be referred to by a
681        reference inside the group.
682    
683        If the bracket fails to match, we need to restore this value and also the
684        values of the final offsets, in case they were set by a previous iteration
685        of the same bracket.
686    
687        If there isn't enough space in the offset vector, treat this as if it were
688        a non-capturing bracket. Don't worry about setting the flag for the error
689        case here; that is handled in the code for KET. */
690    
691        case OP_CBRA:
692        case OP_SCBRA:
693        number = GET2(ecode, 1+LINK_SIZE);
694      offset = number << 1;      offset = number << 1;
695    
696  #ifdef DEBUG  #ifdef DEBUG
697      printf("start bracket %d subject=", number);      printf("start bracket %d\n", number);
698        printf("subject=");
699      pchars(eptr, 16, TRUE, md);      pchars(eptr, 16, TRUE, md);
700      printf("\n");      printf("\n");
701  #endif  #endif
# Line 584  for (;;) Line 710  for (;;)
710        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
711        md->offset_vector[md->offset_end - number] = eptr - md->start_subject;        md->offset_vector[md->offset_end - number] = eptr - md->start_subject;
712    
713          flags = (op == OP_SCBRA)? match_cbegroup : 0;
714        do        do
715          {          {
716          RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
717            match_isgroup);            ims, eptrb, flags, RM1);
718          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
719          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
720          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
721          }          }
# Line 603  for (;;) Line 730  for (;;)
730        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
731        }        }
732    
733      /* Insufficient room for saving captured contents */      /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
734        as a non-capturing bracket. */
735    
736      else op = OP_BRA;      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
737      }      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
738    
739    /* Other types of node can be handled by a switch */      DPRINTF(("insufficient capture room: treat as non-capturing\n"));
740    
741    switch(op)      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
742      {      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
743      case OP_BRA:     /* Non-capturing bracket: optimized */  
744      DPRINTF(("start bracket 0\n"));      /* Non-capturing bracket. Loop for all the alternatives. When we get to the
745      do      final alternative within the brackets, we would return the result of a
746        recursive call to match() whatever happened. We can reduce stack usage by
747        turning this into a tail recursion, except in the case when match_cbegroup
748        is set.*/
749    
750        case OP_BRA:
751        case OP_SBRA:
752        DPRINTF(("start non-capturing bracket\n"));
753        flags = (op >= OP_SBRA)? match_cbegroup : 0;
754        for (;;)
755        {        {
756        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,        if (ecode[GET(ecode, 1)] != OP_ALT)   /* Final alternative */
757          match_isgroup);          {
758        if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (flags == 0)    /* Not a possibly empty group */
759              {
760              ecode += _pcre_OP_lengths[*ecode];
761              DPRINTF(("bracket 0 tail recursion\n"));
762              goto TAIL_RECURSE;
763              }
764    
765            /* Possibly empty group; can't use tail recursion. */
766    
767            RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
768              eptrb, flags, RM48);
769            RRETURN(rrc);
770            }
771    
772          /* For non-final alternatives, continue the loop for a NOMATCH result;
773          otherwise return. */
774    
775          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
776            eptrb, flags, RM2);
777          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
778        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
779        }        }
780      while (*ecode == OP_ALT);      /* Control never reaches here. */
     DPRINTF(("bracket 0 failed\n"));  
     RRETURN(MATCH_NOMATCH);  
781    
782      /* Conditional group: compilation checked that there are no more than      /* Conditional group: compilation checked that there are no more than
783      two branches. If the condition is false, skipping the first branch takes us      two branches. If the condition is false, skipping the first branch takes us
784      past the end if there is only one branch, but that's OK because that is      past the end if there is only one branch, but that's OK because that is
785      exactly what going to the ket would do. */      exactly what going to the ket would do. As there is only one branch to be
786        obeyed, we can use tail recursion to avoid using another stack frame. */
787    
788      case OP_COND:      case OP_COND:
789      if (ecode[LINK_SIZE+1] == OP_CREF) /* Condition extract or recurse test */      case OP_SCOND:
790        if (ecode[LINK_SIZE+1] == OP_RREF)         /* Recursion test */
791          {
792          offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/
793          condition = md->recursive != NULL &&
794            (offset == RREF_ANY || offset == md->recursive->group_num);
795          ecode += condition? 3 : GET(ecode, 1);
796          }
797    
798        else if (ecode[LINK_SIZE+1] == OP_CREF)    /* Group used test */
799        {        {
800        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */
801        condition = (offset == CREF_RECURSE * 2)?        condition = offset < offset_top && md->offset_vector[offset] >= 0;
802          (md->recursive != NULL) :        ecode += condition? 3 : GET(ecode, 1);
803          (offset < offset_top && md->offset_vector[offset] >= 0);        }
804        RMATCH(rrc, eptr, ecode + (condition?  
805          (LINK_SIZE + 4) : (LINK_SIZE + 1 + GET(ecode, 1))),      else if (ecode[LINK_SIZE+1] == OP_DEF)     /* DEFINE - always false */
806          offset_top, md, ims, eptrb, match_isgroup);        {
807        RRETURN(rrc);        condition = FALSE;
808          ecode += GET(ecode, 1);
809        }        }
810    
811      /* The condition is an assertion. Call match() to evaluate it - setting      /* The condition is an assertion. Call match() to evaluate it - setting
812      the final argument TRUE causes it to stop at the end of an assertion. */      the final argument match_condassert causes it to stop at the end of an
813        assertion. */
814    
815      else      else
816        {        {
817        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,
818            match_condassert | match_isgroup);            match_condassert, RM3);
819        if (rrc == MATCH_MATCH)        if (rrc == MATCH_MATCH)
820          {          {
821          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE+2);          condition = TRUE;
822            ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
823          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
824          }          }
825        else if (rrc != MATCH_NOMATCH)        else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
826          {          {
827          RRETURN(rrc);         /* Need braces because of following else */          RRETURN(rrc);         /* Need braces because of following else */
828          }          }
829        else ecode += GET(ecode, 1);        else
830        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,          {
831          match_isgroup);          condition = FALSE;
832        RRETURN(rrc);          ecode += GET(ecode, 1);
833            }
834        }        }
     /* Control never reaches here */  
835    
836      /* Skip over conditional reference or large extraction number data if      /* We are now at the branch that is to be obeyed. As there is only one,
837      encountered. */      we can use tail recursion to avoid using another stack frame, except when
838        match_cbegroup is required for an unlimited repeat of a possibly empty
839        group. If the second alternative doesn't exist, we can just plough on. */
840    
841      case OP_CREF:      if (condition || *ecode == OP_ALT)
842      case OP_BRANUMBER:        {
843      ecode += 3;        ecode += 1 + LINK_SIZE;
844          if (op == OP_SCOND)        /* Possibly empty group */
845            {
846            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49);
847            RRETURN(rrc);
848            }
849          else                       /* Group must match something */
850            {
851            flags = 0;
852            goto TAIL_RECURSE;
853            }
854          }
855        else                         /* Condition false & no 2nd alternative */
856          {
857          ecode += 1 + LINK_SIZE;
858          }
859      break;      break;
860    
     /* End of the pattern. If we are in a recursion, we should restore the  
     offsets appropriately and continue from after the call. */  
861    
862        /* End of the pattern, either real or forced. If we are in a top-level
863        recursion, we should restore the offsets appropriately and continue from
864        after the call. */
865    
866        case OP_ACCEPT:
867      case OP_END:      case OP_END:
868      if (md->recursive != NULL && md->recursive->group_num == 0)      if (md->recursive != NULL && md->recursive->group_num == 0)
869        {        {
870        recursion_info *rec = md->recursive;        recursion_info *rec = md->recursive;
871        DPRINTF(("Hit the end in a (?0) recursion\n"));        DPRINTF(("End of pattern in a (?0) recursion\n"));
872        md->recursive = rec->prevrec;        md->recursive = rec->prevrec;
873        memmove(md->offset_vector, rec->offset_save,        memmove(md->offset_vector, rec->offset_save,
874          rec->saved_max * sizeof(int));          rec->saved_max * sizeof(int));
875        md->start_match = rec->save_start;        mstart = rec->save_start;
876        ims = original_ims;        ims = original_ims;
877        ecode = rec->after_call;        ecode = rec->after_call;
878        break;        break;
# Line 694  for (;;) Line 881  for (;;)
881      /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty      /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty
882      string - backtracking will then try other alternatives, if any. */      string - backtracking will then try other alternatives, if any. */
883    
884      if (md->notempty && eptr == md->start_match) RRETURN(MATCH_NOMATCH);      if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH);
885      md->end_match_ptr = eptr;          /* Record where we ended */      md->end_match_ptr = eptr;           /* Record where we ended */
886      md->end_offset_top = offset_top;   /* and how many extracts were taken */      md->end_offset_top = offset_top;    /* and how many extracts were taken */
887        md->start_match_ptr = mstart;       /* and the start (\K can modify) */
888      RRETURN(MATCH_MATCH);      RRETURN(MATCH_MATCH);
889    
890      /* Change option settings */      /* Change option settings */
# Line 717  for (;;) Line 905  for (;;)
905      case OP_ASSERTBACK:      case OP_ASSERTBACK:
906      do      do
907        {        {
908        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
909          match_isgroup);          RM4);
910        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH) break;
911        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
912        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
913        }        }
914      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 744  for (;;) Line 932  for (;;)
932      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
933      do      do
934        {        {
935        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
936          match_isgroup);          RM5);
937        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);
938        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
939        ecode += GET(ecode,1);        ecode += GET(ecode,1);
940        }        }
941      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 766  for (;;) Line 954  for (;;)
954  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
955      if (utf8)      if (utf8)
956        {        {
957        c = GET(ecode,1);        i = GET(ecode, 1);
958        for (i = 0; i < c; i++)        while (i-- > 0)
959          {          {
960          eptr--;          eptr--;
961          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
962          BACKCHAR(eptr)          BACKCHAR(eptr);
963          }          }
964        }        }
965      else      else
# Line 780  for (;;) Line 968  for (;;)
968      /* No UTF-8 support, or not in UTF-8 mode: count is byte count */      /* No UTF-8 support, or not in UTF-8 mode: count is byte count */
969    
970        {        {
971        eptr -= GET(ecode,1);        eptr -= GET(ecode, 1);
972        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
973        }        }
974    
# Line 800  for (;;) Line 988  for (;;)
988        cb.version          = 1;   /* Version 1 of the callout block */        cb.version          = 1;   /* Version 1 of the callout block */
989        cb.callout_number   = ecode[1];        cb.callout_number   = ecode[1];
990        cb.offset_vector    = md->offset_vector;        cb.offset_vector    = md->offset_vector;
991        cb.subject          = (const char *)md->start_subject;        cb.subject          = (PCRE_SPTR)md->start_subject;
992        cb.subject_length   = md->end_subject - md->start_subject;        cb.subject_length   = md->end_subject - md->start_subject;
993        cb.start_match      = md->start_match - md->start_subject;        cb.start_match      = mstart - md->start_subject;
994        cb.current_position = eptr - md->start_subject;        cb.current_position = eptr - md->start_subject;
995        cb.pattern_position = GET(ecode, 2);        cb.pattern_position = GET(ecode, 2);
996        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
# Line 837  for (;;) Line 1025  for (;;)
1025      case OP_RECURSE:      case OP_RECURSE:
1026        {        {
1027        callpat = md->start_code + GET(ecode, 1);        callpat = md->start_code + GET(ecode, 1);
1028        new_recursive.group_num = *callpat - OP_BRA;        new_recursive.group_num = (callpat == md->start_code)? 0 :
1029            GET2(callpat, 1 + LINK_SIZE);
       /* For extended extraction brackets (large number), we have to fish out  
       the number from a dummy opcode at the start. */  
   
       if (new_recursive.group_num > EXTRACT_BASIC_MAX)  
         new_recursive.group_num = GET2(callpat, 2+LINK_SIZE);  
1030    
1031        /* Add to "recursing stack" */        /* Add to "recursing stack" */
1032    
# Line 869  for (;;) Line 1052  for (;;)
1052    
1053        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
1054              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1055        new_recursive.save_start = md->start_match;        new_recursive.save_start = mstart;
1056        md->start_match = eptr;        mstart = eptr;
1057    
1058        /* OK, now we can do the recursion. For each top-level alternative we        /* OK, now we can do the recursion. For each top-level alternative we
1059        restore the offset and recursion data. */        restore the offset and recursion data. */
1060    
1061        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));
1062          flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;
1063        do        do
1064          {          {
1065          RMATCH(rrc, eptr, callpat + 1 + LINK_SIZE, offset_top, md, ims,          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
1066              eptrb, match_isgroup);            md, ims, eptrb, flags, RM6);
1067          if (rrc == MATCH_MATCH)          if (rrc == MATCH_MATCH)
1068            {            {
1069              DPRINTF(("Recursion matched\n"));
1070            md->recursive = new_recursive.prevrec;            md->recursive = new_recursive.prevrec;
1071            if (new_recursive.offset_save != stacksave)            if (new_recursive.offset_save != stacksave)
1072              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1073            RRETURN(MATCH_MATCH);            RRETURN(MATCH_MATCH);
1074            }            }
1075          else if (rrc != MATCH_NOMATCH) RRETURN(rrc);          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1076              {
1077              DPRINTF(("Recursion gave error %d\n", rrc));
1078              RRETURN(rrc);
1079              }
1080    
1081          md->recursive = &new_recursive;          md->recursive = &new_recursive;
1082          memcpy(md->offset_vector, new_recursive.offset_save,          memcpy(md->offset_vector, new_recursive.offset_save,
# Line 912  for (;;) Line 1101  for (;;)
1101      the end of a normal bracket, leaving the subject pointer. */      the end of a normal bracket, leaving the subject pointer. */
1102    
1103      case OP_ONCE:      case OP_ONCE:
1104        {      prev = ecode;
1105        prev = ecode;      saved_eptr = eptr;
       saved_eptr = eptr;  
1106    
1107        do      do
1108          {        {
1109          RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);
1110            eptrb, match_isgroup);        if (rrc == MATCH_MATCH) break;
1111          if (rrc == MATCH_MATCH) break;        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1112          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        ecode += GET(ecode,1);
1113          ecode += GET(ecode,1);        }
1114          }      while (*ecode == OP_ALT);
       while (*ecode == OP_ALT);  
1115    
1116        /* If hit the end of the group (which could be repeated), fail */      /* If hit the end of the group (which could be repeated), fail */
1117    
1118        if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);      if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);
1119    
1120        /* Continue as from after the assertion, updating the offsets high water      /* Continue as from after the assertion, updating the offsets high water
1121        mark, since extracts may have been taken. */      mark, since extracts may have been taken. */
1122    
1123        do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode, 1); while (*ecode == OP_ALT);
1124    
1125        offset_top = md->end_offset_top;      offset_top = md->end_offset_top;
1126        eptr = md->end_match_ptr;      eptr = md->end_match_ptr;
1127    
1128        /* For a non-repeating ket, just continue at this level. This also      /* For a non-repeating ket, just continue at this level. This also
1129        happens for a repeating ket if no characters were matched in the group.      happens for a repeating ket if no characters were matched in the group.
1130        This is the forcible breaking of infinite loops as implemented in Perl      This is the forcible breaking of infinite loops as implemented in Perl
1131        5.005. If there is an options reset, it will get obeyed in the normal      5.005. If there is an options reset, it will get obeyed in the normal
1132        course of events. */      course of events. */
1133    
1134        if (*ecode == OP_KET || eptr == saved_eptr)      if (*ecode == OP_KET || eptr == saved_eptr)
1135          {        {
1136          ecode += 1+LINK_SIZE;        ecode += 1+LINK_SIZE;
1137          break;        break;
1138          }        }
1139    
1140        /* The repeating kets try the rest of the pattern or restart from the      /* The repeating kets try the rest of the pattern or restart from the
1141        preceding bracket, in the appropriate order. We need to reset any options      preceding bracket, in the appropriate order. The second "call" of match()
1142        that changed within the bracket before re-running it, so check the next      uses tail recursion, to avoid using another stack frame. We need to reset
1143        opcode. */      any options that changed within the bracket before re-running it, so
1144        check the next opcode. */
1145    
1146        if (ecode[1+LINK_SIZE] == OP_OPT)      if (ecode[1+LINK_SIZE] == OP_OPT)
1147          {        {
1148          ims = (ims & ~PCRE_IMS) | ecode[4];        ims = (ims & ~PCRE_IMS) | ecode[4];
1149          DPRINTF(("ims set to %02lx at group repeat\n", ims));        DPRINTF(("ims set to %02lx at group repeat\n", ims));
1150          }        }
1151    
1152        if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1153          {        {
1154          RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM8);
1155          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1156          RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);        ecode = prev;
1157          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        flags = 0;
1158          }        goto TAIL_RECURSE;
       else  /* OP_KETRMAX */  
         {  
         RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);  
         if (rrc != MATCH_NOMATCH) RRETURN(rrc);  
         RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);  
         if (rrc != MATCH_NOMATCH) RRETURN(rrc);  
         }  
1159        }        }
1160      RRETURN(MATCH_NOMATCH);      else  /* OP_KETRMAX */
1161          {
1162          RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);
1163          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1164          ecode += 1 + LINK_SIZE;
1165          flags = 0;
1166          goto TAIL_RECURSE;
1167          }
1168        /* Control never gets here */
1169    
1170      /* An alternation is the end of a branch; scan along to find the end of the      /* An alternation is the end of a branch; scan along to find the end of the
1171      bracketed group and go to there. */      bracketed group and go to there. */
# Line 985  for (;;) Line 1174  for (;;)
1174      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1175      break;      break;
1176    
1177      /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating      /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group,
1178      that it may occur zero times. It may repeat infinitely, or not at all -      indicating that it may occur zero times. It may repeat infinitely, or not
1179      i.e. it could be ()* or ()? in the pattern. Brackets with fixed upper      at all - i.e. it could be ()* or ()? or even (){0} in the pattern. Brackets
1180      repeat limits are compiled as a number of copies, with the optional ones      with fixed upper repeat limits are compiled as a number of copies, with the
1181      preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1182    
1183      case OP_BRAZERO:      case OP_BRAZERO:
1184        {        {
1185        next = ecode+1;        next = ecode+1;
1186        RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10);
1187        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1188        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next,1); while (*next == OP_ALT);
1189        ecode = next + 1+LINK_SIZE;        ecode = next + 1 + LINK_SIZE;
1190        }        }
1191      break;      break;
1192    
1193      case OP_BRAMINZERO:      case OP_BRAMINZERO:
1194        {        {
1195        next = ecode+1;        next = ecode+1;
1196        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next, 1); while (*next == OP_ALT);
1197        RMATCH(rrc, eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb,        RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0, RM11);
         match_isgroup);  
1198        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1199        ecode++;        ecode++;
1200        }        }
1201      break;      break;
1202    
1203      /* End of a group, repeated or non-repeating. If we are at the end of      case OP_SKIPZERO:
1204      an assertion "group", stop matching and return MATCH_MATCH, but record the        {
1205      current high water mark for use by positive assertions. Do this also        next = ecode+1;
1206      for the "once" (not-backup up) groups. */        do next += GET(next,1); while (*next == OP_ALT);
1207          ecode = next + 1 + LINK_SIZE;
1208          }
1209        break;
1210    
1211        /* End of a group, repeated or non-repeating. */
1212    
1213      case OP_KET:      case OP_KET:
1214      case OP_KETRMIN:      case OP_KETRMIN:
1215      case OP_KETRMAX:      case OP_KETRMAX:
1216        {      prev = ecode - GET(ecode, 1);
       prev = ecode - GET(ecode, 1);  
       saved_eptr = eptrb->epb_saved_eptr;  
   
       /* Back up the stack of bracket start pointers. */  
1217    
1218        eptrb = eptrb->epb_prev;      /* If this was a group that remembered the subject start, in order to break
1219        infinite repeats of empty string matches, retrieve the subject start from
1220        the chain. Otherwise, set it NULL. */
1221    
1222        if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||      if (*prev >= OP_SBRA)
1223            *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||        {
1224            *prev == OP_ONCE)        saved_eptr = eptrb->epb_saved_eptr;   /* Value at start of group */
1225          {        eptrb = eptrb->epb_prev;              /* Backup to previous group */
1226          md->end_match_ptr = eptr;      /* For ONCE */        }
1227          md->end_offset_top = offset_top;      else saved_eptr = NULL;
         RRETURN(MATCH_MATCH);  
         }  
1228    
1229        /* In all other cases except a conditional group we have to check the      /* If we are at the end of an assertion group, stop matching and return
1230        group number back at the start and if necessary complete handling an      MATCH_MATCH, but record the current high water mark for use by positive
1231        extraction by setting the offsets and bumping the high water mark. */      assertions. Do this also for the "once" (atomic) groups. */
1232    
1233        if (*prev != OP_COND)      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||
1234          {          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||
1235          number = *prev - OP_BRA;          *prev == OP_ONCE)
1236          {
1237          md->end_match_ptr = eptr;      /* For ONCE */
1238          md->end_offset_top = offset_top;
1239          RRETURN(MATCH_MATCH);
1240          }
1241    
1242          /* For extended extraction brackets (large number), we have to fish out      /* For capturing groups we have to check the group number back at the start
1243          the number from a dummy opcode at the start. */      and if necessary complete handling an extraction by setting the offsets and
1244        bumping the high water mark. Note that whole-pattern recursion is coded as
1245        a recurse into group 0, so it won't be picked up here. Instead, we catch it
1246        when the OP_END is reached. Other recursion is handled here. */
1247    
1248          if (number > EXTRACT_BASIC_MAX) number = GET2(prev, 2+LINK_SIZE);      if (*prev == OP_CBRA || *prev == OP_SCBRA)
1249          offset = number << 1;        {
1250          number = GET2(prev, 1+LINK_SIZE);
1251          offset = number << 1;
1252    
1253  #ifdef DEBUG  #ifdef DEBUG
1254          printf("end bracket %d", number);        printf("end bracket %d", number);
1255          printf("\n");        printf("\n");
1256  #endif  #endif
1257    
1258          /* Test for a numbered group. This includes groups called as a result        md->capture_last = number;
1259          of recursion. Note that whole-pattern recursion is coded as a recurse        if (offset >= md->offset_max) md->offset_overflow = TRUE; else
1260          into group 0, so it won't be picked up here. Instead, we catch it when          {
1261          the OP_END is reached. */          md->offset_vector[offset] =
1262              md->offset_vector[md->offset_end - number];
1263          if (number > 0)          md->offset_vector[offset+1] = eptr - md->start_subject;
1264            {          if (offset_top <= offset) offset_top = offset + 2;
1265            md->capture_last = number;          }
1266            if (offset >= md->offset_max) md->offset_overflow = TRUE; else  
1267              {        /* Handle a recursively called group. Restore the offsets
1268              md->offset_vector[offset] =        appropriately and continue from after the call. */
1269                md->offset_vector[md->offset_end - number];  
1270              md->offset_vector[offset+1] = eptr - md->start_subject;        if (md->recursive != NULL && md->recursive->group_num == number)
1271              if (offset_top <= offset) offset_top = offset + 2;          {
1272              }          recursion_info *rec = md->recursive;
1273            DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
1274            /* Handle a recursively called group. Restore the offsets          md->recursive = rec->prevrec;
1275            appropriately and continue from after the call. */          mstart = rec->save_start;
1276            memcpy(md->offset_vector, rec->offset_save,
1277            if (md->recursive != NULL && md->recursive->group_num == number)            rec->saved_max * sizeof(int));
1278              {          ecode = rec->after_call;
1279              recursion_info *rec = md->recursive;          ims = original_ims;
1280              DPRINTF(("Recursion (%d) succeeded - continuing\n", number));          break;
             md->recursive = rec->prevrec;  
             md->start_match = rec->save_start;  
             memcpy(md->offset_vector, rec->offset_save,  
               rec->saved_max * sizeof(int));  
             ecode = rec->after_call;  
             ims = original_ims;  
             break;  
             }  
           }  
1281          }          }
1282          }
1283    
1284        /* Reset the value of the ims flags, in case they got changed during      /* For both capturing and non-capturing groups, reset the value of the ims
1285        the group. */      flags, in case they got changed during the group. */
1286    
1287        ims = original_ims;      ims = original_ims;
1288        DPRINTF(("ims reset to %02lx\n", ims));      DPRINTF(("ims reset to %02lx\n", ims));
1289    
1290        /* For a non-repeating ket, just continue at this level. This also      /* For a non-repeating ket, just continue at this level. This also
1291        happens for a repeating ket if no characters were matched in the group.      happens for a repeating ket if no characters were matched in the group.
1292        This is the forcible breaking of infinite loops as implemented in Perl      This is the forcible breaking of infinite loops as implemented in Perl
1293        5.005. If there is an options reset, it will get obeyed in the normal      5.005. If there is an options reset, it will get obeyed in the normal
1294        course of events. */      course of events. */
1295    
1296        if (*ecode == OP_KET || eptr == saved_eptr)      if (*ecode == OP_KET || eptr == saved_eptr)
1297          {        {
1298          ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1299          break;        break;
1300          }        }
1301    
1302        /* The repeating kets try the rest of the pattern or restart from the      /* The repeating kets try the rest of the pattern or restart from the
1303        preceding bracket, in the appropriate order. */      preceding bracket, in the appropriate order. In the second case, we can use
1304        tail recursion to avoid using another stack frame, unless we have an
1305        unlimited repeat of a group that can match an empty string. */
1306    
1307        if (*ecode == OP_KETRMIN)      flags = (*prev >= OP_SBRA)? match_cbegroup : 0;
1308          {  
1309          RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);      if (*ecode == OP_KETRMIN)
1310          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        {
1311          RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12);
1312          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1313          }        if (flags != 0)    /* Could match an empty string */
       else  /* OP_KETRMAX */  
1314          {          {
1315          RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);          RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);
1316          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          RRETURN(rrc);
         RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);  
         if (rrc != MATCH_NOMATCH) RRETURN(rrc);  
1317          }          }
1318          ecode = prev;
1319          goto TAIL_RECURSE;
1320        }        }
1321        else  /* OP_KETRMAX */
1322      RRETURN(MATCH_NOMATCH);        {
1323          RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);
1324          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1325          ecode += 1 + LINK_SIZE;
1326          flags = 0;
1327          goto TAIL_RECURSE;
1328          }
1329        /* Control never gets here */
1330    
1331      /* Start of subject unless notbol, or after internal newline if multiline */      /* Start of subject unless notbol, or after internal newline if multiline */
1332    
# Line 1135  for (;;) Line 1334  for (;;)
1334      if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);      if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);
1335      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1336        {        {
1337        if (eptr != md->start_subject && eptr[-1] != NEWLINE)        if (eptr != md->start_subject &&
1338              (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
1339          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
1340        ecode++;        ecode++;
1341        break;        break;
# Line 1156  for (;;) Line 1356  for (;;)
1356      ecode++;      ecode++;
1357      break;      break;
1358    
1359        /* Reset the start of match point */
1360    
1361        case OP_SET_SOM:
1362        mstart = eptr;
1363        ecode++;
1364        break;
1365    
1366      /* Assert before internal newline if multiline, or before a terminating      /* Assert before internal newline if multiline, or before a terminating
1367      newline unless endonly is set, else end of subject unless noteol is set. */      newline unless endonly is set, else end of subject unless noteol is set. */
1368    
# Line 1163  for (;;) Line 1370  for (;;)
1370      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1371        {        {
1372        if (eptr < md->end_subject)        if (eptr < md->end_subject)
1373          { if (*eptr != NEWLINE) RRETURN(MATCH_NOMATCH); }          { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); }
1374        else        else
1375          { if (md->noteol) RRETURN(MATCH_NOMATCH); }          { if (md->noteol) RRETURN(MATCH_NOMATCH); }
1376        ecode++;        ecode++;
# Line 1174  for (;;) Line 1381  for (;;)
1381        if (md->noteol) RRETURN(MATCH_NOMATCH);        if (md->noteol) RRETURN(MATCH_NOMATCH);
1382        if (!md->endonly)        if (!md->endonly)
1383          {          {
1384          if (eptr < md->end_subject - 1 ||          if (eptr != md->end_subject &&
1385             (eptr == md->end_subject - 1 && *eptr != NEWLINE))              (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1386            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1387          ecode++;          ecode++;
1388          break;          break;
1389          }          }
1390        }        }
1391      /* ... else fall through */      /* ... else fall through for endonly */
1392    
1393      /* End of subject assertion (\z) */      /* End of subject assertion (\z) */
1394    
# Line 1193  for (;;) Line 1400  for (;;)
1400      /* End of subject or ending \n assertion (\Z) */      /* End of subject or ending \n assertion (\Z) */
1401    
1402      case OP_EODN:      case OP_EODN:
1403      if (eptr < md->end_subject - 1 ||      if (eptr != md->end_subject &&
1404         (eptr == md->end_subject - 1 && *eptr != NEWLINE)) RRETURN(MATCH_NOMATCH);          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1405          RRETURN(MATCH_NOMATCH);
1406      ecode++;      ecode++;
1407      break;      break;
1408    
# Line 1247  for (;;) Line 1455  for (;;)
1455      /* Match a single character type; inline for speed */      /* Match a single character type; inline for speed */
1456    
1457      case OP_ANY:      case OP_ANY:
1458      if ((ims & PCRE_DOTALL) == 0 && eptr < md->end_subject && *eptr == NEWLINE)      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
1459        RRETURN(MATCH_NOMATCH);      /* Fall through */
1460    
1461        case OP_ALLANY:
1462      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);
1463  #ifdef SUPPORT_UTF8      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
     if (utf8)  
       while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
 #endif  
1464      ecode++;      ecode++;
1465      break;      break;
1466    
# Line 1343  for (;;) Line 1550  for (;;)
1550      ecode++;      ecode++;
1551      break;      break;
1552    
1553        case OP_ANYNL:
1554        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1555        GETCHARINCTEST(c, eptr);
1556        switch(c)
1557          {
1558          default: RRETURN(MATCH_NOMATCH);
1559          case 0x000d:
1560          if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
1561          break;
1562    
1563          case 0x000a:
1564          break;
1565    
1566          case 0x000b:
1567          case 0x000c:
1568          case 0x0085:
1569          case 0x2028:
1570          case 0x2029:
1571          if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
1572          break;
1573          }
1574        ecode++;
1575        break;
1576    
1577        case OP_NOT_HSPACE:
1578        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1579        GETCHARINCTEST(c, eptr);
1580        switch(c)
1581          {
1582          default: break;
1583          case 0x09:      /* HT */
1584          case 0x20:      /* SPACE */
1585          case 0xa0:      /* NBSP */
1586          case 0x1680:    /* OGHAM SPACE MARK */
1587          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1588          case 0x2000:    /* EN QUAD */
1589          case 0x2001:    /* EM QUAD */
1590          case 0x2002:    /* EN SPACE */
1591          case 0x2003:    /* EM SPACE */
1592          case 0x2004:    /* THREE-PER-EM SPACE */
1593          case 0x2005:    /* FOUR-PER-EM SPACE */
1594          case 0x2006:    /* SIX-PER-EM SPACE */
1595          case 0x2007:    /* FIGURE SPACE */
1596          case 0x2008:    /* PUNCTUATION SPACE */
1597          case 0x2009:    /* THIN SPACE */
1598          case 0x200A:    /* HAIR SPACE */
1599          case 0x202f:    /* NARROW NO-BREAK SPACE */
1600          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1601          case 0x3000:    /* IDEOGRAPHIC SPACE */
1602          RRETURN(MATCH_NOMATCH);
1603          }
1604        ecode++;
1605        break;
1606    
1607        case OP_HSPACE:
1608        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1609        GETCHARINCTEST(c, eptr);
1610        switch(c)
1611          {
1612          default: RRETURN(MATCH_NOMATCH);
1613          case 0x09:      /* HT */
1614          case 0x20:      /* SPACE */
1615          case 0xa0:      /* NBSP */
1616          case 0x1680:    /* OGHAM SPACE MARK */
1617          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1618          case 0x2000:    /* EN QUAD */
1619          case 0x2001:    /* EM QUAD */
1620          case 0x2002:    /* EN SPACE */
1621          case 0x2003:    /* EM SPACE */
1622          case 0x2004:    /* THREE-PER-EM SPACE */
1623          case 0x2005:    /* FOUR-PER-EM SPACE */
1624          case 0x2006:    /* SIX-PER-EM SPACE */
1625          case 0x2007:    /* FIGURE SPACE */
1626          case 0x2008:    /* PUNCTUATION SPACE */
1627          case 0x2009:    /* THIN SPACE */
1628          case 0x200A:    /* HAIR SPACE */
1629          case 0x202f:    /* NARROW NO-BREAK SPACE */
1630          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1631          case 0x3000:    /* IDEOGRAPHIC SPACE */
1632          break;
1633          }
1634        ecode++;
1635        break;
1636    
1637        case OP_NOT_VSPACE:
1638        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1639        GETCHARINCTEST(c, eptr);
1640        switch(c)
1641          {
1642          default: break;
1643          case 0x0a:      /* LF */
1644          case 0x0b:      /* VT */
1645          case 0x0c:      /* FF */
1646          case 0x0d:      /* CR */
1647          case 0x85:      /* NEL */
1648          case 0x2028:    /* LINE SEPARATOR */
1649          case 0x2029:    /* PARAGRAPH SEPARATOR */
1650          RRETURN(MATCH_NOMATCH);
1651          }
1652        ecode++;
1653        break;
1654    
1655        case OP_VSPACE:
1656        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1657        GETCHARINCTEST(c, eptr);
1658        switch(c)
1659          {
1660          default: RRETURN(MATCH_NOMATCH);
1661          case 0x0a:      /* LF */
1662          case 0x0b:      /* VT */
1663          case 0x0c:      /* FF */
1664          case 0x0d:      /* CR */
1665          case 0x85:      /* NEL */
1666          case 0x2028:    /* LINE SEPARATOR */
1667          case 0x2029:    /* PARAGRAPH SEPARATOR */
1668          break;
1669          }
1670        ecode++;
1671        break;
1672    
1673  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
1674      /* Check the next character by Unicode property. We will get here only      /* Check the next character by Unicode property. We will get here only
1675      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. */
# Line 1352  for (;;) Line 1679  for (;;)
1679      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1680      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1681        {        {
1682        int chartype, rqdtype;        const ucd_record * prop = GET_UCD(c);
       int othercase;  
       int category = ucp_findchar(c, &chartype, &othercase);  
   
       rqdtype = *(++ecode);  
       ecode++;  
1683    
1684        if (rqdtype >= 128)        switch(ecode[1])
1685          {          {
1686          if ((rqdtype - 128 != category) == (op == OP_PROP))          case PT_ANY:
1687            if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH);
1688            break;
1689    
1690            case PT_LAMP:
1691            if ((prop->chartype == ucp_Lu ||
1692                 prop->chartype == ucp_Ll ||
1693                 prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
1694            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1695          }           break;
1696        else  
1697          {          case PT_GC:
1698          if ((rqdtype != chartype) == (op == OP_PROP))          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
1699              RRETURN(MATCH_NOMATCH);
1700            break;
1701    
1702            case PT_PC:
1703            if ((ecode[2] != prop->chartype) == (op == OP_PROP))
1704              RRETURN(MATCH_NOMATCH);
1705            break;
1706    
1707            case PT_SC:
1708            if ((ecode[2] != prop->script) == (op == OP_PROP))
1709            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1710            break;
1711    
1712            default:
1713            RRETURN(PCRE_ERROR_INTERNAL);
1714          }          }
1715    
1716          ecode += 3;
1717        }        }
1718      break;      break;
1719    
# Line 1379  for (;;) Line 1724  for (;;)
1724      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1725      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1726        {        {
1727        int chartype;        int category = UCD_CATEGORY(c);
       int othercase;  
       int category = ucp_findchar(c, &chartype, &othercase);  
1728        if (category == ucp_M) RRETURN(MATCH_NOMATCH);        if (category == ucp_M) RRETURN(MATCH_NOMATCH);
1729        while (eptr < md->end_subject)        while (eptr < md->end_subject)
1730          {          {
# Line 1390  for (;;) Line 1733  for (;;)
1733            {            {
1734            GETCHARLEN(c, eptr, len);            GETCHARLEN(c, eptr, len);
1735            }            }
1736          category = ucp_findchar(c, &chartype, &othercase);          category = UCD_CATEGORY(c);
1737          if (category != ucp_M) break;          if (category != ucp_M) break;
1738          eptr += len;          eptr += len;
1739          }          }
# Line 1411  for (;;) Line 1754  for (;;)
1754      case OP_REF:      case OP_REF:
1755        {        {
1756        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
1757        ecode += 3;                                 /* Advance past item */        ecode += 3;
1758    
1759        /* If the reference is unset, set the length to be longer than the amount        /* If the reference is unset, there are two possibilities:
       of subject left; this ensures that every attempt at a match fails. We  
       can't just fail here, because of the possibility of quantifiers with zero  
       minima. */  
   
       length = (offset >= offset_top || md->offset_vector[offset] < 0)?  
         md->end_subject - eptr + 1 :  
         md->offset_vector[offset+1] - md->offset_vector[offset];  
1760    
1761        /* Set up for repetition, or handle the non-repeated case */        (a) In the default, Perl-compatible state, set the length to be longer
1762          than the amount of subject left; this ensures that every attempt at a
1763          match fails. We can't just fail here, because of the possibility of
1764          quantifiers with zero minima.
1765    
1766        switch (*ecode)        (b) If the JavaScript compatibility flag is set, set the length to zero
1767          {        so that the back reference matches an empty string.
1768    
1769          Otherwise, set the length to the length of what was matched by the
1770          referenced subpattern. */
1771    
1772          if (offset >= offset_top || md->offset_vector[offset] < 0)
1773            length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;
1774          else
1775            length = md->offset_vector[offset+1] - md->offset_vector[offset];
1776    
1777          /* Set up for repetition, or handle the non-repeated case */
1778    
1779          switch (*ecode)
1780            {
1781          case OP_CRSTAR:          case OP_CRSTAR:
1782          case OP_CRMINSTAR:          case OP_CRMINSTAR:
1783          case OP_CRPLUS:          case OP_CRPLUS:
# Line 1480  for (;;) Line 1832  for (;;)
1832          {          {
1833          for (fi = min;; fi++)          for (fi = min;; fi++)
1834            {            {
1835            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
1836            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1837            if (fi >= max || !match_ref(offset, eptr, length, md, ims))            if (fi >= max || !match_ref(offset, eptr, length, md, ims))
1838              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
# Line 1501  for (;;) Line 1853  for (;;)
1853            }            }
1854          while (eptr >= pp)          while (eptr >= pp)
1855            {            {
1856            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);
1857            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1858            eptr -= length;            eptr -= length;
1859            }            }
# Line 1606  for (;;) Line 1958  for (;;)
1958            {            {
1959            for (fi = min;; fi++)            for (fi = min;; fi++)
1960              {              {
1961              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
1962              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1963              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1964              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
# Line 1626  for (;;) Line 1978  for (;;)
1978            {            {
1979            for (fi = min;; fi++)            for (fi = min;; fi++)
1980              {              {
1981              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
1982              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1983              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1984              c = *eptr++;              c = *eptr++;
# Line 1663  for (;;) Line 2015  for (;;)
2015              }              }
2016            for (;;)            for (;;)
2017              {              {
2018              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);
2019              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2020              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2021              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 1682  for (;;) Line 2034  for (;;)
2034              }              }
2035            while (eptr >= pp)            while (eptr >= pp)
2036              {              {
2037              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);
             eptr--;  
2038              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2039                eptr--;
2040              }              }
2041            }            }
2042    
# Line 1753  for (;;) Line 2105  for (;;)
2105          {          {
2106          for (fi = min;; fi++)          for (fi = min;; fi++)
2107            {            {
2108            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
2109            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2110            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2111            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
# Line 1777  for (;;) Line 2129  for (;;)
2129            }            }
2130          for(;;)          for(;;)
2131            {            {
2132            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
2133            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2134            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2135            BACKCHAR(eptr)            if (utf8) BACKCHAR(eptr);
2136            }            }
2137          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2138          }          }
# Line 1836  for (;;) Line 2188  for (;;)
2188    
2189        else        else
2190          {          {
2191          int dc;          unsigned int dc;
2192          GETCHARINC(dc, eptr);          GETCHARINC(dc, eptr);
2193          ecode += length;          ecode += length;
2194    
2195          /* If we have Unicode property support, we can use it to test the other          /* If we have Unicode property support, we can use it to test the other
2196          case of the character, if there is one. The result of ucp_findchar() is          case of the character, if there is one. */
         < 0 if the char isn't found, and othercase is returned as zero if there  
         isn't one. */  
2197    
2198          if (fc != dc)          if (fc != dc)
2199            {            {
2200  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2201            int chartype;            if (dc != UCD_OTHERCASE(fc))
           int othercase;  
           if (ucp_findchar(fc, &chartype, &othercase) < 0 || dc != othercase)  
2202  #endif  #endif
2203              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2204            }            }
# Line 1867  for (;;) Line 2215  for (;;)
2215        }        }
2216      break;      break;
2217    
2218      /* Match a single character repeatedly; different opcodes share code. */      /* Match a single character repeatedly. */
2219    
2220      case OP_EXACT:      case OP_EXACT:
2221      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
2222      ecode += 3;      ecode += 3;
2223      goto REPEATCHAR;      goto REPEATCHAR;
2224    
2225        case OP_POSUPTO:
2226        possessive = TRUE;
2227        /* Fall through */
2228    
2229      case OP_UPTO:      case OP_UPTO:
2230      case OP_MINUPTO:      case OP_MINUPTO:
2231      min = 0;      min = 0;
# Line 1882  for (;;) Line 2234  for (;;)
2234      ecode += 3;      ecode += 3;
2235      goto REPEATCHAR;      goto REPEATCHAR;
2236    
2237        case OP_POSSTAR:
2238        possessive = TRUE;
2239        min = 0;
2240        max = INT_MAX;
2241        ecode++;
2242        goto REPEATCHAR;
2243    
2244        case OP_POSPLUS:
2245        possessive = TRUE;
2246        min = 1;
2247        max = INT_MAX;
2248        ecode++;
2249        goto REPEATCHAR;
2250    
2251        case OP_POSQUERY:
2252        possessive = TRUE;
2253        min = 0;
2254        max = 1;
2255        ecode++;
2256        goto REPEATCHAR;
2257    
2258      case OP_STAR:      case OP_STAR:
2259      case OP_MINSTAR:      case OP_MINSTAR:
2260      case OP_PLUS:      case OP_PLUS:
# Line 1913  for (;;) Line 2286  for (;;)
2286    
2287        if (length > 1)        if (length > 1)
2288          {          {
         int oclength = 0;  
         uschar occhars[8];  
   
2289  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2290          int othercase;          unsigned int othercase;
         int chartype;  
2291          if ((ims & PCRE_CASELESS) != 0 &&          if ((ims & PCRE_CASELESS) != 0 &&
2292               ucp_findchar(fc, &chartype, &othercase) >= 0 &&              (othercase = UCD_OTHERCASE(fc)) != fc)
              othercase > 0)  
2293            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
2294            else oclength = 0;
2295  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2296    
2297          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2298            {            {
2299            if (memcmp(eptr, charptr, length) == 0) eptr += length;            if (memcmp(eptr, charptr, length) == 0) eptr += length;
2300    #ifdef SUPPORT_UCP
2301            /* Need braces because of following else */            /* Need braces because of following else */
2302            else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }            else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }
2303            else            else
# Line 1935  for (;;) Line 2305  for (;;)
2305              if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);              if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);
2306              eptr += oclength;              eptr += oclength;
2307              }              }
2308    #else   /* without SUPPORT_UCP */
2309              else { RRETURN(MATCH_NOMATCH); }
2310    #endif  /* SUPPORT_UCP */
2311            }            }
2312    
2313          if (min == max) continue;          if (min == max) continue;
# Line 1943  for (;;) Line 2316  for (;;)
2316            {            {
2317            for (fi = min;; fi++)            for (fi = min;; fi++)
2318              {              {
2319              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
2320              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2321              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2322              if (memcmp(eptr, charptr, length) == 0) eptr += length;              if (memcmp(eptr, charptr, length) == 0) eptr += length;
2323    #ifdef SUPPORT_UCP
2324              /* Need braces because of following else */              /* Need braces because of following else */
2325              else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }              else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }
2326              else              else
# Line 1954  for (;;) Line 2328  for (;;)
2328                if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);                if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);
2329                eptr += oclength;                eptr += oclength;
2330                }                }
2331    #else   /* without SUPPORT_UCP */
2332                else { RRETURN (MATCH_NOMATCH); }
2333    #endif  /* SUPPORT_UCP */
2334              }              }
2335            /* Control never gets here */            /* Control never gets here */
2336            }            }
2337          else  
2338            else  /* Maximize */
2339            {            {
2340            pp = eptr;            pp = eptr;
2341            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2342              {              {
2343              if (eptr > md->end_subject - length) break;              if (eptr > md->end_subject - length) break;
2344              if (memcmp(eptr, charptr, length) == 0) eptr += length;              if (memcmp(eptr, charptr, length) == 0) eptr += length;
2345    #ifdef SUPPORT_UCP
2346              else if (oclength == 0) break;              else if (oclength == 0) break;
2347              else              else
2348                {                {
2349                if (memcmp(eptr, occhars, oclength) != 0) break;                if (memcmp(eptr, occhars, oclength) != 0) break;
2350                eptr += oclength;                eptr += oclength;
2351                }                }
2352    #else   /* without SUPPORT_UCP */
2353                else break;
2354    #endif  /* SUPPORT_UCP */
2355              }              }
2356            while (eptr >= pp)  
2357              if (possessive) continue;
2358              for(;;)
2359             {             {
2360             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);
2361             if (rrc != MATCH_NOMATCH) RRETURN(rrc);             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2362               if (eptr == pp) RRETURN(MATCH_NOMATCH);
2363    #ifdef SUPPORT_UCP
2364               eptr--;
2365               BACKCHAR(eptr);
2366    #else   /* without SUPPORT_UCP */
2367             eptr -= length;             eptr -= length;
2368    #endif  /* SUPPORT_UCP */
2369             }             }
           RRETURN(MATCH_NOMATCH);  
2370            }            }
2371          /* Control never gets here */          /* Control never gets here */
2372          }          }
# Line 2017  for (;;) Line 2406  for (;;)
2406          {          {
2407          for (fi = min;; fi++)          for (fi = min;; fi++)
2408            {            {
2409            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
2410            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2411            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max || eptr >= md->end_subject ||
2412                fc != md->lcc[*eptr++])                fc != md->lcc[*eptr++])
# Line 2025  for (;;) Line 2414  for (;;)
2414            }            }
2415          /* Control never gets here */          /* Control never gets here */
2416          }          }
2417        else        else  /* Maximize */
2418          {          {
2419          pp = eptr;          pp = eptr;
2420          for (i = min; i < max; i++)          for (i = min; i < max; i++)
# Line 2033  for (;;) Line 2422  for (;;)
2422            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;
2423            eptr++;            eptr++;
2424            }            }
2425            if (possessive) continue;
2426          while (eptr >= pp)          while (eptr >= pp)
2427            {            {
2428            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);
2429            eptr--;            eptr--;
2430            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2431            }            }
# Line 2054  for (;;) Line 2444  for (;;)
2444          {          {
2445          for (fi = min;; fi++)          for (fi = min;; fi++)
2446            {            {
2447            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
2448            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2449            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)
2450              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2451            }            }
2452          /* Control never gets here */          /* Control never gets here */
2453          }          }
2454        else        else  /* Maximize */
2455          {          {
2456          pp = eptr;          pp = eptr;
2457          for (i = min; i < max; i++)          for (i = min; i < max; i++)
# Line 2069  for (;;) Line 2459  for (;;)
2459            if (eptr >= md->end_subject || fc != *eptr) break;            if (eptr >= md->end_subject || fc != *eptr) break;
2460            eptr++;            eptr++;
2461            }            }
2462            if (possessive) continue;
2463          while (eptr >= pp)          while (eptr >= pp)
2464            {            {
2465            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);
2466            eptr--;            eptr--;
2467            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2468            }            }
# Line 2121  for (;;) Line 2512  for (;;)
2512      ecode += 3;      ecode += 3;
2513      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
2514    
2515        case OP_NOTPOSSTAR:
2516        possessive = TRUE;
2517        min = 0;
2518        max = INT_MAX;
2519        ecode++;
2520        goto REPEATNOTCHAR;
2521    
2522        case OP_NOTPOSPLUS:
2523        possessive = TRUE;
2524        min = 1;
2525        max = INT_MAX;
2526        ecode++;
2527        goto REPEATNOTCHAR;
2528    
2529        case OP_NOTPOSQUERY:
2530        possessive = TRUE;
2531        min = 0;
2532        max = 1;
2533        ecode++;
2534        goto REPEATNOTCHAR;
2535    
2536        case OP_NOTPOSUPTO:
2537        possessive = TRUE;
2538        min = 0;
2539        max = GET2(ecode, 1);
2540        ecode += 3;
2541        goto REPEATNOTCHAR;
2542    
2543      case OP_NOTSTAR:      case OP_NOTSTAR:
2544      case OP_NOTMINSTAR:      case OP_NOTMINSTAR:
2545      case OP_NOTPLUS:      case OP_NOTPLUS:
# Line 2160  for (;;) Line 2579  for (;;)
2579        /* UTF-8 mode */        /* UTF-8 mode */
2580        if (utf8)        if (utf8)
2581          {          {
2582          register int d;          register unsigned int d;
2583          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2584            {            {
2585            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
# Line 2185  for (;;) Line 2604  for (;;)
2604          /* UTF-8 mode */          /* UTF-8 mode */
2605          if (utf8)          if (utf8)
2606            {            {
2607            register int d;            register unsigned int d;
2608            for (fi = min;; fi++)            for (fi = min;; fi++)
2609              {              {
2610              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
2611              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2612              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2613              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
# Line 2202  for (;;) Line 2621  for (;;)
2621            {            {
2622            for (fi = min;; fi++)            for (fi = min;; fi++)
2623              {              {
2624              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
2625              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2626              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])
2627                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
# Line 2221  for (;;) Line 2640  for (;;)
2640          /* UTF-8 mode */          /* UTF-8 mode */
2641          if (utf8)          if (utf8)
2642            {            {
2643            register int d;            register unsigned int d;
2644            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2645              {              {
2646              int len = 1;              int len = 1;
# Line 2231  for (;;) Line 2650  for (;;)
2650              if (fc == d) break;              if (fc == d) break;
2651              eptr += len;              eptr += len;
2652              }              }
2653            for(;;)          if (possessive) continue;
2654            for(;;)
2655              {              {
2656              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30);
2657              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2658              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2659              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2248  for (;;) Line 2668  for (;;)
2668              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;
2669              eptr++;              eptr++;
2670              }              }
2671              if (possessive) continue;
2672            while (eptr >= pp)            while (eptr >= pp)
2673              {              {
2674              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31);
2675              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2676              eptr--;              eptr--;
2677              }              }
# Line 2269  for (;;) Line 2690  for (;;)
2690        /* UTF-8 mode */        /* UTF-8 mode */
2691        if (utf8)        if (utf8)
2692          {          {
2693          register int d;          register unsigned int d;
2694          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2695            {            {
2696            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
# Line 2292  for (;;) Line 2713  for (;;)
2713          /* UTF-8 mode */          /* UTF-8 mode */
2714          if (utf8)          if (utf8)
2715            {            {
2716            register int d;            register unsigned int d;
2717            for (fi = min;; fi++)            for (fi = min;; fi++)
2718              {              {
2719              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
2720              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2721              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2722              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fi >= max || eptr >= md->end_subject || fc == d)
# Line 2308  for (;;) Line 2729  for (;;)
2729            {            {
2730            for (fi = min;; fi++)            for (fi = min;; fi++)
2731              {              {
2732              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);
2733              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2734              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)
2735                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
# Line 2327  for (;;) Line 2748  for (;;)
2748          /* UTF-8 mode */          /* UTF-8 mode */
2749          if (utf8)          if (utf8)
2750            {            {
2751            register int d;            register unsigned int d;
2752            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2753              {              {
2754              int len = 1;              int len = 1;
# Line 2336  for (;;) Line 2757  for (;;)
2757              if (fc == d) break;              if (fc == d) break;
2758              eptr += len;              eptr += len;
2759              }              }
2760              if (possessive) continue;
2761            for(;;)            for(;;)
2762              {              {
2763              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34);
2764              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2765              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2766              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2353  for (;;) Line 2775  for (;;)
2775              if (eptr >= md->end_subject || fc == *eptr) break;              if (eptr >= md->end_subject || fc == *eptr) break;
2776              eptr++;              eptr++;
2777              }              }
2778              if (possessive) continue;
2779            while (eptr >= pp)            while (eptr >= pp)
2780              {              {
2781              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35);
2782              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2783              eptr--;              eptr--;
2784              }              }
# Line 2384  for (;;) Line 2807  for (;;)
2807      ecode += 3;      ecode += 3;
2808      goto REPEATTYPE;      goto REPEATTYPE;
2809    
2810        case OP_TYPEPOSSTAR:
2811        possessive = TRUE;
2812        min = 0;
2813        max = INT_MAX;
2814        ecode++;
2815        goto REPEATTYPE;
2816    
2817        case OP_TYPEPOSPLUS:
2818        possessive = TRUE;
2819        min = 1;
2820        max = INT_MAX;
2821        ecode++;
2822        goto REPEATTYPE;
2823    
2824        case OP_TYPEPOSQUERY:
2825        possessive = TRUE;
2826        min = 0;
2827        max = 1;
2828        ecode++;
2829        goto REPEATTYPE;
2830    
2831        case OP_TYPEPOSUPTO:
2832        possessive = TRUE;
2833        min = 0;
2834        max = GET2(ecode, 1);
2835        ecode += 3;
2836        goto REPEATTYPE;
2837    
2838      case OP_TYPESTAR:      case OP_TYPESTAR:
2839      case OP_TYPEMINSTAR:      case OP_TYPEMINSTAR:
2840      case OP_TYPEPLUS:      case OP_TYPEPLUS:
# Line 2408  for (;;) Line 2859  for (;;)
2859        {        {
2860        prop_fail_result = ctype == OP_NOTPROP;        prop_fail_result = ctype == OP_NOTPROP;
2861        prop_type = *ecode++;        prop_type = *ecode++;
2862        if (prop_type >= 128)        prop_value = *ecode++;
         {  
         prop_test_against = prop_type - 128;  
         prop_test_variable = &prop_category;  
         }  
       else  
         {  
         prop_test_against = prop_type;  
         prop_test_variable = &prop_chartype;  
         }  
2863        }        }
2864      else prop_type = -1;      else prop_type = -1;
2865  #endif  #endif
# Line 2434  for (;;) Line 2876  for (;;)
2876      if (min > 0)      if (min > 0)
2877        {        {
2878  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2879        if (prop_type > 0)        if (prop_type >= 0)
2880          {          {
2881          for (i = 1; i <= min; i++)          switch(prop_type)
2882            {            {
2883            GETCHARINC(c, eptr);            case PT_ANY:
2884            prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase);            if (prop_fail_result) RRETURN(MATCH_NOMATCH);
2885            if ((*prop_test_variable == prop_test_against) == prop_fail_result)            for (i = 1; i <= min; i++)
2886              RRETURN(MATCH_NOMATCH);              {
2887                if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2888                GETCHARINCTEST(c, eptr);
2889                }
2890              break;
2891    
2892              case PT_LAMP:
2893              for (i = 1; i <= min; i++)
2894                {
2895                if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2896                GETCHARINCTEST(c, eptr);
2897                prop_chartype = UCD_CHARTYPE(c);
2898                if ((prop_chartype == ucp_Lu ||
2899                     prop_chartype == ucp_Ll ||
2900                     prop_chartype == ucp_Lt) == prop_fail_result)
2901                  RRETURN(MATCH_NOMATCH);
2902                }
2903              break;
2904    
2905              case PT_GC:
2906              for (i = 1; i <= min; i++)
2907                {
2908                if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2909                GETCHARINCTEST(c, eptr);
2910                prop_category = UCD_CATEGORY(c);
2911                if ((prop_category == prop_value) == prop_fail_result)
2912                  RRETURN(MATCH_NOMATCH);
2913                }
2914              break;
2915    
2916              case PT_PC:
2917              for (i = 1; i <= min; i++)
2918                {
2919                if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2920                GETCHARINCTEST(c, eptr);
2921                prop_chartype = UCD_CHARTYPE(c);
2922                if ((prop_chartype == prop_value) == prop_fail_result)
2923                  RRETURN(MATCH_NOMATCH);
2924                }
2925              break;
2926    
2927              case PT_SC:
2928              for (i = 1; i <= min; i++)
2929                {
2930                if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2931                GETCHARINCTEST(c, eptr);
2932                prop_script = UCD_SCRIPT(c);
2933                if ((prop_script == prop_value) == prop_fail_result)
2934                  RRETURN(MATCH_NOMATCH);
2935                }
2936              break;
2937    
2938              default:
2939              RRETURN(PCRE_ERROR_INTERNAL);
2940            }            }
2941          }          }
2942    
# Line 2453  for (;;) Line 2948  for (;;)
2948          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2949            {            {
2950            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
2951            prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase);            prop_category = UCD_CATEGORY(c);
2952            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
2953            while (eptr < md->end_subject)            while (eptr < md->end_subject)
2954              {              {
# Line 2462  for (;;) Line 2957  for (;;)
2957                {                {
2958                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
2959                }                }
2960              prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase);              prop_category = UCD_CATEGORY(c);
2961              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
2962              eptr += len;              eptr += len;
2963              }              }
# Line 2480  for (;;) Line 2975  for (;;)
2975          case OP_ANY:          case OP_ANY:
2976          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2977            {            {
2978            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject || IS_NEWLINE(eptr))
              (*eptr++ == NEWLINE && (ims & PCRE_DOTALL) == 0))  
2979              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2980              eptr++;
2981              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
2982              }
2983            break;
2984    
2985            case OP_ALLANY:
2986            for (i = 1; i <= min; i++)
2987              {
2988              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2989              eptr++;
2990            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
2991            }            }
2992          break;          break;
# Line 2491  for (;;) Line 2995  for (;;)
2995          eptr += min;          eptr += min;
2996          break;          break;
2997    
2998            case OP_ANYNL:
2999            for (i = 1; i <= min; i++)
3000              {
3001              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3002              GETCHARINC(c, eptr);
3003              switch(c)
3004                {
3005                default: RRETURN(MATCH_NOMATCH);
3006                case 0x000d:
3007                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3008                break;
3009    
3010                case 0x000a:
3011                break;
3012    
3013                case 0x000b:
3014                case 0x000c:
3015                case 0x0085:
3016                case 0x2028:
3017                case 0x2029:
3018                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3019                break;
3020                }
3021              }
3022            break;
3023    
3024            case OP_NOT_HSPACE:
3025            for (i = 1; i <= min; i++)
3026              {
3027              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3028              GETCHARINC(c, eptr);
3029              switch(c)
3030                {
3031                default: break;
3032                case 0x09:      /* HT */
3033                case 0x20:      /* SPACE */
3034                case 0xa0:      /* NBSP */
3035                case 0x1680:    /* OGHAM SPACE MARK */
3036                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3037                case 0x2000:    /* EN QUAD */
3038                case 0x2001:    /* EM QUAD */
3039                case 0x2002:    /* EN SPACE */
3040                case 0x2003:    /* EM SPACE */
3041                case 0x2004:    /* THREE-PER-EM SPACE */
3042                case 0x2005:    /* FOUR-PER-EM SPACE */
3043                case 0x2006:    /* SIX-PER-EM SPACE */
3044                case 0x2007:    /* FIGURE SPACE */
3045                case 0x2008:    /* PUNCTUATION SPACE */
3046                case 0x2009:    /* THIN SPACE */
3047                case 0x200A:    /* HAIR SPACE */
3048                case 0x202f:    /* NARROW NO-BREAK SPACE */
3049                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3050                case 0x3000:    /* IDEOGRAPHIC SPACE */
3051                RRETURN(MATCH_NOMATCH);
3052                }
3053              }
3054            break;
3055    
3056            case OP_HSPACE:
3057            for (i = 1; i <= min; i++)
3058              {
3059              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3060              GETCHARINC(c, eptr);
3061              switch(c)
3062                {
3063                default: RRETURN(MATCH_NOMATCH);
3064                case 0x09:      /* HT */
3065                case 0x20:      /* SPACE */
3066                case 0xa0:      /* NBSP */
3067                case 0x1680:    /* OGHAM SPACE MARK */
3068                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3069                case 0x2000:    /* EN QUAD */
3070                case 0x2001:    /* EM QUAD */
3071                case 0x2002:    /* EN SPACE */
3072                case 0x2003:    /* EM SPACE */
3073                case 0x2004:    /* THREE-PER-EM SPACE */
3074                case 0x2005:    /* FOUR-PER-EM SPACE */
3075                case 0x2006:    /* SIX-PER-EM SPACE */
3076                case 0x2007:    /* FIGURE SPACE */
3077                case 0x2008:    /* PUNCTUATION SPACE */
3078                case 0x2009:    /* THIN SPACE */
3079                case 0x200A:    /* HAIR SPACE */
3080                case 0x202f:    /* NARROW NO-BREAK SPACE */
3081                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3082                case 0x3000:    /* IDEOGRAPHIC SPACE */
3083                break;
3084                }
3085              }
3086            break;
3087    
3088            case OP_NOT_VSPACE:
3089            for (i = 1; i <= min; i++)
3090              {
3091              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3092              GETCHARINC(c, eptr);
3093              switch(c)
3094                {
3095                default: break;
3096                case 0x0a:      /* LF */
3097                case 0x0b:      /* VT */
3098                case 0x0c:      /* FF */
3099                case 0x0d:      /* CR */
3100                case 0x85:      /* NEL */
3101                case 0x2028:    /* LINE SEPARATOR */
3102                case 0x2029:    /* PARAGRAPH SEPARATOR */
3103                RRETURN(MATCH_NOMATCH);
3104                }
3105              }
3106            break;
3107    
3108            case OP_VSPACE:
3109            for (i = 1; i <= min; i++)
3110              {
3111              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3112              GETCHARINC(c, eptr);
3113              switch(c)
3114                {
3115                default: RRETURN(MATCH_NOMATCH);
3116                case 0x0a:      /* LF */
3117                case 0x0b:      /* VT */
3118                case 0x0c:      /* FF */
3119                case 0x0d:      /* CR */
3120                case 0x85:      /* NEL */
3121                case 0x2028:    /* LINE SEPARATOR */
3122                case 0x2029:    /* PARAGRAPH SEPARATOR */
3123                break;
3124                }
3125              }
3126            break;
3127    
3128          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3129          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3130            {            {
# Line 2515  for (;;) Line 3149  for (;;)
3149          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3150            {            {
3151            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject ||
3152               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0))               (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0))
3153              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3154            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3155            }            }
3156          break;          break;
3157    
# Line 2535  for (;;) Line 3169  for (;;)
3169          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3170            {            {
3171            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject ||
3172               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0))               (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0))
3173              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3174            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3175            }            }
3176          break;          break;
3177    
# Line 2559  for (;;) Line 3193  for (;;)
3193  #endif     /* SUPPORT_UTF8 */  #endif     /* SUPPORT_UTF8 */
3194    
3195        /* Code for the non-UTF-8 case for minimum matching of operators other        /* Code for the non-UTF-8 case for minimum matching of operators other
3196        than OP_PROP and OP_NOTPROP. */        than OP_PROP and OP_NOTPROP. We can assume that there are the minimum
3197          number of bytes present, as this was tested above. */
3198    
3199        switch(ctype)        switch(ctype)
3200          {          {
3201          case OP_ANY:          case OP_ANY:
3202          if ((ims & PCRE_DOTALL) == 0)          for (i = 1; i <= min; i++)
3203            {            {
3204            for (i = 1; i <= min; i++)            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3205              if (*eptr++ == NEWLINE) RRETURN(MATCH_NOMATCH);            eptr++;
3206            }            }
3207          else eptr += min;          break;
3208    
3209            case OP_ALLANY:
3210            eptr += min;
3211          break;          break;
3212    
3213          case OP_ANYBYTE:          case OP_ANYBYTE:
3214          eptr += min;          eptr += min;
3215          break;          break;
3216    
3217            /* Because of the CRLF case, we can't assume the minimum number of
3218            bytes are present in this case. */
3219    
3220            case OP_ANYNL:
3221            for (i = 1; i <= min; i++)
3222              {
3223              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3224              switch(*eptr++)
3225                {
3226                default: RRETURN(MATCH_NOMATCH);
3227                case 0x000d:
3228                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3229                break;
3230                case 0x000a:
3231                break;
3232    
3233                case 0x000b:
3234                case 0x000c:
3235                case 0x0085:
3236                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3237                break;
3238                }
3239              }
3240            break;
3241    
3242            case OP_NOT_HSPACE:
3243            for (i = 1; i <= min; i++)
3244              {
3245              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3246              switch(*eptr++)
3247                {
3248                default: break;
3249                case 0x09:      /* HT */
3250                case 0x20:      /* SPACE */
3251                case 0xa0:      /* NBSP */
3252                RRETURN(MATCH_NOMATCH);
3253                }
3254              }
3255            break;
3256    
3257            case OP_HSPACE:
3258            for (i = 1; i <= min; i++)
3259              {
3260              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3261              switch(*eptr++)
3262                {
3263                default: RRETURN(MATCH_NOMATCH);
3264                case 0x09:      /* HT */
3265                case 0x20:      /* SPACE */
3266                case 0xa0:      /* NBSP */
3267                break;
3268                }
3269              }
3270            break;
3271    
3272            case OP_NOT_VSPACE:
3273            for (i = 1; i <= min; i++)
3274              {
3275              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3276              switch(*eptr++)
3277                {
3278                default: break;
3279                case 0x0a:      /* LF */
3280                case 0x0b:      /* VT */
3281                case 0x0c:      /* FF */
3282                case 0x0d:      /* CR */
3283                case 0x85:      /* NEL */
3284                RRETURN(MATCH_NOMATCH);
3285                }
3286              }
3287            break;
3288    
3289            case OP_VSPACE:
3290            for (i = 1; i <= min; i++)
3291              {
3292              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3293              switch(*eptr++)
3294                {
3295                default: RRETURN(MATCH_NOMATCH);
3296                case 0x0a:      /* LF */
3297                case 0x0b:      /* VT */
3298                case 0x0c:      /* FF */
3299                case 0x0d:      /* CR */
3300                case 0x85:      /* NEL */
3301                break;
3302                }
3303              }
3304            break;
3305    
3306          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3307          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3308            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
# Line 2624  for (;;) Line 3351  for (;;)
3351      if (minimize)      if (minimize)
3352        {        {
3353  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3354        if (prop_type > 0)        if (prop_type >= 0)
         {  
         for (fi = min;; fi++)  
           {  
           RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);  
           if (rrc != MATCH_NOMATCH) RRETURN(rrc);  
           if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);  
           GETCHARINC(c, eptr);  
           prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase);  
           if ((*prop_test_variable == prop_test_against) == prop_fail_result)  
             RRETURN(MATCH_NOMATCH);  
           }  
         }  
   
       /* Match extended Unicode sequences. We will get here only if the  
       support is in the binary; otherwise a compile-time error occurs. */  
   
       else if (ctype == OP_EXTUNI)  
3355          {          {
3356          for (fi = min;; fi++)          switch(prop_type)
3357            {            {
3358            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            case PT_ANY:
3359            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            for (fi = min;; fi++)
           if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);  
           GETCHARINCTEST(c, eptr);  
           prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase);  
           if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);  
           while (eptr < md->end_subject)  
3360              {              {
3361              int len = 1;              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);
3362              if (!utf8) c = *eptr; else              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3363                if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3364                GETCHARINC(c, eptr);
3365                if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3366                }
3367              /* Control never gets here */
3368    
3369              case PT_LAMP:
3370              for (fi = min;; fi++)
3371                {
3372                RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);
3373                if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3374                if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3375                GETCHARINC(c, eptr);
3376                prop_chartype = UCD_CHARTYPE(c);
3377                if ((prop_chartype == ucp_Lu ||
3378                     prop_chartype == ucp_Ll ||
3379                     prop_chartype == ucp_Lt) == prop_fail_result)
3380                  RRETURN(MATCH_NOMATCH);
3381                }
3382              /* Control never gets here */
3383    
3384              case PT_GC:
3385              for (fi = min;; fi++)
3386                {
3387                RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);
3388                if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3389                if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3390                GETCHARINC(c, eptr);
3391                prop_category = UCD_CATEGORY(c);
3392                if ((prop_category == prop_value) == prop_fail_result)
3393                  RRETURN(MATCH_NOMATCH);
3394                }
3395              /* Control never gets here */
3396    
3397              case PT_PC:
3398              for (fi = min;; fi++)
3399                {
3400                RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);
3401                if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3402                if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3403                GETCHARINC(c, eptr);
3404                prop_chartype = UCD_CHARTYPE(c);
3405                if ((prop_chartype == prop_value) == prop_fail_result)
3406                  RRETURN(MATCH_NOMATCH);
3407                }
3408              /* Control never gets here */
3409    
3410              case PT_SC:
3411              for (fi = min;; fi++)
3412                {
3413                RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);
3414                if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3415                if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3416                GETCHARINC(c, eptr);
3417                prop_script = UCD_SCRIPT(c);
3418                if ((prop_script == prop_value) == prop_fail_result)
3419                  RRETURN(MATCH_NOMATCH);
3420                }
3421              /* Control never gets here */
3422    
3423              default:
3424              RRETURN(PCRE_ERROR_INTERNAL);
3425              }
3426            }
3427    
3428          /* Match extended Unicode sequences. We will get here only if the
3429          support is in the binary; otherwise a compile-time error occurs. */
3430    
3431          else if (ctype == OP_EXTUNI)
3432            {
3433            for (fi = min;; fi++)
3434              {
3435              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);
3436              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3437              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3438              GETCHARINCTEST(c, eptr);
3439              prop_category = UCD_CATEGORY(c);
3440              if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3441              while (eptr < md->end_subject)
3442                {
3443                int len = 1;
3444                if (!utf8) c = *eptr; else
3445                {                {
3446                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3447                }                }
3448              prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase);              prop_category = UCD_CATEGORY(c);
3449              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3450              eptr += len;              eptr += len;
3451              }              }
# Line 2674  for (;;) Line 3461  for (;;)
3461          {          {
3462          for (fi = min;; fi++)          for (fi = min;; fi++)
3463            {            {
3464            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);
3465            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3466            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject ||
3467                   (ctype == OP_ANY && IS_NEWLINE(eptr)))
3468                RRETURN(MATCH_NOMATCH);
3469    
3470            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3471            switch(ctype)            switch(ctype)
3472              {              {
3473              case OP_ANY:              case OP_ANY:        /* This is the non-NL case */
3474              if ((ims & PCRE_DOTALL) == 0 && c == NEWLINE) RRETURN(MATCH_NOMATCH);              case OP_ALLANY:
3475                case OP_ANYBYTE:
3476              break;              break;
3477    
3478              case OP_ANYBYTE:              case OP_ANYNL:
3479                switch(c)
3480                  {
3481                  default: RRETURN(MATCH_NOMATCH);
3482                  case 0x000d:
3483                  if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3484                  break;
3485                  case 0x000a:
3486                  break;
3487    
3488                  case 0x000b:
3489                  case 0x000c:
3490                  case 0x0085:
3491                  case 0x2028:
3492                  case 0x2029:
3493                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3494                  break;
3495                  }
3496                break;
3497    
3498                case OP_NOT_HSPACE:
3499                switch(c)
3500                  {
3501                  default: break;
3502                  case 0x09:      /* HT */
3503                  case 0x20:      /* SPACE */
3504                  case 0xa0:      /* NBSP */
3505                  case 0x1680:    /* OGHAM SPACE MARK */
3506                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3507                  case 0x2000:    /* EN QUAD */
3508                  case 0x2001:    /* EM QUAD */
3509                  case 0x2002:    /* EN SPACE */
3510                  case 0x2003:    /* EM SPACE */
3511                  case 0x2004:    /* THREE-PER-EM SPACE */
3512                  case 0x2005:    /* FOUR-PER-EM SPACE */
3513                  case 0x2006:    /* SIX-PER-EM SPACE */
3514                  case 0x2007:    /* FIGURE SPACE */
3515                  case 0x2008:    /* PUNCTUATION SPACE */
3516                  case 0x2009:    /* THIN SPACE */
3517                  case 0x200A:    /* HAIR SPACE */
3518                  case 0x202f:    /* NARROW NO-BREAK SPACE */
3519                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3520                  case 0x3000:    /* IDEOGRAPHIC SPACE */
3521                  RRETURN(MATCH_NOMATCH);
3522                  }
3523                break;
3524    
3525                case OP_HSPACE:
3526                switch(c)
3527                  {
3528                  default: RRETURN(MATCH_NOMATCH);
3529                  case 0x09:      /* HT */
3530                  case 0x20:      /* SPACE */
3531                  case 0xa0:      /* NBSP */
3532                  case 0x1680:    /* OGHAM SPACE MARK */
3533                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3534                  case 0x2000:    /* EN QUAD */
3535                  case 0x2001:    /* EM QUAD */
3536                  case 0x2002:    /* EN SPACE */
3537                  case 0x2003:    /* EM SPACE */
3538                  case 0x2004:    /* THREE-PER-EM SPACE */
3539                  case 0x2005:    /* FOUR-PER-EM SPACE */
3540                  case 0x2006:    /* SIX-PER-EM SPACE */
3541                  case 0x2007:    /* FIGURE SPACE */
3542                  case 0x2008:    /* PUNCTUATION SPACE */
3543                  case 0x2009:    /* THIN SPACE */
3544                  case 0x200A:    /* HAIR SPACE */
3545                  case 0x202f:    /* NARROW NO-BREAK SPACE */
3546                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3547                  case 0x3000:    /* IDEOGRAPHIC SPACE */
3548                  break;
3549                  }
3550                break;
3551    
3552                case OP_NOT_VSPACE:
3553                switch(c)
3554                  {
3555                  default: break;
3556                  case 0x0a:      /* LF */
3557                  case 0x0b:      /* VT */
3558                  case 0x0c:      /* FF */
3559                  case 0x0d:      /* CR */
3560                  case 0x85:      /* NEL */
3561                  case 0x2028:    /* LINE SEPARATOR */
3562                  case 0x2029:    /* PARAGRAPH SEPARATOR */
3563                  RRETURN(MATCH_NOMATCH);
3564                  }
3565                break;
3566    
3567                case OP_VSPACE:
3568                switch(c)
3569                  {
3570                  default: RRETURN(MATCH_NOMATCH);
3571                  case 0x0a:      /* LF */
3572                  case 0x0b:      /* VT */
3573                  case 0x0c:      /* FF */
3574                  case 0x0d:      /* CR */
3575                  case 0x85:      /* NEL */
3576                  case 0x2028:    /* LINE SEPARATOR */
3577                  case 0x2029:    /* PARAGRAPH SEPARATOR */
3578                  break;
3579                  }
3580              break;              break;
3581    
3582              case OP_NOT_DIGIT:              case OP_NOT_DIGIT:
# Line 2729  for (;;) Line 3620  for (;;)
3620          {          {
3621          for (fi = min;; fi++)          for (fi = min;; fi++)
3622            {            {
3623            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);
3624            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3625            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject ||
3626                   (ctype == OP_ANY && IS_NEWLINE(eptr)))
3627                RRETURN(MATCH_NOMATCH);
3628    
3629            c = *eptr++;            c = *eptr++;
3630            switch(ctype)            switch(ctype)
3631              {              {
3632              case OP_ANY:              case OP_ANY:     /* This is the non-NL case */
3633              if ((ims & PCRE_DOTALL) == 0 && c == NEWLINE) RRETURN(MATCH_NOMATCH);              case OP_ALLANY:
3634                case OP_ANYBYTE:
3635              break;              break;
3636    
3637              case OP_ANYBYTE:              case OP_ANYNL:
3638                switch(c)
3639                  {
3640                  default: RRETURN(MATCH_NOMATCH);
3641                  case 0x000d:
3642                  if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3643                  break;
3644    
3645                  case 0x000a:
3646                  break;
3647    
3648                  case 0x000b:
3649                  case 0x000c:
3650                  case 0x0085:
3651                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3652                  break;
3653                  }
3654                break;
3655    
3656                case OP_NOT_HSPACE:
3657                switch(c)
3658                  {
3659                  default: break;
3660                  case 0x09:      /* HT */
3661                  case 0x20:      /* SPACE */
3662                  case 0xa0:      /* NBSP */
3663                  RRETURN(MATCH_NOMATCH);
3664                  }
3665                break;
3666    
3667                case OP_HSPACE:
3668                switch(c)
3669                  {
3670                  default: RRETURN(MATCH_NOMATCH);
3671                  case 0x09:      /* HT */
3672                  case 0x20:      /* SPACE */
3673                  case 0xa0:      /* NBSP */
3674                  break;
3675                  }
3676                break;
3677    
3678                case OP_NOT_VSPACE:
3679                switch(c)
3680                  {
3681                  default: break;
3682                  case 0x0a:      /* LF */
3683                  case 0x0b:      /* VT */
3684                  case 0x0c:      /* FF */
3685                  case 0x0d:      /* CR */
3686                  case 0x85:      /* NEL */
3687                  RRETURN(MATCH_NOMATCH);
3688                  }
3689                break;
3690    
3691                case OP_VSPACE:
3692                switch(c)
3693                  {
3694                  default: RRETURN(MATCH_NOMATCH);
3695                  case 0x0a:      /* LF */
3696                  case 0x0b:      /* VT */
3697                  case 0x0c:      /* FF */
3698                  case 0x0d:      /* CR */
3699                  case 0x85:      /* NEL */
3700                  break;
3701                  }
3702              break;              break;
3703    
3704              case OP_NOT_DIGIT:              case OP_NOT_DIGIT:
# Line 2774  for (;;) Line 3733  for (;;)
3733        /* Control never gets here */        /* Control never gets here */
3734        }        }
3735    
3736      /* If maximizing it is worth using inline code for speed, doing the type      /* If maximizing, it is worth using inline code for speed, doing the type
3737      test once at the start (i.e. keep it out of the loop). Again, keep the      test once at the start (i.e. keep it out of the loop). Again, keep the
3738      UTF-8 and UCP stuff separate. */      UTF-8 and UCP stuff separate. */
3739    
# Line 2783  for (;;) Line 3742  for (;;)
3742        pp = eptr;  /* Remember where we started */        pp = eptr;  /* Remember where we started */
3743    
3744  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3745        if (prop_type > 0)        if (prop_type >= 0)
3746          {          {
3747          for (i = min; i < max; i++)          switch(prop_type)
3748            {            {
3749            int len = 1;            case PT_ANY:
3750            if (eptr >= md->end_subject) break;            for (i = min; i < max; i++)
3751            GETCHARLEN(c, eptr, len);              {
3752            prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase);              int len = 1;
3753            if ((*prop_test_variable == prop_test_against) == prop_fail_result)              if (eptr >= md->end_subject) break;
3754              break;              GETCHARLEN(c, eptr, len);
3755            eptr+= len;              if (prop_fail_result) break;
3756                eptr+= len;
3757                }
3758              break;
3759    
3760              case PT_LAMP:
3761              for (i = min; i < max; i++)
3762                {
3763                int len = 1;
3764                if (eptr >= md->end_subject) break;
3765                GETCHARLEN(c, eptr, len);
3766                prop_chartype = UCD_CHARTYPE(c);
3767                if ((prop_chartype == ucp_Lu ||
3768                     prop_chartype == ucp_Ll ||
3769                     prop_chartype == ucp_Lt) == prop_fail_result)
3770                  break;
3771                eptr+= len;
3772                }
3773              break;
3774    
3775              case PT_GC:
3776              for (i = min; i < max; i++)
3777                {
3778                int len = 1;
3779                if (eptr >= md->end_subject) break;
3780                GETCHARLEN(c, eptr, len);
3781                prop_category = UCD_CATEGORY(c);
3782                if ((prop_category == prop_value) == prop_fail_result)
3783                  break;
3784                eptr+= len;
3785                }
3786              break;
3787    
3788              case PT_PC:
3789              for (i = min; i < max; i++)
3790                {
3791                int len = 1;
3792                if (eptr >= md->end_subject) break;
3793                GETCHARLEN(c, eptr, len);
3794                prop_chartype = UCD_CHARTYPE(c);
3795                if ((prop_chartype == prop_value) == prop_fail_result)
3796                  break;
3797                eptr+= len;
3798                }
3799              break;
3800    
3801              case PT_SC:
3802              for (i = min; i < max; i++)
3803                {
3804                int len = 1;
3805                if (eptr >= md->end_subject) break;
3806                GETCHARLEN(c, eptr, len);
3807                prop_script = UCD_SCRIPT(c);
3808                if ((prop_script == prop_value) == prop_fail_result)
3809                  break;
3810                eptr+= len;
3811                }
3812              break;
3813            }            }
3814    
3815          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
3816    
3817            if (possessive) continue;
3818          for(;;)          for(;;)
3819            {            {
3820            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44);
3821            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3822            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
3823            BACKCHAR(eptr);            if (utf8) BACKCHAR(eptr);
3824            }            }
3825          }          }
3826    
# Line 2816  for (;;) Line 3833  for (;;)
3833            {            {
3834            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
3835            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3836            prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase);            prop_category = UCD_CATEGORY(c);
3837            if (prop_category == ucp_M) break;            if (prop_category == ucp_M) break;
3838            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3839              {              {
# Line 2825  for (;;) Line 3842  for (;;)
3842                {                {
3843                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3844                }                }
3845              prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase);              prop_category = UCD_CATEGORY(c);
3846              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3847              eptr += len;              eptr += len;
3848              }              }
# Line 2833  for (;;) Line 3850  for (;;)
3850    
3851          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
3852    
3853            if (possessive) continue;
3854          for(;;)          for(;;)
3855            {            {
3856            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45);
3857            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3858            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
3859            for (;;)                        /* Move back over one extended */            for (;;)                        /* Move back over one extended */
3860              {              {
3861              int len = 1;              int len = 1;
             BACKCHAR(eptr);  
3862              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr; else
3863                {                {
3864                  BACKCHAR(eptr);
3865                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3866                }                }
3867              prop_category = ucp_findchar(c, &prop_chartype, &prop_othercase);              prop_category = UCD_CATEGORY(c);
3868              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3869              eptr--;              eptr--;
3870              }              }
# Line 2864  for (;;) Line 3882  for (;;)
3882          switch(ctype)          switch(ctype)
3883            {            {
3884            case OP_ANY:            case OP_ANY:
   
           /* Special code is required for UTF8, but when the maximum is unlimited  
           we don't need it, so we repeat the non-UTF8 code. This is probably  
           worth it, because .* is quite a common idiom. */  
   
3885            if (max < INT_MAX)            if (max < INT_MAX)
3886              {              {
3887              if ((ims & PCRE_DOTALL) == 0)              for (i = min; i < max; i++)
               {  
               for (i = min; i < max; i++)  
                 {  
                 if (eptr >= md->end_subject || *eptr == NEWLINE) break;  
                 eptr++;  
                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
                 }  
               }  
             else  
3888                {                {
3889                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
3890                  {                eptr++;
3891                  eptr++;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
                 }  
3892                }                }
3893              }              }
3894    
# Line 2894  for (;;) Line 3896  for (;;)
3896    
3897            else            else
3898              {              {
3899              if ((ims & PCRE_DOTALL) == 0)              for (i = min; i < max; i++)
3900                {                {
3901                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
3902                  {                eptr++;
3903                  if (eptr >= md->end_subject || *eptr == NEWLINE) break;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
                 eptr++;  
                 }  
               break;  
3904                }                }
3905              else              }
3906              break;
3907    
3908              case OP_ALLANY:
3909              if (max < INT_MAX)
3910                {
3911                for (i = min; i < max; i++)
3912                {                {
3913                c = max - min;                if (eptr >= md->end_subject) break;
3914                if (c > md->end_subject - eptr) c = md->end_subject - eptr;                eptr++;
3915                eptr += c;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3916                }                }
3917              }              }
3918              else eptr = md->end_subject;   /* Unlimited UTF-8 repeat */
3919            break;            break;
3920    
3921            /* The byte case is the same as non-UTF8 */            /* The byte case is the same as non-UTF8 */
3922    
3923            case OP_ANYBYTE:            case OP_ANYBYTE:
3924            c = max - min;            c = max - min;
3925            if (c > md->end_subject - eptr) c = md->end_subject - eptr;            if (c > (unsigned int)(md->end_subject - eptr))
3926                c = md->end_subject - eptr;
3927            eptr += c;            eptr += c;
3928            break;            break;
3929    
3930              case OP_ANYNL:
3931              for (i = min; i < max; i++)
3932                {
3933                int len = 1;
3934                if (eptr >= md->end_subject) break;
3935                GETCHARLEN(c, eptr, len);
3936                if (c == 0x000d)
3937                  {
3938                  if (++eptr >= md->end_subject) break;
3939                  if (*eptr == 0x000a) eptr++;
3940                  }
3941                else
3942                  {
3943                  if (c != 0x000a &&
3944                      (md->bsr_anycrlf ||
3945                       (c != 0x000b && c != 0x000c &&
3946                        c != 0x0085 && c != 0x2028 && c != 0x2029)))
3947                    break;
3948                  eptr += len;
3949                  }
3950                }
3951              break;
3952    
3953              case OP_NOT_HSPACE:
3954              case OP_HSPACE:
3955              for (i = min; i < max; i++)
3956                {
3957                BOOL gotspace;
3958                int len = 1;
3959                if (eptr >= md->end_subject) break;
3960                GETCHARLEN(c, eptr, len);
3961                switch(c)
3962                  {
3963                  default: gotspace = FALSE; break;
3964                  case 0x09:      /* HT */
3965                  case 0x20:      /* SPACE */
3966                  case 0xa0:      /* NBSP */
3967                  case 0x1680:    /* OGHAM SPACE MARK */
3968                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3969                  case 0x2000:    /* EN QUAD */
3970                  case 0x2001:    /* EM QUAD */
3971                  case 0x2002:    /* EN SPACE */
3972                  case 0x2003:    /* EM SPACE */
3973                  case 0x2004:    /* THREE-PER-EM SPACE */
3974                  case 0x2005:    /* FOUR-PER-EM SPACE */
3975                  case 0x2006:    /* SIX-PER-EM SPACE */
3976                  case 0x2007:    /* FIGURE SPACE */
3977                  case 0x2008:    /* PUNCTUATION SPACE */
3978                  case 0x2009:    /* THIN SPACE */
3979                  case 0x200A:    /* HAIR SPACE */
3980                  case 0x202f:    /* NARROW NO-BREAK SPACE */
3981                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3982                  case 0x3000:    /* IDEOGRAPHIC SPACE */
3983                  gotspace = TRUE;
3984                  break;
3985                  }
3986                if (gotspace == (ctype == OP_NOT_HSPACE)) break;
3987                eptr += len;
3988                }
3989              break;
3990    
3991              case OP_NOT_VSPACE:
3992              case OP_VSPACE:
3993              for (i = min; i < max; i++)
3994                {
3995                BOOL gotspace;
3996                int len = 1;
3997                if (eptr >= md->end_subject) break;
3998                GETCHARLEN(c, eptr, len);
3999                switch(c)
4000                  {
4001                  default: gotspace = FALSE; break;
4002                  case 0x0a:      /* LF */
4003                  case 0x0b:      /* VT */
4004                  case 0x0c:      /* FF */
4005                  case 0x0d:      /* CR */
4006                  case 0x85:      /* NEL */
4007                  case 0x2028:    /* LINE SEPARATOR */
4008                  case 0x2029:    /* PARAGRAPH SEPARATOR */
4009                  gotspace = TRUE;
4010                  break;
4011                  }
4012                if (gotspace == (ctype == OP_NOT_VSPACE)) break;
4013                eptr += len;
4014                }
4015              break;
4016    
4017            case OP_NOT_DIGIT:            case OP_NOT_DIGIT:
4018            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4019              {              {
# Line 2992  for (;;) Line 4086  for (;;)
4086    
4087          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
4088    
4089            if (possessive) continue;
4090          for(;;)          for(;;)
4091            {            {
4092            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM46);
4093            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4094            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
4095            BACKCHAR(eptr);            BACKCHAR(eptr);
4096            }            }
4097          }          }
4098        else        else
4099  #endif  #endif  /* SUPPORT_UTF8 */
4100    
4101        /* Not UTF-8 mode */        /* Not UTF-8 mode */
4102          {          {
4103          switch(ctype)          switch(ctype)
4104            {            {
4105            case OP_ANY:            case OP_ANY:
4106            if ((ims & PCRE_DOTALL) == 0)            for (i = min; i < max; i++)
4107              {              {
4108              for (i = min; i < max; i++)              if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
4109                {              eptr++;
               if (eptr >= md->end_subject || *eptr == NEWLINE) break;  
               eptr++;  
               }  
             break;  
4110              }              }
4111            /* For DOTALL case, fall through and treat as \C */            break;
4112    
4113              case OP_ALLANY:
4114            case OP_ANYBYTE:            case OP_ANYBYTE:
4115            c = max - min;            c = max - min;
4116            if (c > md->end_subject - eptr) c = md->end_subject - eptr;            if (c > (unsigned int)(md->end_subject - eptr))
4117                c = md->end_subject - eptr;
4118            eptr += c;            eptr += c;
4119            break;            break;
4120    
4121              case OP_ANYNL:
4122              for (i = min; i < max; i++)
4123                {
4124                if (eptr >= md->end_subject) break;
4125                c = *eptr;
4126                if (c == 0x000d)
4127                  {
4128                  if (++eptr >= md->end_subject) break;
4129                  if (*eptr == 0x000a) eptr++;
4130                  }
4131                else
4132                  {
4133                  if (c != 0x000a &&
4134                      (md->bsr_anycrlf ||
4135                        (c != 0x000b && c != 0x000c && c != 0x0085)))
4136                    break;
4137                  eptr++;
4138                  }
4139                }
4140              break;
4141    
4142              case OP_NOT_HSPACE:
4143              for (i = min; i < max; i++)
4144                {
4145                if (eptr >= md->end_subject) break;
4146                c = *eptr;
4147                if (c == 0x09 || c == 0x20 || c == 0xa0) break;
4148                eptr++;
4149                }
4150              break;
4151    
4152              case OP_HSPACE:
4153              for (i = min; i < max; i++)
4154                {
4155                if (eptr >= md->end_subject) break;
4156                c = *eptr;
4157                if (c != 0x09 && c != 0x20 && c != 0xa0) break;
4158                eptr++;
4159                }
4160              break;
4161    
4162              case OP_NOT_VSPACE:
4163              for (i = min; i < max; i++)
4164                {
4165                if (eptr >= md->end_subject) break;
4166                c = *eptr;
4167                if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85)
4168                  break;
4169                eptr++;
4170                }
4171              break;
4172    
4173              case OP_VSPACE:
4174              for (i = min; i < max; i++)
4175                {
4176                if (eptr >= md->end_subject) break;
4177                c = *eptr;
4178                if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85)
4179                  break;
4180                eptr++;
4181                }
4182              break;
4183    
4184            case OP_NOT_DIGIT:            case OP_NOT_DIGIT:
4185            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4186              {              {
# Line 3085  for (;;) Line 4241  for (;;)
4241    
4242          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
4243    
4244            if (possessive) continue;
4245          while (eptr >= pp)          while (eptr >= pp)
4246            {            {
4247            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM47);
4248            eptr--;            eptr--;
4249            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4250            }            }
# Line 3099  for (;;) Line 4256  for (;;)
4256        }        }
4257      /* Control never gets here */      /* Control never gets here */
4258    
4259      /* There's been some horrible disaster. Since all codes > OP_BRA are      /* There's been some horrible disaster. Arrival here can only mean there is
4260      for capturing brackets, and there shouldn't be any gaps between 0 and      something seriously wrong in the code above or the OP_xxx definitions. */
     OP_BRA, arrival here can only mean there is something seriously wrong  
     in the code above or the OP_xxx definitions. */  
4261    
4262      default:      default:
4263      DPRINTF(("Unknown opcode %d\n", *ecode));      DPRINTF(("Unknown opcode %d\n", *ecode));
4264      RRETURN(PCRE_ERROR_UNKNOWN_NODE);      RRETURN(PCRE_ERROR_UNKNOWN_OPCODE);
4265      }      }
4266    
4267    /* Do not stick any code in here without much thought; it is assumed    /* Do not stick any code in here without much thought; it is assumed
# Line 3115  for (;;) Line 4270  for (;;)
4270    
4271    }             /* End of main loop */    }             /* End of main loop */
4272  /* Control never reaches here */  /* Control never reaches here */
4273    
4274    
4275    /* When compiling to use the heap rather than the stack for recursive calls to
4276    match(), the RRETURN() macro jumps here. The number that is saved in
4277    frame->Xwhere indicates which label we actually want to return to. */
4278    
4279    #ifdef NO_RECURSE
4280    #define LBL(val) case val: goto L_RM##val;
4281    HEAP_RETURN:
4282    switch (frame->Xwhere)
4283      {
4284      LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8)
4285      LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17)
4286      LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33)
4287      LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52)
4288      LBL(53) LBL(54)
4289    #ifdef SUPPORT_UTF8
4290      LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30)
4291      LBL(32) LBL(34) LBL(42) LBL(46)
4292    #ifdef SUPPORT_UCP
4293      LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45)
4294    #endif  /* SUPPORT_UCP */
4295    #endif  /* SUPPORT_UTF8 */
4296      default:
4297      DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere));
4298      return PCRE_ERROR_INTERNAL;
4299      }
4300    #undef LBL
4301    #endif  /* NO_RECURSE */
4302  }  }
4303    
4304    
# Line 3127  Undefine all the macros that were define Line 4311  Undefine all the macros that were define
4311  #ifdef NO_RECURSE  #ifdef NO_RECURSE
4312  #undef eptr  #undef eptr
4313  #undef ecode  #undef ecode
4314    #undef mstart
4315  #undef offset_top  #undef offset_top
4316  #undef ims  #undef ims
4317  #undef eptrb  #undef eptrb
# Line 3144  Undefine all the macros that were define Line 4329  Undefine all the macros that were define
4329    
4330  #undef cur_is_word  #undef cur_is_word
4331  #undef condition  #undef condition
 #undef minimize  
4332  #undef prev_is_word  #undef prev_is_word
4333    
4334  #undef original_ims  #undef original_ims
# Line 3200  Returns:          > 0 => success; value Line 4384  Returns:          > 0 => success; value
4384                   < -1 => some kind of unexpected problem                   < -1 => some kind of unexpected problem
4385  */  */
4386    
4387  EXPORT int  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
4388  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,
4389    const char *subject, int length, int start_offset, int options, int *offsets,    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,
4390    int offsetcount)    int offsetcount)
4391  {  {
4392  int rc, resetcount, ocount;  int rc, resetcount, ocount;
4393  int first_byte = -1;  int first_byte = -1;
4394  int req_byte = -1;  int req_byte = -1;
4395  int req_byte2 = -1;  int req_byte2 = -1;
4396  unsigned long int ims = 0;  int newline;
4397    unsigned long int ims;
4398  BOOL using_temporary_offsets = FALSE;  BOOL using_temporary_offsets = FALSE;
4399  BOOL anchored;  BOOL anchored;
4400  BOOL startline;  BOOL startline;
4401  BOOL firstline;  BOOL firstline;
4402  BOOL first_byte_caseless = FALSE;  BOOL first_byte_caseless = FALSE;
4403  BOOL req_byte_caseless = FALSE;  BOOL req_byte_caseless = FALSE;
4404    BOOL utf8;
4405  match_data match_block;  match_data match_block;
4406    match_data *md = &match_block;
4407  const uschar *tables;  const uschar *tables;
4408  const uschar *start_bits = NULL;  const uschar *start_bits = NULL;
4409  const uschar *start_match = (const uschar *)subject + start_offset;  USPTR start_match = (USPTR)subject + start_offset;
4410  const uschar *end_subject;  USPTR end_subject;
4411  const uschar *req_byte_ptr = start_match - 1;  USPTR req_byte_ptr = start_match - 1;
4412    
4413  pcre_study_data internal_study;  pcre_study_data internal_study;
4414  const pcre_study_data *study;  const pcre_study_data *study;
# Line 3241  if (offsetcount < 0) return PCRE_ERROR_B Line 4428  if (offsetcount < 0) return PCRE_ERROR_B
4428  the default values. */  the default values. */
4429    
4430  study = NULL;  study = NULL;
4431  match_block.match_limit = MATCH_LIMIT;  md->match_limit = MATCH_LIMIT;
4432  match_block.callout_data = NULL;  md->match_limit_recursion = MATCH_LIMIT_RECURSION;
4433    md->callout_data = NULL;
4434    
4435  /* The table pointer is always in native byte order. */  /* The table pointer is always in native byte order. */
4436    
# Line 3254  if (extra_data != NULL) Line 4442  if (extra_data != NULL)
4442    if ((flags & PCRE_EXTRA_STUDY_DATA) != 0)    if ((flags & PCRE_EXTRA_STUDY_DATA) != 0)
4443      study = (const pcre_study_data *)extra_data->study_data;      study = (const pcre_study_data *)extra_data->study_data;
4444