/[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 87 by nigel, Sat Feb 24 21:41:21 2007 UTC revision 402 by ph10, Sat Mar 21 17:26:03 2009 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-2006 University of Cambridge             Copyright (c) 1997-2009 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;  
   USPTR 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 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 186  calls by keeping local variables that ne Line 220  calls by keeping local variables that ne
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    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  /* These versions of the macros use the stack, as normal. There are debugging
251  versions and production versions. */  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    
257  #ifdef DEBUG  #ifdef DEBUG
258  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
259    { \    { \
260    printf("match() called in line %d\n", __LINE__); \    printf("match() called in line %d\n", __LINE__); \
261    rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1); \    rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1); \
262    printf("to line %d\n", __LINE__); \    printf("to line %d\n", __LINE__); \
263    }    }
264  #define RRETURN(ra) \  #define RRETURN(ra) \
# Line 208  versions and production versions. */ Line 267  versions and production versions. */
267    return ra; \    return ra; \
268    }    }
269  #else  #else
270  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
271    rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1)    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  #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->Xrdepth = frame->Xrdepth + 1;\    newframe->Xrdepth = frame->Xrdepth + 1;\
296      newframe->Xprevframe = frame;\    newframe->Xprevframe = frame;\
297      frame = newframe;\    frame = newframe;\
298      DPRINTF(("restarting from line %d\n", __LINE__));\    DPRINTF(("restarting from line %d\n", __LINE__));\
299      goto HEAP_RECURSE;\    goto HEAP_RECURSE;\
300      }\    L_##rw:\
301    else\    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 254  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 271  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    int Xrdepth;    unsigned int Xrdepth;
333    
334    /* Function local variables */    /* Function local variables */
335    
336    const uschar *Xcallpat;    const uschar *Xcallpat;
337    #ifdef SUPPORT_UTF8
338    const uschar *Xcharptr;    const uschar *Xcharptr;
339    #endif
340    const uschar *Xdata;    const uschar *Xdata;
341    const uschar *Xnext;    const uschar *Xnext;
342    const uschar *Xpp;    const uschar *Xpp;
# Line 291  typedef struct heapframe { Line 347  typedef struct heapframe {
347    
348    BOOL Xcur_is_word;    BOOL Xcur_is_word;
349    BOOL Xcondition;    BOOL Xcondition;
   BOOL Xminimize;  
350    BOOL Xprev_is_word;    BOOL Xprev_is_word;
351    
352    unsigned long int Xoriginal_ims;    unsigned long int Xoriginal_ims;
# Line 303  typedef struct heapframe { Line 358  typedef struct heapframe {
358    int Xprop_category;    int Xprop_category;
359    int Xprop_chartype;    int Xprop_chartype;
360    int Xprop_script;    int Xprop_script;
361    int *Xprop_test_variable;    int Xoclength;
362      uschar Xocchars[8];
363  #endif  #endif
364    
365    int Xctype;    int Xctype;
366    int Xfc;    unsigned int Xfc;
367    int Xfi;    int Xfi;
368    int Xlength;    int Xlength;
369    int Xmax;    int Xmax;
# Line 321  typedef struct heapframe { Line 377  typedef struct heapframe {
377    
378    eptrblock Xnewptrb;    eptrblock Xnewptrb;
379    
380    /* Place to pass back result, and where to jump back to */    /* Where to jump back to */
381    
382    int  Xresult;    int Xwhere;
   jmp_buf Xwhere;  
383    
384  } heapframe;  } heapframe;
385    
# Line 340  typedef struct heapframe { Line 395  typedef struct heapframe {
395  *         Match from current position            *  *         Match from current position            *
396  *************************************************/  *************************************************/
397    
398  /* 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  
399  returns a negative (error) response, the outer incarnation must also return the  returns a negative (error) response, the outer incarnation must also return the
400  same response.  same response.
401    
# Line 353  performance. Tests using gcc on a SPARC Line 405  performance. Tests using gcc on a SPARC
405  made performance worse.  made performance worse.
406    
407  Arguments:  Arguments:
408     eptr        pointer in subject     eptr        pointer to current character in subject
409     ecode       position in code     ecode       pointer to current position in compiled code
410       mstart      pointer to the current match start position (can be modified
411                     by encountering \K)
412     offset_top  current top pointer     offset_top  current top pointer
413     md          pointer to "static" info for the match     md          pointer to "static" info for the match
414     ims         current /i, /m, and /s options     ims         current /i, /m, and /s options
# Line 362  Arguments: Line 416  Arguments:
416                   brackets - for testing for empty matches                   brackets - for testing for empty matches
417     flags       can contain     flags       can contain
418                   match_condassert - this is an assertion condition                   match_condassert - this is an assertion condition
419                   match_isgroup - this is the start of a bracketed group                   match_cbegroup - this is the start of an unlimited repeat
420                       group that can match an empty string
421     rdepth      the recursion depth     rdepth      the recursion depth
422    
423  Returns:       MATCH_MATCH if matched            )  these values are >= 0  Returns:       MATCH_MATCH if matched            )  these values are >= 0
# Line 372  Returns:       MATCH_MATCH if matched Line 427  Returns:       MATCH_MATCH if matched
427  */  */
428    
429  static int  static int
430  match(REGISTER USPTR eptr, REGISTER const uschar *ecode,  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, const uschar *mstart,
431    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,
432    int flags, int rdepth)    int flags, unsigned int rdepth)
433  {  {
434  /* 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,
435  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
436  because they are used a lot in loops. */  "register" because they are used a lot in loops. */
437    
438  register int  rrc;    /* Returns from recursive calls */  register int  rrc;         /* Returns from recursive calls */
439  register int  i;      /* Used for loops not involving calls to RMATCH() */  register int  i;           /* Used for loops not involving calls to RMATCH() */
440  register int  c;      /* Character values not kept over RMATCH() calls */  register unsigned int c;   /* Character values not kept over RMATCH() calls */
441  register BOOL utf8;   /* Local copy of UTF-8 flag for speed */  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */
442    
443    BOOL minimize, possessive; /* Quantifier options */
444    
445  /* 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
446  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 398  frame->Xprevframe = NULL;            /* Line 455  frame->Xprevframe = NULL;            /*
455    
456  frame->Xeptr = eptr;  frame->Xeptr = eptr;
457  frame->Xecode = ecode;  frame->Xecode = ecode;
458    frame->Xmstart = mstart;
459  frame->Xoffset_top = offset_top;  frame->Xoffset_top = offset_top;
460  frame->Xims = ims;  frame->Xims = ims;
461  frame->Xeptrb = eptrb;  frame->Xeptrb = eptrb;
# Line 412  HEAP_RECURSE: Line 470  HEAP_RECURSE:
470    
471  #define eptr               frame->Xeptr  #define eptr               frame->Xeptr
472  #define ecode              frame->Xecode  #define ecode              frame->Xecode
473    #define mstart             frame->Xmstart
474  #define offset_top         frame->Xoffset_top  #define offset_top         frame->Xoffset_top
475  #define ims                frame->Xims  #define ims                frame->Xims
476  #define eptrb              frame->Xeptrb  #define eptrb              frame->Xeptrb
# Line 434  HEAP_RECURSE: Line 493  HEAP_RECURSE:
493    
494  #define cur_is_word        frame->Xcur_is_word  #define cur_is_word        frame->Xcur_is_word
495  #define condition          frame->Xcondition  #define condition          frame->Xcondition
 #define minimize           frame->Xminimize  
496  #define prev_is_word       frame->Xprev_is_word  #define prev_is_word       frame->Xprev_is_word
497    
498  #define original_ims       frame->Xoriginal_ims  #define original_ims       frame->Xoriginal_ims
# Line 446  HEAP_RECURSE: Line 504  HEAP_RECURSE:
504  #define prop_category      frame->Xprop_category  #define prop_category      frame->Xprop_category
505  #define prop_chartype      frame->Xprop_chartype  #define prop_chartype      frame->Xprop_chartype
506  #define prop_script        frame->Xprop_script  #define prop_script        frame->Xprop_script
507  #define prop_test_variable frame->Xprop_test_variable  #define oclength           frame->Xoclength
508    #define occhars            frame->Xocchars
509  #endif  #endif
510    
511  #define ctype              frame->Xctype  #define ctype              frame->Xctype
# Line 470  HEAP_RECURSE: Line 529  HEAP_RECURSE:
529  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
530  i, and fc and c, can be the same variables. */  i, and fc and c, can be the same variables. */
531    
532  #else  #else         /* NO_RECURSE not defined */
533  #define fi i  #define fi i
534  #define fc c  #define fc c
535    
# Line 489  recursion_info new_recursive;      /* wi Line 548  recursion_info new_recursive;      /* wi
548                                     /* that do not have to be preserved over  */                                     /* that do not have to be preserved over  */
549  BOOL cur_is_word;                  /* a recursive call to RMATCH().          */  BOOL cur_is_word;                  /* a recursive call to RMATCH().          */
550  BOOL condition;  BOOL condition;
 BOOL minimize;  
551  BOOL prev_is_word;  BOOL prev_is_word;
552    
553  unsigned long int original_ims;  unsigned long int original_ims;
# Line 501  int prop_fail_result; Line 559  int prop_fail_result;
559  int prop_category;  int prop_category;
560  int prop_chartype;  int prop_chartype;
561  int prop_script;  int prop_script;
562  int *prop_test_variable;  int oclength;
563    uschar occhars[8];
564  #endif  #endif
565    
566    int codelink;
567    int condcode;
568  int ctype;  int ctype;
569  int length;  int length;
570  int max;  int max;
# Line 516  int save_offset1, save_offset2, save_off Line 577  int save_offset1, save_offset2, save_off
577  int stacksave[REC_STACK_SAVE_MAX];  int stacksave[REC_STACK_SAVE_MAX];
578    
579  eptrblock newptrb;  eptrblock newptrb;
580  #endif  #endif     /* NO_RECURSE */
581    
582  /* These statements are here to stop the compiler complaining about unitialized  /* These statements are here to stop the compiler complaining about unitialized
583  variables. */  variables. */
# Line 524  variables. */ Line 585  variables. */
585  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
586  prop_value = 0;  prop_value = 0;
587  prop_fail_result = 0;  prop_fail_result = 0;
 prop_test_variable = NULL;  
588  #endif  #endif
589    
590    
591    /* This label is used for tail recursion, which is used in a few cases even
592    when NO_RECURSE is not defined, in order to reduce the amount of stack that is
593    used. Thanks to Ian Taylor for noticing this possibility and sending the
594    original patch. */
595    
596    TAIL_RECURSE:
597    
598  /* OK, now we can get on with the real code of the function. Recursive calls  /* OK, now we can get on with the real code of the function. Recursive calls
599  are specified by the macro RMATCH and RRETURN is used to return. When  are specified by the macro RMATCH and RRETURN is used to return. When
600  NO_RECURSE is *not* defined, these just turn into a recursive call to match()  NO_RECURSE is *not* defined, these just turn into a recursive call to match()
# Line 535  defined). However, RMATCH isn't like a f Line 603  defined). However, RMATCH isn't like a f
603  complicated macro. It has to be used in one particular way. This shouldn't,  complicated macro. It has to be used in one particular way. This shouldn't,
604  however, impact performance when true recursion is being used. */  however, impact performance when true recursion is being used. */
605    
606    #ifdef SUPPORT_UTF8
607    utf8 = md->utf8;       /* Local copy of the flag */
608    #else
609    utf8 = FALSE;
610    #endif
611    
612  /* First check that we haven't called match() too many times, or that we  /* First check that we haven't called match() too many times, or that we
613  haven't exceeded the recursive call limit. */  haven't exceeded the recursive call limit. */
614    
# Line 542  if (md->match_call_count++ >= md->match_ Line 616  if (md->match_call_count++ >= md->match_
616  if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT);  if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT);
617    
618  original_ims = ims;    /* Save for resetting on ')' */  original_ims = ims;    /* Save for resetting on ')' */
 utf8 = md->utf8;       /* Local copy of the flag */  
619    
620  /* 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
621  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
622  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
623  this stack. */  hit the closing ket, in order to break infinite loops that match no characters.
624    When match() is called in other circumstances, don't add to the chain. The
625    match_cbegroup flag must NOT be used with tail recursion, because the memory
626    block that is used is on the stack, so a new one may be required for each
627    match(). */
628    
629  if ((flags & match_isgroup) != 0)  if ((flags & match_cbegroup) != 0)
630    {    {
   newptrb.epb_prev = eptrb;  
631    newptrb.epb_saved_eptr = eptr;    newptrb.epb_saved_eptr = eptr;
632      newptrb.epb_prev = eptrb;
633    eptrb = &newptrb;    eptrb = &newptrb;
634    }    }
635    
636  /* Now start processing the operations. */  /* Now start processing the opcodes. */
637    
638  for (;;)  for (;;)
639    {    {
640      minimize = possessive = FALSE;
641    op = *ecode;    op = *ecode;
642    minimize = FALSE;  
   
643    /* 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
644    matching at least one subject character. */    matching at least one subject character. */
645    
646    if (md->partial &&    if (md->partial &&
647        eptr >= md->end_subject &&        eptr >= md->end_subject &&
648        eptr > md->start_match)        eptr > mstart)
649      md->hitend = TRUE;      md->hitend = TRUE;
650    
651    /* 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)  
652      {      {
653      number = op - OP_BRA;      case OP_FAIL:
654        RRETURN(MATCH_NOMATCH);
     /* For extended extraction brackets (large number), we have to fish out the  
     number from a dummy opcode at the start. */  
655    
656      if (number > EXTRACT_BASIC_MAX)      case OP_PRUNE:
657        number = GET2(ecode, 2+LINK_SIZE);      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
658          ims, eptrb, flags, RM51);
659        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
660        RRETURN(MATCH_PRUNE);
661    
662        case OP_COMMIT:
663        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
664          ims, eptrb, flags, RM52);
665        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
666        RRETURN(MATCH_COMMIT);
667    
668        case OP_SKIP:
669        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
670          ims, eptrb, flags, RM53);
671        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
672        md->start_match_ptr = eptr;   /* Pass back current position */
673        RRETURN(MATCH_SKIP);
674    
675        case OP_THEN:
676        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
677          ims, eptrb, flags, RM54);
678        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
679        RRETURN(MATCH_THEN);
680    
681        /* Handle a capturing bracket. If there is space in the offset vector, save
682        the current subject position in the working slot at the top of the vector.
683        We mustn't change the current values of the data slot, because they may be
684        set from a previous iteration of this group, and be referred to by a
685        reference inside the group.
686    
687        If the bracket fails to match, we need to restore this value and also the
688        values of the final offsets, in case they were set by a previous iteration
689        of the same bracket.
690    
691        If there isn't enough space in the offset vector, treat this as if it were
692        a non-capturing bracket. Don't worry about setting the flag for the error
693        case here; that is handled in the code for KET. */
694    
695        case OP_CBRA:
696        case OP_SCBRA:
697        number = GET2(ecode, 1+LINK_SIZE);
698      offset = number << 1;      offset = number << 1;
699    
700  #ifdef DEBUG  #ifdef DEBUG
701      printf("start bracket %d subject=", number);      printf("start bracket %d\n", number);
702        printf("subject=");
703      pchars(eptr, 16, TRUE, md);      pchars(eptr, 16, TRUE, md);
704      printf("\n");      printf("\n");
705  #endif  #endif
# Line 612  for (;;) Line 714  for (;;)
714        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
715        md->offset_vector[md->offset_end - number] = eptr - md->start_subject;        md->offset_vector[md->offset_end - number] = eptr - md->start_subject;
716    
717          flags = (op == OP_SCBRA)? match_cbegroup : 0;
718        do        do
719          {          {
720          RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
721            match_isgroup);            ims, eptrb, flags, RM1);
722          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
723          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
724          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
725          }          }
# Line 631  for (;;) Line 734  for (;;)
734        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
735        }        }
736    
737      /* Insufficient room for saving captured contents */      /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
738        as a non-capturing bracket. */
739    
740      else op = OP_BRA;      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
741      }      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
742    
743    /* Other types of node can be handled by a switch */      DPRINTF(("insufficient capture room: treat as non-capturing\n"));
744    
745    switch(op)      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
746      {      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
747      case OP_BRA:     /* Non-capturing bracket: optimized */  
748      DPRINTF(("start bracket 0\n"));      /* Non-capturing bracket. Loop for all the alternatives. When we get to the
749      do      final alternative within the brackets, we would return the result of a
750        recursive call to match() whatever happened. We can reduce stack usage by
751        turning this into a tail recursion, except in the case when match_cbegroup
752        is set.*/
753    
754        case OP_BRA:
755        case OP_SBRA:
756        DPRINTF(("start non-capturing bracket\n"));
757        flags = (op >= OP_SBRA)? match_cbegroup : 0;
758        for (;;)
759        {        {
760        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,        if (ecode[GET(ecode, 1)] != OP_ALT)   /* Final alternative */
761          match_isgroup);          {
762        if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (flags == 0)    /* Not a possibly empty group */
763              {
764              ecode += _pcre_OP_lengths[*ecode];
765              DPRINTF(("bracket 0 tail recursion\n"));
766              goto TAIL_RECURSE;
767              }
768    
769            /* Possibly empty group; can't use tail recursion. */
770    
771            RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
772              eptrb, flags, RM48);
773            RRETURN(rrc);
774            }
775    
776          /* For non-final alternatives, continue the loop for a NOMATCH result;
777          otherwise return. */
778    
779          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
780            eptrb, flags, RM2);
781          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
782        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
783        }        }
784      while (*ecode == OP_ALT);      /* Control never reaches here. */
     DPRINTF(("bracket 0 failed\n"));  
     RRETURN(MATCH_NOMATCH);  
785    
786      /* Conditional group: compilation checked that there are no more than      /* Conditional group: compilation checked that there are no more than
787      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
788      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
789      exactly what going to the ket would do. */      exactly what going to the ket would do. As there is only one branch to be
790        obeyed, we can use tail recursion to avoid using another stack frame. */
791    
792      case OP_COND:      case OP_COND:
793      if (ecode[LINK_SIZE+1] == OP_CREF) /* Condition extract or recurse test */      case OP_SCOND:
794        codelink= GET(ecode, 1);
795    
796        /* Because of the way auto-callout works during compile, a callout item is
797        inserted between OP_COND and an assertion condition. */
798    
799        if (ecode[LINK_SIZE+1] == OP_CALLOUT)
800          {
801          if (pcre_callout != NULL)
802            {
803            pcre_callout_block cb;
804            cb.version          = 1;   /* Version 1 of the callout block */
805            cb.callout_number   = ecode[LINK_SIZE+2];
806            cb.offset_vector    = md->offset_vector;
807            cb.subject          = (PCRE_SPTR)md->start_subject;
808            cb.subject_length   = md->end_subject - md->start_subject;
809            cb.start_match      = mstart - md->start_subject;
810            cb.current_position = eptr - md->start_subject;
811            cb.pattern_position = GET(ecode, LINK_SIZE + 3);
812            cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);
813            cb.capture_top      = offset_top/2;
814            cb.capture_last     = md->capture_last;
815            cb.callout_data     = md->callout_data;
816            if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);
817            if (rrc < 0) RRETURN(rrc);
818            }
819          ecode += _pcre_OP_lengths[OP_CALLOUT];
820          }
821    
822        condcode = ecode[LINK_SIZE+1];
823    
824        /* Now see what the actual condition is */
825    
826        if (condcode == OP_RREF)         /* Recursion test */
827          {
828          offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/
829          condition = md->recursive != NULL &&
830            (offset == RREF_ANY || offset == md->recursive->group_num);
831          ecode += condition? 3 : GET(ecode, 1);
832          }
833    
834        else if (condcode == OP_CREF)    /* Group used test */
835        {        {
836        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */
837        condition = (offset == CREF_RECURSE * 2)?        condition = offset < offset_top && md->offset_vector[offset] >= 0;
838          (md->recursive != NULL) :        ecode += condition? 3 : GET(ecode, 1);
839          (offset < offset_top && md->offset_vector[offset] >= 0);        }
840        RMATCH(rrc, eptr, ecode + (condition?  
841          (LINK_SIZE + 4) : (LINK_SIZE + 1 + GET(ecode, 1))),      else if (condcode == OP_DEF)     /* DEFINE - always false */
842          offset_top, md, ims, eptrb, match_isgroup);        {
843        RRETURN(rrc);        condition = FALSE;
844          ecode += GET(ecode, 1);
845        }        }
846    
847      /* The condition is an assertion. Call match() to evaluate it - setting      /* The condition is an assertion. Call match() to evaluate it - setting
848      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
849        assertion. */
850    
851      else      else
852        {        {
853        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,
854            match_condassert | match_isgroup);            match_condassert, RM3);
855        if (rrc == MATCH_MATCH)        if (rrc == MATCH_MATCH)
856          {          {
857          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE+2);          condition = TRUE;
858            ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
859          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
860          }          }
861        else if (rrc != MATCH_NOMATCH)        else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
862          {          {
863          RRETURN(rrc);         /* Need braces because of following else */          RRETURN(rrc);         /* Need braces because of following else */
864          }          }
865        else ecode += GET(ecode, 1);        else
866        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,          {
867          match_isgroup);          condition = FALSE;
868        RRETURN(rrc);          ecode += codelink;
869            }
870        }        }
     /* Control never reaches here */  
871    
872      /* 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,
873      encountered. */      we can use tail recursion to avoid using another stack frame, except when
874        match_cbegroup is required for an unlimited repeat of a possibly empty
875        group. If the second alternative doesn't exist, we can just plough on. */
876    
877      case OP_CREF:      if (condition || *ecode == OP_ALT)
878      case OP_BRANUMBER:        {
879      ecode += 3;        ecode += 1 + LINK_SIZE;
880          if (op == OP_SCOND)        /* Possibly empty group */
881            {
882            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49);
883            RRETURN(rrc);
884            }
885          else                       /* Group must match something */
886            {
887            flags = 0;
888            goto TAIL_RECURSE;
889            }
890          }
891        else                         /* Condition false & no alternative */
892          {
893          ecode += 1 + LINK_SIZE;
894          }
895      break;      break;
896    
     /* End of the pattern. If we are in a recursion, we should restore the  
     offsets appropriately and continue from after the call. */  
897    
898        /* End of the pattern, either real or forced. If we are in a top-level
899        recursion, we should restore the offsets appropriately and continue from
900        after the call. */
901    
902        case OP_ACCEPT:
903      case OP_END:      case OP_END:
904      if (md->recursive != NULL && md->recursive->group_num == 0)      if (md->recursive != NULL && md->recursive->group_num == 0)
905        {        {
# Line 713  for (;;) Line 908  for (;;)
908        md->recursive = rec->prevrec;        md->recursive = rec->prevrec;
909        memmove(md->offset_vector, rec->offset_save,        memmove(md->offset_vector, rec->offset_save,
910          rec->saved_max * sizeof(int));          rec->saved_max * sizeof(int));
911        md->start_match = rec->save_start;        mstart = rec->save_start;
912        ims = original_ims;        ims = original_ims;
913        ecode = rec->after_call;        ecode = rec->after_call;
914        break;        break;
# Line 722  for (;;) Line 917  for (;;)
917      /* 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
918      string - backtracking will then try other alternatives, if any. */      string - backtracking will then try other alternatives, if any. */
919    
920      if (md->notempty && eptr == md->start_match) RRETURN(MATCH_NOMATCH);      if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH);
921      md->end_match_ptr = eptr;          /* Record where we ended */      md->end_match_ptr = eptr;           /* Record where we ended */
922      md->end_offset_top = offset_top;   /* and how many extracts were taken */      md->end_offset_top = offset_top;    /* and how many extracts were taken */
923        md->start_match_ptr = mstart;       /* and the start (\K can modify) */
924      RRETURN(MATCH_MATCH);      RRETURN(MATCH_MATCH);
925    
926      /* Change option settings */      /* Change option settings */
# Line 745  for (;;) Line 941  for (;;)
941      case OP_ASSERTBACK:      case OP_ASSERTBACK:
942      do      do
943        {        {
944        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
945          match_isgroup);          RM4);
946        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH) break;
947        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
948        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
949        }        }
950      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 772  for (;;) Line 968  for (;;)
968      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
969      do      do
970        {        {
971        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
972          match_isgroup);          RM5);
973        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);
974        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
975        ecode += GET(ecode,1);        ecode += GET(ecode,1);
976        }        }
977      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 794  for (;;) Line 990  for (;;)
990  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
991      if (utf8)      if (utf8)
992        {        {
993        c = GET(ecode,1);        i = GET(ecode, 1);
994        for (i = 0; i < c; i++)        while (i-- > 0)
995          {          {
996          eptr--;          eptr--;
997          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
998          BACKCHAR(eptr)          BACKCHAR(eptr);
999          }          }
1000        }        }
1001      else      else
# Line 808  for (;;) Line 1004  for (;;)
1004      /* 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 */
1005    
1006        {        {
1007        eptr -= GET(ecode,1);        eptr -= GET(ecode, 1);
1008        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
1009        }        }
1010    
# Line 830  for (;;) Line 1026  for (;;)
1026        cb.offset_vector    = md->offset_vector;        cb.offset_vector    = md->offset_vector;
1027        cb.subject          = (PCRE_SPTR)md->start_subject;        cb.subject          = (PCRE_SPTR)md->start_subject;
1028        cb.subject_length   = md->end_subject - md->start_subject;        cb.subject_length   = md->end_subject - md->start_subject;
1029        cb.start_match      = md->start_match - md->start_subject;        cb.start_match      = mstart - md->start_subject;
1030        cb.current_position = eptr - md->start_subject;        cb.current_position = eptr - md->start_subject;
1031        cb.pattern_position = GET(ecode, 2);        cb.pattern_position = GET(ecode, 2);
1032        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
# Line 865  for (;;) Line 1061  for (;;)
1061      case OP_RECURSE:      case OP_RECURSE:
1062        {        {
1063        callpat = md->start_code + GET(ecode, 1);        callpat = md->start_code + GET(ecode, 1);
1064        new_recursive.group_num = *callpat - OP_BRA;        new_recursive.group_num = (callpat == md->start_code)? 0 :
1065            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);  
1066    
1067        /* Add to "recursing stack" */        /* Add to "recursing stack" */
1068    
# Line 897  for (;;) Line 1088  for (;;)
1088    
1089        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
1090              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1091        new_recursive.save_start = md->start_match;        new_recursive.save_start = mstart;
1092        md->start_match = eptr;        mstart = eptr;
1093    
1094        /* 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
1095        restore the offset and recursion data. */        restore the offset and recursion data. */
1096    
1097        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));
1098          flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;
1099        do        do
1100          {          {
1101          RMATCH(rrc, eptr, callpat + 1 + LINK_SIZE, offset_top, md, ims,          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
1102              eptrb, match_isgroup);            md, ims, eptrb, flags, RM6);
1103          if (rrc == MATCH_MATCH)          if (rrc == MATCH_MATCH)
1104            {            {
1105            DPRINTF(("Recursion matched\n"));            DPRINTF(("Recursion matched\n"));
# Line 916  for (;;) Line 1108  for (;;)
1108              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1109            RRETURN(MATCH_MATCH);            RRETURN(MATCH_MATCH);
1110            }            }
1111          else if (rrc != MATCH_NOMATCH)          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1112            {            {
1113            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1114              if (new_recursive.offset_save != stacksave)
1115                (pcre_free)(new_recursive.offset_save);
1116            RRETURN(rrc);            RRETURN(rrc);
1117            }            }
1118    
# Line 945  for (;;) Line 1139  for (;;)
1139      the end of a normal bracket, leaving the subject pointer. */      the end of a normal bracket, leaving the subject pointer. */
1140    
1141      case OP_ONCE:      case OP_ONCE:
1142        {      prev = ecode;
1143        prev = ecode;      saved_eptr = eptr;
       saved_eptr = eptr;  
1144    
1145        do      do
1146          {        {
1147          RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);
1148            eptrb, match_isgroup);        if (rrc == MATCH_MATCH) break;
1149          if (rrc == MATCH_MATCH) break;        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1150          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        ecode += GET(ecode,1);
1151          ecode += GET(ecode,1);        }
1152          }      while (*ecode == OP_ALT);
       while (*ecode == OP_ALT);  
1153    
1154        /* If hit the end of the group (which could be repeated), fail */      /* If hit the end of the group (which could be repeated), fail */
1155    
1156        if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);      if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);
1157    
1158        /* Continue as from after the assertion, updating the offsets high water      /* Continue as from after the assertion, updating the offsets high water
1159        mark, since extracts may have been taken. */      mark, since extracts may have been taken. */
1160    
1161        do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode, 1); while (*ecode == OP_ALT);
1162    
1163        offset_top = md->end_offset_top;      offset_top = md->end_offset_top;
1164        eptr = md->end_match_ptr;      eptr = md->end_match_ptr;
1165    
1166        /* For a non-repeating ket, just continue at this level. This also      /* For a non-repeating ket, just continue at this level. This also
1167        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.
1168        This is the forcible breaking of infinite loops as implemented in Perl      This is the forcible breaking of infinite loops as implemented in Perl
1169        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
1170        course of events. */      course of events. */
1171    
1172        if (*ecode == OP_KET || eptr == saved_eptr)      if (*ecode == OP_KET || eptr == saved_eptr)
1173          {        {
1174          ecode += 1+LINK_SIZE;        ecode += 1+LINK_SIZE;
1175          break;        break;
1176          }        }
1177    
1178        /* 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
1179        preceding bracket, in the appropriate order. We need to reset any options      preceding bracket, in the appropriate order. The second "call" of match()
1180        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
1181        opcode. */      any options that changed within the bracket before re-running it, so
1182        check the next opcode. */
1183    
1184        if (ecode[1+LINK_SIZE] == OP_OPT)      if (ecode[1+LINK_SIZE] == OP_OPT)
1185          {        {
1186          ims = (ims & ~PCRE_IMS) | ecode[4];        ims = (ims & ~PCRE_IMS) | ecode[4];
1187          DPRINTF(("ims set to %02lx at group repeat\n", ims));        DPRINTF(("ims set to %02lx at group repeat\n", ims));
1188          }        }
1189    
1190        if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1191          {        {
1192          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);
1193          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1194          RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);        ecode = prev;
1195          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        flags = 0;
1196          }        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);  
         }  
1197        }        }
1198      RRETURN(MATCH_NOMATCH);      else  /* OP_KETRMAX */
1199          {
1200          RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);
1201          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1202          ecode += 1 + LINK_SIZE;
1203          flags = 0;
1204          goto TAIL_RECURSE;
1205          }
1206        /* Control never gets here */
1207    
1208      /* 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
1209      bracketed group and go to there. */      bracketed group and go to there. */
# Line 1018  for (;;) Line 1212  for (;;)
1212      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1213      break;      break;
1214    
1215      /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating      /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group,
1216      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
1217      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
1218      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
1219      preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1220    
1221      case OP_BRAZERO:      case OP_BRAZERO:
1222        {        {
1223        next = ecode+1;        next = ecode+1;
1224        RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10);
1225        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1226        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next,1); while (*next == OP_ALT);
1227        ecode = next + 1+LINK_SIZE;        ecode = next + 1 + LINK_SIZE;
1228        }        }
1229      break;      break;
1230    
1231      case OP_BRAMINZERO:      case OP_BRAMINZERO:
1232        {        {
1233        next = ecode+1;        next = ecode+1;
1234        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next, 1); while (*next == OP_ALT);
1235        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);  
1236        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1237        ecode++;        ecode++;
1238        }        }
1239      break;      break;
1240    
1241      /* End of a group, repeated or non-repeating. If we are at the end of      case OP_SKIPZERO:
1242      an assertion "group", stop matching and return MATCH_MATCH, but record the        {
1243      current high water mark for use by positive assertions. Do this also        next = ecode+1;
1244      for the "once" (not-backup up) groups. */        do next += GET(next,1); while (*next == OP_ALT);
1245          ecode = next + 1 + LINK_SIZE;
1246          }
1247        break;
1248    
1249        /* End of a group, repeated or non-repeating. */
1250    
1251      case OP_KET:      case OP_KET:
1252      case OP_KETRMIN:      case OP_KETRMIN:
1253      case OP_KETRMAX:      case OP_KETRMAX:
1254        {      prev = ecode - GET(ecode, 1);
       prev = ecode - GET(ecode, 1);  
       saved_eptr = eptrb->epb_saved_eptr;  
1255    
1256        /* Back up the stack of bracket start pointers. */      /* If this was a group that remembered the subject start, in order to break
1257        infinite repeats of empty string matches, retrieve the subject start from
1258        the chain. Otherwise, set it NULL. */
1259    
1260        eptrb = eptrb->epb_prev;      if (*prev >= OP_SBRA)
1261          {
1262        if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||        saved_eptr = eptrb->epb_saved_eptr;   /* Value at start of group */
1263            *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||        eptrb = eptrb->epb_prev;              /* Backup to previous group */
1264            *prev == OP_ONCE)        }
1265          {      else saved_eptr = NULL;
         md->end_match_ptr = eptr;      /* For ONCE */  
         md->end_offset_top = offset_top;  
         RRETURN(MATCH_MATCH);  
         }  
1266    
1267        /* 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
1268        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
1269        extraction by setting the offsets and bumping the high water mark. */      assertions. Do this also for the "once" (atomic) groups. */
1270    
1271        if (*prev != OP_COND)      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||
1272          {          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||
1273          number = *prev - OP_BRA;          *prev == OP_ONCE)
1274          {
1275          md->end_match_ptr = eptr;      /* For ONCE */
1276          md->end_offset_top = offset_top;
1277          RRETURN(MATCH_MATCH);
1278          }
1279    
1280          /* 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
1281          the number from a dummy opcode at the start. */      and if necessary complete handling an extraction by setting the offsets and
1282        bumping the high water mark. Note that whole-pattern recursion is coded as
1283        a recurse into group 0, so it won't be picked up here. Instead, we catch it
1284        when the OP_END is reached. Other recursion is handled here. */
1285    
1286          if (number > EXTRACT_BASIC_MAX) number = GET2(prev, 2+LINK_SIZE);      if (*prev == OP_CBRA || *prev == OP_SCBRA)
1287          offset = number << 1;        {
1288          number = GET2(prev, 1+LINK_SIZE);
1289          offset = number << 1;
1290    
1291  #ifdef DEBUG  #ifdef DEBUG
1292          printf("end bracket %d", number);        printf("end bracket %d", number);
1293          printf("\n");        printf("\n");
1294  #endif  #endif
1295    
1296          /* Test for a numbered group. This includes groups called as a result        md->capture_last = number;
1297          of recursion. Note that whole-pattern recursion is coded as a recurse        if (offset >= md->offset_max) md->offset_overflow = TRUE; else
1298          into group 0, so it won't be picked up here. Instead, we catch it when          {
1299          the OP_END is reached. */          md->offset_vector[offset] =
1300              md->offset_vector[md->offset_end - number];
1301          if (number > 0)          md->offset_vector[offset+1] = eptr - md->start_subject;
1302            {          if (offset_top <= offset) offset_top = offset + 2;
1303            md->capture_last = number;          }
           if (offset >= md->offset_max) md->offset_overflow = TRUE; else  
             {  
             md->offset_vector[offset] =  
               md->offset_vector[md->offset_end - number];  
             md->offset_vector[offset+1] = eptr - md->start_subject;  
             if (offset_top <= offset) offset_top = offset + 2;  
             }  
1304    
1305            /* Handle a recursively called group. Restore the offsets        /* Handle a recursively called group. Restore the offsets
1306            appropriately and continue from after the call. */        appropriately and continue from after the call. */
1307    
1308            if (md->recursive != NULL && md->recursive->group_num == number)        if (md->recursive != NULL && md->recursive->group_num == number)
1309              {          {
1310              recursion_info *rec = md->recursive;          recursion_info *rec = md->recursive;
1311              DPRINTF(("Recursion (%d) succeeded - continuing\n", number));          DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
1312              md->recursive = rec->prevrec;          md->recursive = rec->prevrec;
1313              md->start_match = rec->save_start;          mstart = rec->save_start;
1314              memcpy(md->offset_vector, rec->offset_save,          memcpy(md->offset_vector, rec->offset_save,
1315                rec->saved_max * sizeof(int));            rec->saved_max * sizeof(int));
1316              ecode = rec->after_call;          ecode = rec->after_call;
1317              ims = original_ims;          ims = original_ims;
1318              break;          break;
             }  
           }  
1319          }          }
1320          }
1321    
1322        /* 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
1323        the group. */      flags, in case they got changed during the group. */
1324    
1325        ims = original_ims;      ims = original_ims;
1326        DPRINTF(("ims reset to %02lx\n", ims));      DPRINTF(("ims reset to %02lx\n", ims));
1327    
1328        /* For a non-repeating ket, just continue at this level. This also      /* For a non-repeating ket, just continue at this level. This also
1329        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.
1330        This is the forcible breaking of infinite loops as implemented in Perl      This is the forcible breaking of infinite loops as implemented in Perl
1331        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
1332        course of events. */      course of events. */
1333    
1334        if (*ecode == OP_KET || eptr == saved_eptr)      if (*ecode == OP_KET || eptr == saved_eptr)
1335          {        {
1336          ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1337          break;        break;
1338          }        }
1339    
1340        /* 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
1341        preceding bracket, in the appropriate order. */      preceding bracket, in the appropriate order. In the second case, we can use
1342        tail recursion to avoid using another stack frame, unless we have an
1343        unlimited repeat of a group that can match an empty string. */
1344    
1345        if (*ecode == OP_KETRMIN)      flags = (*prev >= OP_SBRA)? match_cbegroup : 0;
1346          {  
1347          RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);      if (*ecode == OP_KETRMIN)
1348          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        {
1349          RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12);
1350          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1351          }        if (flags != 0)    /* Could match an empty string */
       else  /* OP_KETRMAX */  
1352          {          {
1353          RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);          RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);
1354          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);  
1355          }          }
1356          ecode = prev;
1357          goto TAIL_RECURSE;
1358        }        }
1359        else  /* OP_KETRMAX */
1360      RRETURN(MATCH_NOMATCH);        {
1361          RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);
1362          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1363          ecode += 1 + LINK_SIZE;
1364          flags = 0;
1365          goto TAIL_RECURSE;
1366          }
1367        /* Control never gets here */
1368    
1369      /* Start of subject unless notbol, or after internal newline if multiline */      /* Start of subject unless notbol, or after internal newline if multiline */
1370    
# Line 1168  for (;;) Line 1372  for (;;)
1372      if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);      if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);
1373      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1374        {        {
1375        if (eptr != md->start_subject && eptr[-1] != NEWLINE)        if (eptr != md->start_subject &&
1376              (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
1377          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
1378        ecode++;        ecode++;
1379        break;        break;
# Line 1189  for (;;) Line 1394  for (;;)
1394      ecode++;      ecode++;
1395      break;      break;
1396    
1397        /* Reset the start of match point */
1398    
1399        case OP_SET_SOM:
1400        mstart = eptr;
1401        ecode++;
1402        break;
1403    
1404      /* Assert before internal newline if multiline, or before a terminating      /* Assert before internal newline if multiline, or before a terminating
1405      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. */
1406    
# Line 1196  for (;;) Line 1408  for (;;)
1408      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1409        {        {
1410        if (eptr < md->end_subject)        if (eptr < md->end_subject)
1411          { if (*eptr != NEWLINE) RRETURN(MATCH_NOMATCH); }          { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); }
1412        else        else
1413          { if (md->noteol) RRETURN(MATCH_NOMATCH); }          { if (md->noteol) RRETURN(MATCH_NOMATCH); }
1414        ecode++;        ecode++;
# Line 1207  for (;;) Line 1419  for (;;)
1419        if (md->noteol) RRETURN(MATCH_NOMATCH);        if (md->noteol) RRETURN(MATCH_NOMATCH);
1420        if (!md->endonly)        if (!md->endonly)
1421          {          {
1422          if (eptr < md->end_subject - 1 ||          if (eptr != md->end_subject &&
1423             (eptr == md->end_subject - 1 && *eptr != NEWLINE))              (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1424            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1425          ecode++;          ecode++;
1426          break;          break;
1427          }          }
1428        }        }
1429      /* ... else fall through */      /* ... else fall through for endonly */
1430    
1431      /* End of subject assertion (\z) */      /* End of subject assertion (\z) */
1432    
# Line 1226  for (;;) Line 1438  for (;;)
1438      /* End of subject or ending \n assertion (\Z) */      /* End of subject or ending \n assertion (\Z) */
1439    
1440      case OP_EODN:      case OP_EODN:
1441      if (eptr < md->end_subject - 1 ||      if (eptr != md->end_subject &&
1442         (eptr == md->end_subject - 1 && *eptr != NEWLINE)) RRETURN(MATCH_NOMATCH);          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1443          RRETURN(MATCH_NOMATCH);
1444      ecode++;      ecode++;
1445      break;      break;
1446    
# Line 1280  for (;;) Line 1493  for (;;)
1493      /* Match a single character type; inline for speed */      /* Match a single character type; inline for speed */
1494    
1495      case OP_ANY:      case OP_ANY:
1496      if ((ims & PCRE_DOTALL) == 0 && eptr < md->end_subject && *eptr == NEWLINE)      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
1497        RRETURN(MATCH_NOMATCH);      /* Fall through */
1498    
1499        case OP_ALLANY:
1500      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);
1501  #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  
1502      ecode++;      ecode++;
1503      break;      break;
1504    
# Line 1376  for (;;) Line 1588  for (;;)
1588      ecode++;      ecode++;
1589      break;      break;
1590    
1591        case OP_ANYNL:
1592        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1593        GETCHARINCTEST(c, eptr);
1594        switch(c)
1595          {
1596          default: RRETURN(MATCH_NOMATCH);
1597          case 0x000d:
1598          if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
1599          break;
1600    
1601          case 0x000a:
1602          break;
1603    
1604          case 0x000b:
1605          case 0x000c:
1606          case 0x0085:
1607          case 0x2028:
1608          case 0x2029:
1609          if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
1610          break;
1611          }
1612        ecode++;
1613        break;
1614    
1615        case OP_NOT_HSPACE:
1616        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1617        GETCHARINCTEST(c, eptr);
1618        switch(c)
1619          {
1620          default: break;
1621          case 0x09:      /* HT */
1622          case 0x20:      /* SPACE */
1623          case 0xa0:      /* NBSP */
1624          case 0x1680:    /* OGHAM SPACE MARK */
1625          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1626          case 0x2000:    /* EN QUAD */
1627          case 0x2001:    /* EM QUAD */
1628          case 0x2002:    /* EN SPACE */
1629          case 0x2003:    /* EM SPACE */
1630          case 0x2004:    /* THREE-PER-EM SPACE */
1631          case 0x2005:    /* FOUR-PER-EM SPACE */
1632          case 0x2006:    /* SIX-PER-EM SPACE */
1633          case 0x2007:    /* FIGURE SPACE */
1634          case 0x2008:    /* PUNCTUATION SPACE */
1635          case 0x2009:    /* THIN SPACE */
1636          case 0x200A:    /* HAIR SPACE */
1637          case 0x202f:    /* NARROW NO-BREAK SPACE */
1638          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1639          case 0x3000:    /* IDEOGRAPHIC SPACE */
1640          RRETURN(MATCH_NOMATCH);
1641          }
1642        ecode++;
1643        break;
1644    
1645        case OP_HSPACE:
1646        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1647        GETCHARINCTEST(c, eptr);
1648        switch(c)
1649          {
1650          default: RRETURN(MATCH_NOMATCH);
1651          case 0x09:      /* HT */
1652          case 0x20:      /* SPACE */
1653          case 0xa0:      /* NBSP */
1654          case 0x1680:    /* OGHAM SPACE MARK */
1655          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1656          case 0x2000:    /* EN QUAD */
1657          case 0x2001:    /* EM QUAD */
1658          case 0x2002:    /* EN SPACE */
1659          case 0x2003:    /* EM SPACE */
1660          case 0x2004:    /* THREE-PER-EM SPACE */
1661          case 0x2005:    /* FOUR-PER-EM SPACE */
1662          case 0x2006:    /* SIX-PER-EM SPACE */
1663          case 0x2007:    /* FIGURE SPACE */
1664          case 0x2008:    /* PUNCTUATION SPACE */
1665          case 0x2009:    /* THIN SPACE */
1666          case 0x200A:    /* HAIR SPACE */
1667          case 0x202f:    /* NARROW NO-BREAK SPACE */
1668          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1669          case 0x3000:    /* IDEOGRAPHIC SPACE */
1670          break;
1671          }
1672        ecode++;
1673        break;
1674    
1675        case OP_NOT_VSPACE:
1676        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1677        GETCHARINCTEST(c, eptr);
1678        switch(c)
1679          {
1680          default: break;
1681          case 0x0a:      /* LF */
1682          case 0x0b:      /* VT */
1683          case 0x0c:      /* FF */
1684          case 0x0d:      /* CR */
1685          case 0x85:      /* NEL */
1686          case 0x2028:    /* LINE SEPARATOR */
1687          case 0x2029:    /* PARAGRAPH SEPARATOR */
1688          RRETURN(MATCH_NOMATCH);
1689          }
1690        ecode++;
1691        break;
1692    
1693        case OP_VSPACE:
1694        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1695        GETCHARINCTEST(c, eptr);
1696        switch(c)
1697          {
1698          default: RRETURN(MATCH_NOMATCH);
1699          case 0x0a:      /* LF */
1700          case 0x0b:      /* VT */
1701          case 0x0c:      /* FF */
1702          case 0x0d:      /* CR */
1703          case 0x85:      /* NEL */
1704          case 0x2028:    /* LINE SEPARATOR */
1705          case 0x2029:    /* PARAGRAPH SEPARATOR */
1706          break;
1707          }
1708        ecode++;
1709        break;
1710    
1711  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
1712      /* Check the next character by Unicode property. We will get here only      /* Check the next character by Unicode property. We will get here only
1713      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 1385  for (;;) Line 1717  for (;;)
1717      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1718      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1719        {        {
1720        int chartype, script;        const ucd_record *prop = GET_UCD(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1721    
1722        switch(ecode[1])        switch(ecode[1])
1723          {          {
# Line 1395  for (;;) Line 1726  for (;;)
1726          break;          break;
1727    
1728          case PT_LAMP:          case PT_LAMP:
1729          if ((chartype == ucp_Lu ||          if ((prop->chartype == ucp_Lu ||
1730               chartype == ucp_Ll ||               prop->chartype == ucp_Ll ||
1731               chartype == ucp_Lt) == (op == OP_NOTPROP))               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
1732            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1733           break;           break;
1734    
1735          case PT_GC:          case PT_GC:
1736          if ((ecode[2] != category) == (op == OP_PROP))          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
1737            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1738          break;          break;
1739    
1740          case PT_PC:          case PT_PC:
1741          if ((ecode[2] != chartype) == (op == OP_PROP))          if ((ecode[2] != prop->chartype) == (op == OP_PROP))
1742            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1743          break;          break;
1744    
1745          case PT_SC:          case PT_SC:
1746          if ((ecode[2] != script) == (op == OP_PROP))          if ((ecode[2] != prop->script) == (op == OP_PROP))
1747            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1748          break;          break;
1749    
1750          default:          default:
1751          RRETURN(PCRE_ERROR_INTERNAL);          RRETURN(PCRE_ERROR_INTERNAL);
         break;  
1752          }          }
1753    
1754        ecode += 3;        ecode += 3;
# Line 1432  for (;;) Line 1762  for (;;)
1762      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1763      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1764        {        {
1765        int chartype, script;        int category = UCD_CATEGORY(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1766        if (category == ucp_M) RRETURN(MATCH_NOMATCH);        if (category == ucp_M) RRETURN(MATCH_NOMATCH);
1767        while (eptr < md->end_subject)        while (eptr < md->end_subject)
1768          {          {
# Line 1442  for (;;) Line 1771  for (;;)
1771            {            {
1772            GETCHARLEN(c, eptr, len);            GETCHARLEN(c, eptr, len);
1773            }            }
1774          category = _pcre_ucp_findprop(c, &chartype, &script);          category = UCD_CATEGORY(c);
1775          if (category != ucp_M) break;          if (category != ucp_M) break;
1776          eptr += len;          eptr += len;
1777          }          }
# Line 1463  for (;;) Line 1792  for (;;)
1792      case OP_REF:      case OP_REF:
1793        {        {
1794        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
1795        ecode += 3;                                 /* Advance past item */        ecode += 3;
1796    
1797          /* If the reference is unset, there are two possibilities:
1798    
1799        /* If the reference is unset, set the length to be longer than the amount        (a) In the default, Perl-compatible state, set the length to be longer
1800        of subject left; this ensures that every attempt at a match fails. We        than the amount of subject left; this ensures that every attempt at a
1801        can't just fail here, because of the possibility of quantifiers with zero        match fails. We can't just fail here, because of the possibility of
1802        minima. */        quantifiers with zero minima.
1803    
1804        length = (offset >= offset_top || md->offset_vector[offset] < 0)?        (b) If the JavaScript compatibility flag is set, set the length to zero
1805          md->end_subject - eptr + 1 :        so that the back reference matches an empty string.
1806          md->offset_vector[offset+1] - md->offset_vector[offset];  
1807          Otherwise, set the length to the length of what was matched by the
1808          referenced subpattern. */
1809    
1810          if (offset >= offset_top || md->offset_vector[offset] < 0)
1811            length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;
1812          else
1813            length = md->offset_vector[offset+1] - md->offset_vector[offset];
1814    
1815        /* Set up for repetition, or handle the non-repeated case */        /* Set up for repetition, or handle the non-repeated case */
1816    
# Line 1532  for (;;) Line 1870  for (;;)
1870          {          {
1871          for (fi = min;; fi++)          for (fi = min;; fi++)
1872            {            {
1873            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
1874            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1875            if (fi >= max || !match_ref(offset, eptr, length, md, ims))            if (fi >= max || !match_ref(offset, eptr, length, md, ims))
1876              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
# Line 1553  for (;;) Line 1891  for (;;)
1891            }            }
1892          while (eptr >= pp)          while (eptr >= pp)
1893            {            {
1894            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);
1895            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1896            eptr -= length;            eptr -= length;
1897            }            }
# Line 1658  for (;;) Line 1996  for (;;)
1996            {            {
1997            for (fi = min;; fi++)            for (fi = min;; fi++)
1998              {              {
1999              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
2000              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2001              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2002              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
# Line 1678  for (;;) Line 2016  for (;;)
2016            {            {
2017            for (fi = min;; fi++)            for (fi = min;; fi++)
2018              {              {
2019              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
2020              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2021              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2022              c = *eptr++;              c = *eptr++;
# Line 1715  for (;;) Line 2053  for (;;)
2053              }              }
2054            for (;;)            for (;;)
2055              {              {
2056              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);
2057              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2058              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2059              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 1734  for (;;) Line 2072  for (;;)
2072              }              }
2073            while (eptr >= pp)            while (eptr >= pp)
2074              {              {
2075              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);
2076              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2077              eptr--;              eptr--;
2078              }              }
# Line 1747  for (;;) Line 2085  for (;;)
2085    
2086    
2087      /* Match an extended character class. This opcode is encountered only      /* Match an extended character class. This opcode is encountered only
2088      in UTF-8 mode, because that's the only time it is compiled. */      when UTF-8 mode mode is supported. Nevertheless, we may not be in UTF-8
2089        mode, because Unicode properties are supported in non-UTF-8 mode. */
2090    
2091  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2092      case OP_XCLASS:      case OP_XCLASS:
# Line 1789  for (;;) Line 2128  for (;;)
2128        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2129          {          {
2130          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2131          GETCHARINC(c, eptr);          GETCHARINCTEST(c, eptr);
2132          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2133          }          }
2134    
# Line 1805  for (;;) Line 2144  for (;;)
2144          {          {
2145          for (fi = min;; fi++)          for (fi = min;; fi++)
2146            {            {
2147            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
2148            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2149            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2150            GETCHARINC(c, eptr);            GETCHARINCTEST(c, eptr);
2151            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2152            }            }
2153          /* Control never gets here */          /* Control never gets here */
# Line 1823  for (;;) Line 2162  for (;;)
2162            {            {
2163            int len = 1;            int len = 1;
2164            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
2165            GETCHARLEN(c, eptr, len);            GETCHARLENTEST(c, eptr, len);
2166            if (!_pcre_xclass(c, data)) break;            if (!_pcre_xclass(c, data)) break;
2167            eptr += len;            eptr += len;
2168            }            }
2169          for(;;)          for(;;)
2170            {            {
2171            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
2172            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2173            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2174            BACKCHAR(eptr)            if (utf8) BACKCHAR(eptr);
2175            }            }
2176          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2177          }          }
# Line 1888  for (;;) Line 2227  for (;;)
2227    
2228        else        else
2229          {          {
2230          int dc;          unsigned int dc;
2231          GETCHARINC(dc, eptr);          GETCHARINC(dc, eptr);
2232          ecode += length;          ecode += length;
2233    
# Line 1898  for (;;) Line 2237  for (;;)
2237          if (fc != dc)          if (fc != dc)
2238            {            {
2239  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2240            if (dc != _pcre_ucp_othercase(fc))            if (dc != UCD_OTHERCASE(fc))
2241  #endif  #endif
2242              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2243            }            }
# Line 1915  for (;;) Line 2254  for (;;)
2254        }        }
2255      break;      break;
2256    
2257      /* Match a single character repeatedly; different opcodes share code. */      /* Match a single character repeatedly. */
2258    
2259      case OP_EXACT:      case OP_EXACT:
2260      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
2261      ecode += 3;      ecode += 3;
2262      goto REPEATCHAR;      goto REPEATCHAR;
2263    
2264        case OP_POSUPTO:
2265        possessive = TRUE;
2266        /* Fall through */
2267    
2268      case OP_UPTO:      case OP_UPTO:
2269      case OP_MINUPTO:      case OP_MINUPTO:
2270      min = 0;      min = 0;
# Line 1930  for (;;) Line 2273  for (;;)
2273      ecode += 3;      ecode += 3;
2274      goto REPEATCHAR;      goto REPEATCHAR;
2275    
2276        case OP_POSSTAR:
2277        possessive = TRUE;
2278        min = 0;
2279        max = INT_MAX;
2280        ecode++;
2281        goto REPEATCHAR;
2282    
2283        case OP_POSPLUS:
2284        possessive = TRUE;
2285        min = 1;
2286        max = INT_MAX;
2287        ecode++;
2288        goto REPEATCHAR;
2289    
2290        case OP_POSQUERY:
2291        possessive = TRUE;
2292        min = 0;
2293        max = 1;
2294        ecode++;
2295        goto REPEATCHAR;
2296    
2297      case OP_STAR:      case OP_STAR:
2298      case OP_MINSTAR:      case OP_MINSTAR:
2299      case OP_PLUS:      case OP_PLUS:
# Line 1961  for (;;) Line 2325  for (;;)
2325    
2326        if (length > 1)        if (length > 1)
2327          {          {
         int oclength = 0;  
         uschar occhars[8];  
   
2328  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2329          int othercase;          unsigned int othercase;
2330          if ((ims & PCRE_CASELESS) != 0 &&          if ((ims & PCRE_CASELESS) != 0 &&
2331              (othercase = _pcre_ucp_othercase(fc)) >= 0 &&              (othercase = UCD_OTHERCASE(fc)) != fc)
              othercase >= 0)  
2332            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
2333            else oclength = 0;
2334  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2335    
2336          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2337            {            {
2338            if (memcmp(eptr, charptr, length) == 0) eptr += length;            if (memcmp(eptr, charptr, length) == 0) eptr += length;
2339    #ifdef SUPPORT_UCP
2340            /* Need braces because of following else */            /* Need braces because of following else */
2341            else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }            else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }
2342            else            else
# Line 1982  for (;;) Line 2344  for (;;)
2344              if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);              if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);
2345              eptr += oclength;              eptr += oclength;
2346              }              }
2347    #else   /* without SUPPORT_UCP */
2348              else { RRETURN(MATCH_NOMATCH); }
2349    #endif  /* SUPPORT_UCP */
2350            }            }
2351    
2352          if (min == max) continue;          if (min == max) continue;
# Line 1990  for (;;) Line 2355  for (;;)
2355            {            {
2356            for (fi = min;; fi++)            for (fi = min;; fi++)
2357              {              {
2358              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
2359              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2360              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2361              if (memcmp(eptr, charptr, length) == 0) eptr += length;              if (memcmp(eptr, charptr, length) == 0) eptr += length;
2362    #ifdef SUPPORT_UCP
2363              /* Need braces because of following else */              /* Need braces because of following else */
2364              else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }              else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }
2365              else              else
# Line 2001  for (;;) Line 2367  for (;;)
2367                if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);                if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);
2368                eptr += oclength;                eptr += oclength;
2369                }                }
2370    #else   /* without SUPPORT_UCP */
2371                else { RRETURN (MATCH_NOMATCH); }
2372    #endif  /* SUPPORT_UCP */
2373              }              }
2374            /* Control never gets here */            /* Control never gets here */
2375            }            }
2376          else  
2377            else  /* Maximize */
2378            {            {
2379            pp = eptr;            pp = eptr;
2380            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2381              {              {
2382              if (eptr > md->end_subject - length) break;              if (eptr > md->end_subject - length) break;
2383              if (memcmp(eptr, charptr, length) == 0) eptr += length;              if (memcmp(eptr, charptr, length) == 0) eptr += length;
2384    #ifdef SUPPORT_UCP
2385              else if (oclength == 0) break;              else if (oclength == 0) break;
2386              else              else
2387                {                {
2388                if (memcmp(eptr, occhars, oclength) != 0) break;                if (memcmp(eptr, occhars, oclength) != 0) break;
2389                eptr += oclength;                eptr += oclength;
2390                }                }
2391    #else   /* without SUPPORT_UCP */
2392                else break;
2393    #endif  /* SUPPORT_UCP */
2394              }              }
2395            while (eptr >= pp)  
2396              if (possessive) continue;
2397              for(;;)
2398             {             {
2399             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);
2400             if (rrc != MATCH_NOMATCH) RRETURN(rrc);             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2401               if (eptr == pp) RRETURN(MATCH_NOMATCH);
2402    #ifdef SUPPORT_UCP
2403               eptr--;
2404               BACKCHAR(eptr);
2405    #else   /* without SUPPORT_UCP */
2406             eptr -= length;             eptr -= length;
2407    #endif  /* SUPPORT_UCP */
2408             }             }
           RRETURN(MATCH_NOMATCH);  
2409            }            }
2410          /* Control never gets here */          /* Control never gets here */
2411          }          }
# Line 2064  for (;;) Line 2445  for (;;)
2445          {          {
2446          for (fi = min;; fi++)          for (fi = min;; fi++)
2447            {            {
2448            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
2449            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2450            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max || eptr >= md->end_subject ||
2451                fc != md->lcc[*eptr++])                fc != md->lcc[*eptr++])
# Line 2072  for (;;) Line 2453  for (;;)
2453            }            }
2454          /* Control never gets here */          /* Control never gets here */
2455          }          }
2456        else        else  /* Maximize */
2457          {          {
2458          pp = eptr;          pp = eptr;
2459          for (i = min; i < max; i++)          for (i = min; i < max; i++)
# Line 2080  for (;;) Line 2461  for (;;)
2461            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;
2462            eptr++;            eptr++;
2463            }            }
2464            if (possessive) continue;
2465          while (eptr >= pp)          while (eptr >= pp)
2466            {            {
2467            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);
2468            eptr--;            eptr--;
2469            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2470            }            }
# Line 2101  for (;;) Line 2483  for (;;)
2483          {          {
2484          for (fi = min;; fi++)          for (fi = min;; fi++)
2485            {            {
2486            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
2487            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2488            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)
2489              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2490            }            }
2491          /* Control never gets here */          /* Control never gets here */
2492          }          }
2493        else        else  /* Maximize */
2494          {          {
2495          pp = eptr;          pp = eptr;
2496          for (i = min; i < max; i++)          for (i = min; i < max; i++)
# Line 2116  for (;;) Line 2498  for (;;)
2498            if (eptr >= md->end_subject || fc != *eptr) break;            if (eptr >= md->end_subject || fc != *eptr) break;
2499            eptr++;            eptr++;
2500            }            }
2501            if (possessive) continue;
2502          while (eptr >= pp)          while (eptr >= pp)
2503            {            {
2504            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);
2505            eptr--;            eptr--;
2506            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2507            }            }
# Line 2168  for (;;) Line 2551  for (;;)
2551      ecode += 3;      ecode += 3;
2552      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
2553    
2554        case OP_NOTPOSSTAR:
2555        possessive = TRUE;
2556        min = 0;
2557        max = INT_MAX;
2558        ecode++;
2559        goto REPEATNOTCHAR;
2560    
2561        case OP_NOTPOSPLUS:
2562        possessive = TRUE;
2563        min = 1;
2564        max = INT_MAX;
2565        ecode++;
2566        goto REPEATNOTCHAR;
2567    
2568        case OP_NOTPOSQUERY:
2569        possessive = TRUE;
2570        min = 0;
2571        max = 1;
2572        ecode++;
2573        goto REPEATNOTCHAR;
2574    
2575        case OP_NOTPOSUPTO:
2576        possessive = TRUE;
2577        min = 0;
2578        max = GET2(ecode, 1);
2579        ecode += 3;
2580        goto REPEATNOTCHAR;
2581    
2582      case OP_NOTSTAR:      case OP_NOTSTAR:
2583      case OP_NOTMINSTAR:      case OP_NOTMINSTAR:
2584      case OP_NOTPLUS:      case OP_NOTPLUS:
# Line 2207  for (;;) Line 2618  for (;;)
2618        /* UTF-8 mode */        /* UTF-8 mode */
2619        if (utf8)        if (utf8)
2620          {          {
2621          register int d;          register unsigned int d;
2622          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2623            {            {
2624            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
# Line 2232  for (;;) Line 2643  for (;;)
2643          /* UTF-8 mode */          /* UTF-8 mode */
2644          if (utf8)          if (utf8)
2645            {            {
2646            register int d;            register unsigned int d;
2647            for (fi = min;; fi++)            for (fi = min;; fi++)
2648              {              {
2649              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
2650              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2651                if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2652              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2653              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
2654              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
2655                RRETURN(MATCH_NOMATCH);  
2656              }              }
2657            }            }
2658          else          else
# Line 2249  for (;;) Line 2661  for (;;)
2661            {            {
2662            for (fi = min;; fi++)            for (fi = min;; fi++)
2663              {              {
2664              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
2665              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2666              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])
2667                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
# Line 2268  for (;;) Line 2680  for (;;)
2680          /* UTF-8 mode */          /* UTF-8 mode */
2681          if (utf8)          if (utf8)
2682            {            {
2683            register int d;            register unsigned int d;
2684            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2685              {              {
2686              int len = 1;              int len = 1;
# Line 2278  for (;;) Line 2690  for (;;)
2690              if (fc == d) break;              if (fc == d) break;
2691              eptr += len;              eptr += len;
2692              }              }
2693            for(;;)          if (possessive) continue;
2694            for(;;)
2695              {              {
2696              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30);
2697              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2698              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2699              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2295  for (;;) Line 2708  for (;;)
2708              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;
2709              eptr++;              eptr++;
2710              }              }
2711              if (possessive) continue;
2712            while (eptr >= pp)            while (eptr >= pp)
2713              {              {
2714              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31);
2715              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2716              eptr--;              eptr--;
2717              }              }
# Line 2316  for (;;) Line 2730  for (;;)
2730        /* UTF-8 mode */        /* UTF-8 mode */
2731        if (utf8)        if (utf8)
2732          {          {
2733          register int d;          register unsigned int d;
2734          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2735            {            {
2736            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
# Line 2339  for (;;) Line 2753  for (;;)
2753          /* UTF-8 mode */          /* UTF-8 mode */
2754          if (utf8)          if (utf8)
2755            {            {
2756            register int d;            register unsigned int d;
2757            for (fi = min;; fi++)            for (fi = min;; fi++)
2758              {              {
2759              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
2760              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2761                if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2762              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2763              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
2764              }              }
2765            }            }
2766          else          else
# Line 2355  for (;;) Line 2769  for (;;)
2769            {            {
2770            for (fi = min;; fi++)            for (fi = min;; fi++)
2771              {              {
2772              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);
2773              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2774              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)
2775                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
# Line 2374  for (;;) Line 2788  for (;;)
2788          /* UTF-8 mode */          /* UTF-8 mode */
2789          if (utf8)          if (utf8)
2790            {            {
2791            register int d;            register unsigned int d;
2792            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2793              {              {
2794              int len = 1;              int len = 1;
# Line 2383  for (;;) Line 2797  for (;;)
2797              if (fc == d) break;              if (fc == d) break;
2798              eptr += len;              eptr += len;
2799              }              }
2800              if (possessive) continue;
2801            for(;;)            for(;;)
2802              {              {
2803              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34);
2804              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2805              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2806              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2400  for (;;) Line 2815  for (;;)
2815              if (eptr >= md->end_subject || fc == *eptr) break;              if (eptr >= md->end_subject || fc == *eptr) break;
2816              eptr++;              eptr++;
2817              }              }
2818              if (possessive) continue;
2819            while (eptr >= pp)            while (eptr >= pp)
2820              {              {
2821              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35);
2822              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2823              eptr--;              eptr--;
2824              }              }
# Line 2431  for (;;) Line 2847  for (;;)
2847      ecode += 3;      ecode += 3;
2848      goto REPEATTYPE;      goto REPEATTYPE;
2849    
2850        case OP_TYPEPOSSTAR:
2851        possessive = TRUE;
2852        min = 0;
2853        max = INT_MAX;
2854        ecode++;
2855        goto REPEATTYPE;
2856    
2857        case OP_TYPEPOSPLUS:
2858        possessive = TRUE;
2859        min = 1;
2860        max = INT_MAX;
2861        ecode++;
2862        goto REPEATTYPE;
2863    
2864        case OP_TYPEPOSQUERY:
2865        possessive = TRUE;
2866        min = 0;
2867        max = 1;
2868        ecode++;
2869        goto REPEATTYPE;
2870    
2871        case OP_TYPEPOSUPTO:
2872        possessive = TRUE;
2873        min = 0;
2874        max = GET2(ecode, 1);
2875        ecode += 3;
2876        goto REPEATTYPE;
2877    
2878      case OP_TYPESTAR:      case OP_TYPESTAR:
2879      case OP_TYPEMINSTAR:      case OP_TYPEMINSTAR:
2880      case OP_TYPEPLUS:      case OP_TYPEPLUS:
# Line 2481  for (;;) Line 2925  for (;;)
2925            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2926              {              {
2927              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2928              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2929              }              }
2930            break;            break;
2931    
# Line 2489  for (;;) Line 2933  for (;;)
2933            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2934              {              {
2935              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2936              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2937              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
2938              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
2939                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
2940                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 2502  for (;;) Line 2946  for (;;)
2946            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2947              {              {
2948              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2949              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2950              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
2951              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
2952                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2953              }              }
# Line 2513  for (;;) Line 2957  for (;;)
2957            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2958              {              {
2959              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2960              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2961              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
2962              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
2963                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2964              }              }
# Line 2524  for (;;) Line 2968  for (;;)
2968            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2969              {              {
2970              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2971              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2972              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
2973              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
2974                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2975              }              }
# Line 2533  for (;;) Line 2977  for (;;)
2977    
2978            default:            default:
2979            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
           break;  
2980            }            }
2981          }          }
2982    
# Line 2545  for (;;) Line 2988  for (;;)
2988          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2989            {            {
2990            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
2991            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
2992            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
2993            while (eptr < md->end_subject)            while (eptr < md->end_subject)
2994              {              {
# Line 2554  for (;;) Line 2997  for (;;)
2997                {                {
2998                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
2999                }                }
3000              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3001              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3002              eptr += len;              eptr += len;
3003              }              }
# Line 2572  for (;;) Line 3015  for (;;)
3015          case OP_ANY:          case OP_ANY:
3016          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3017            {            {
3018            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject || IS_NEWLINE(eptr))
              (*eptr++ == NEWLINE && (ims & PCRE_DOTALL) == 0))  
3019              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3020              eptr++;
3021              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3022              }
3023            break;
3024    
3025            case OP_ALLANY:
3026            for (i = 1; i <= min; i++)
3027              {
3028              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3029              eptr++;
3030            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3031            }            }
3032          break;          break;
# Line 2583  for (;;) Line 3035  for (;;)
3035          eptr += min;          eptr += min;
3036          break;          break;
3037    
3038            case OP_ANYNL:
3039            for (i = 1; i <= min; i++)
3040              {
3041              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3042              GETCHARINC(c, eptr);
3043              switch(c)
3044                {
3045                default: RRETURN(MATCH_NOMATCH);
3046                case 0x000d:
3047                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3048                break;
3049    
3050                case 0x000a:
3051                break;
3052    
3053                case 0x000b:
3054                case 0x000c:
3055                case 0x0085:
3056                case 0x2028:
3057                case 0x2029:
3058                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3059                break;
3060                }
3061              }
3062            break;
3063    
3064            case OP_NOT_HSPACE:
3065            for (i = 1; i <= min; i++)
3066              {
3067              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3068              GETCHARINC(c, eptr);
3069              switch(c)
3070                {
3071                default: break;
3072                case 0x09:      /* HT */
3073                case 0x20:      /* SPACE */
3074                case 0xa0:      /* NBSP */
3075                case 0x1680:    /* OGHAM SPACE MARK */
3076                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3077                case 0x2000:    /* EN QUAD */
3078                case 0x2001:    /* EM QUAD */
3079                case 0x2002:    /* EN SPACE */
3080                case 0x2003:    /* EM SPACE */
3081                case 0x2004:    /* THREE-PER-EM SPACE */
3082                case 0x2005:    /* FOUR-PER-EM SPACE */
3083                case 0x2006:    /* SIX-PER-EM SPACE */
3084                case 0x2007:    /* FIGURE SPACE */
3085                case 0x2008:    /* PUNCTUATION SPACE */
3086                case 0x2009:    /* THIN SPACE */
3087                case 0x200A:    /* HAIR SPACE */
3088                case 0x202f:    /* NARROW NO-BREAK SPACE */
3089                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3090                case 0x3000:    /* IDEOGRAPHIC SPACE */
3091                RRETURN(MATCH_NOMATCH);
3092                }
3093              }
3094            break;
3095    
3096            case OP_HSPACE:
3097            for (i = 1; i <= min; i++)
3098              {
3099              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3100              GETCHARINC(c, eptr);
3101              switch(c)
3102                {
3103                default: RRETURN(MATCH_NOMATCH);
3104                case 0x09:      /* HT */
3105                case 0x20:      /* SPACE */
3106                case 0xa0:      /* NBSP */
3107                case 0x1680:    /* OGHAM SPACE MARK */
3108                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3109                case 0x2000:    /* EN QUAD */
3110                case 0x2001:    /* EM QUAD */
3111                case 0x2002:    /* EN SPACE */
3112                case 0x2003:    /* EM SPACE */
3113                case 0x2004:    /* THREE-PER-EM SPACE */
3114                case 0x2005:    /* FOUR-PER-EM SPACE */
3115                case 0x2006:    /* SIX-PER-EM SPACE */
3116                case 0x2007:    /* FIGURE SPACE */
3117                case 0x2008:    /* PUNCTUATION SPACE */
3118                case 0x2009:    /* THIN SPACE */
3119                case 0x200A:    /* HAIR SPACE */
3120                case 0x202f:    /* NARROW NO-BREAK SPACE */
3121                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3122                case 0x3000:    /* IDEOGRAPHIC SPACE */
3123                break;
3124                }
3125              }
3126            break;
3127    
3128            case OP_NOT_VSPACE:
3129            for (i = 1; i <= min; i++)
3130              {
3131              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3132              GETCHARINC(c, eptr);
3133              switch(c)
3134                {
3135                default: break;
3136                case 0x0a:      /* LF */
3137                case 0x0b:      /* VT */
3138                case 0x0c:      /* FF */
3139                case 0x0d:      /* CR */
3140                case 0x85:      /* NEL */
3141                case 0x2028:    /* LINE SEPARATOR */
3142                case 0x2029:    /* PARAGRAPH SEPARATOR */
3143                RRETURN(MATCH_NOMATCH);
3144                }
3145              }
3146            break;
3147    
3148            case OP_VSPACE:
3149            for (i = 1; i <= min; i++)
3150              {
3151              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3152              GETCHARINC(c, eptr);
3153              switch(c)
3154                {
3155                default: RRETURN(MATCH_NOMATCH);
3156                case 0x0a:      /* LF */
3157                case 0x0b:      /* VT */
3158                case 0x0c:      /* FF */
3159                case 0x0d:      /* CR */
3160                case 0x85:      /* NEL */
3161                case 0x2028:    /* LINE SEPARATOR */
3162                case 0x2029:    /* PARAGRAPH SEPARATOR */
3163                break;
3164                }
3165              }
3166            break;
3167    
3168          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3169          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3170            {            {
# Line 2607  for (;;) Line 3189  for (;;)
3189          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3190            {            {
3191            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject ||
3192               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0))               (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0))
3193              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3194            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3195            }            }
3196          break;          break;
3197    
# Line 2627  for (;;) Line 3209  for (;;)
3209          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3210            {            {
3211            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject ||
3212               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0))               (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0))
3213              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3214            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3215            }            }
3216          break;          break;
3217    
# Line 2651  for (;;) Line 3233  for (;;)
3233  #endif     /* SUPPORT_UTF8 */  #endif     /* SUPPORT_UTF8 */
3234    
3235        /* 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
3236        than OP_PROP and OP_NOTPROP. */        than OP_PROP and OP_NOTPROP. We can assume that there are the minimum
3237          number of bytes present, as this was tested above. */
3238    
3239        switch(ctype)        switch(ctype)
3240          {          {
3241          case OP_ANY:          case OP_ANY:
3242          if ((ims & PCRE_DOTALL) == 0)          for (i = 1; i <= min; i++)
3243            {            {
3244            for (i = 1; i <= min; i++)            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3245              if (*eptr++ == NEWLINE) RRETURN(MATCH_NOMATCH);            eptr++;
3246            }            }
3247          else eptr += min;          break;
3248    
3249            case OP_ALLANY:
3250            eptr += min;
3251          break;          break;
3252    
3253          case OP_ANYBYTE:          case OP_ANYBYTE:
3254          eptr += min;          eptr += min;
3255          break;          break;
3256    
3257            /* Because of the CRLF case, we can't assume the minimum number of
3258            bytes are present in this case. */
3259    
3260            case OP_ANYNL:
3261            for (i = 1; i <= min; i++)
3262              {
3263              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3264              switch(*eptr++)
3265                {
3266                default: RRETURN(MATCH_NOMATCH);
3267                case 0x000d:
3268                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3269                break;
3270                case 0x000a:
3271                break;
3272    
3273                case 0x000b:
3274                case 0x000c:
3275                case 0x0085:
3276                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3277                break;
3278                }
3279              }
3280            break;
3281    
3282            case OP_NOT_HSPACE:
3283            for (i = 1; i <= min; i++)
3284              {
3285              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3286              switch(*eptr++)
3287                {
3288                default: break;
3289                case 0x09:      /* HT */
3290                case 0x20:      /* SPACE */
3291                case 0xa0:      /* NBSP */
3292                RRETURN(MATCH_NOMATCH);
3293                }
3294              }
3295            break;
3296    
3297            case OP_HSPACE:
3298            for (i = 1; i <= min; i++)
3299              {
3300              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3301              switch(*eptr++)
3302                {
3303                default: RRETURN(MATCH_NOMATCH);
3304                case 0x09:      /* HT */
3305                case 0x20:      /* SPACE */
3306                case 0xa0:      /* NBSP */
3307                break;
3308                }
3309              }
3310            break;
3311    
3312            case OP_NOT_VSPACE:
3313            for (i = 1; i <= min; i++)
3314              {
3315              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3316              switch(*eptr++)
3317                {
3318                default: break;
3319                case 0x0a:      /* LF */
3320                case 0x0b:      /* VT */
3321                case 0x0c:      /* FF */
3322                case 0x0d:      /* CR */
3323                case 0x85:      /* NEL */
3324                RRETURN(MATCH_NOMATCH);
3325                }
3326              }
3327            break;
3328    
3329            case OP_VSPACE:
3330            for (i = 1; i <= min; i++)
3331              {
3332              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3333              switch(*eptr++)
3334                {
3335                default: RRETURN(MATCH_NOMATCH);
3336                case 0x0a:      /* LF */
3337                case 0x0b:      /* VT */
3338                case 0x0c:      /* FF */
3339                case 0x0d:      /* CR */
3340                case 0x85:      /* NEL */
3341                break;
3342                }
3343              }
3344            break;
3345    
3346          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3347          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3348            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
# Line 2723  for (;;) Line 3398  for (;;)
3398            case PT_ANY:            case PT_ANY:
3399            for (fi = min;; fi++)            for (fi = min;; fi++)
3400              {              {
3401              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);
3402              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3403              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3404              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3405              if (prop_fail_result) RRETURN(MATCH_NOMATCH);              if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3406              }              }
3407            break;            /* Control never gets here */
3408    
3409            case PT_LAMP:            case PT_LAMP:
3410            for (fi = min;; fi++)            for (fi = min;; fi++)
3411              {              {
3412              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);
3413              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3414              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3415              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3416              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3417              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3418                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3419                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
3420                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3421              }              }
3422            break;            /* Control never gets here */
3423    
3424            case PT_GC:            case PT_GC:
3425            for (fi = min;; fi++)            for (fi = min;; fi++)
3426              {              {
3427              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);
3428              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3429              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3430              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3431              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3432              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3433                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3434              }              }
3435            break;            /* Control never gets here */
3436    
3437            case PT_PC:            case PT_PC:
3438            for (fi = min;; fi++)            for (fi = min;; fi++)
3439              {              {
3440              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);
3441              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3442              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3443              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3444              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3445              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3446                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3447              }              }
3448            break;            /* Control never gets here */
3449    
3450            case PT_SC:            case PT_SC:
3451            for (fi = min;; fi++)            for (fi = min;; fi++)
3452              {              {
3453              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);
3454              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3455              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3456              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3457              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3458              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3459                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3460              }              }
3461            break;            /* Control never gets here */
3462    
3463            default:            default:
3464            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
           break;  
3465            }            }
3466          }          }
3467    
# Line 2798  for (;;) Line 3472  for (;;)
3472          {          {
3473          for (fi = min;; fi++)          for (fi = min;; fi++)
3474            {            {
3475            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);
3476            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3477            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3478            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3479            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3480            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3481            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3482              {              {
# Line 2811  for (;;) Line 3485  for (;;)
3485                {                {
3486                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3487                }                }
3488              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3489              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3490              eptr += len;              eptr += len;
3491              }              }
# Line 2827  for (;;) Line 3501  for (;;)
3501          {          {
3502          for (fi = min;; fi++)          for (fi = min;; fi++)
3503            {            {
3504            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);
3505            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3506            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject ||
3507                   (ctype == OP_ANY && IS_NEWLINE(eptr)))
3508                RRETURN(MATCH_NOMATCH);
3509    
3510            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3511            switch(ctype)            switch(ctype)
3512              {              {
3513              case OP_ANY:              case OP_ANY:        /* This is the non-NL case */
3514              if ((ims & PCRE_DOTALL) == 0 && c == NEWLINE) RRETURN(MATCH_NOMATCH);              case OP_ALLANY:
3515                case OP_ANYBYTE:
3516              break;              break;
3517    
3518              case OP_ANYBYTE:              case OP_ANYNL:
3519                switch(c)
3520                  {
3521                  default: RRETURN(MATCH_NOMATCH);
3522                  case 0x000d:
3523                  if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3524                  break;
3525                  case 0x000a:
3526                  break;
3527    
3528                  case 0x000b:
3529                  case 0x000c:
3530                  case 0x0085:
3531                  case 0x2028:
3532                  case 0x2029:
3533                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3534                  break;
3535                  }
3536                break;
3537    
3538                case OP_NOT_HSPACE:
3539                switch(c)
3540                  {
3541                  default: break;
3542                  case 0x09:      /* HT */
3543                  case 0x20:      /* SPACE */
3544                  case 0xa0:      /* NBSP */
3545                  case 0x1680:    /* OGHAM SPACE MARK */
3546                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3547                  case 0x2000:    /* EN QUAD */
3548                  case 0x2001:    /* EM QUAD */
3549                  case 0x2002:    /* EN SPACE */
3550                  case 0x2003:    /* EM SPACE */
3551                  case 0x2004:    /* THREE-PER-EM SPACE */
3552                  case 0x2005:    /* FOUR-PER-EM SPACE */
3553                  case 0x2006:    /* SIX-PER-EM SPACE */
3554                  case 0x2007:    /* FIGURE SPACE */
3555                  case 0x2008:    /* PUNCTUATION SPACE */
3556                  case 0x2009:    /* THIN SPACE */
3557                  case 0x200A:    /* HAIR SPACE */
3558                  case 0x202f:    /* NARROW NO-BREAK SPACE */
3559                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3560                  case 0x3000:    /* IDEOGRAPHIC SPACE */
3561                  RRETURN(MATCH_NOMATCH);
3562                  }
3563                break;
3564    
3565                case OP_HSPACE:
3566                switch(c)
3567                  {
3568                  default: RRETURN(MATCH_NOMATCH);
3569                  case 0x09:      /* HT */
3570                  case 0x20:      /* SPACE */
3571                  case 0xa0:      /* NBSP */
3572                  case 0x1680:    /* OGHAM SPACE MARK */
3573                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3574                  case 0x2000:    /* EN QUAD */
3575                  case 0x2001:    /* EM QUAD */
3576                  case 0x2002:    /* EN SPACE */
3577                  case 0x2003:    /* EM SPACE */
3578                  case 0x2004:    /* THREE-PER-EM SPACE */
3579                  case 0x2005:    /* FOUR-PER-EM SPACE */
3580                  case 0x2006:    /* SIX-PER-EM SPACE */
3581                  case 0x2007:    /* FIGURE SPACE */
3582                  case 0x2008:    /* PUNCTUATION SPACE */
3583                  case 0x2009:    /* THIN SPACE */
3584                  case 0x200A:    /* HAIR SPACE */
3585                  case 0x202f:    /* NARROW NO-BREAK SPACE */
3586                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3587                  case 0x3000:    /* IDEOGRAPHIC SPACE */
3588                  break;
3589                  }
3590                break;
3591    
3592                case OP_NOT_VSPACE:
3593                switch(c)
3594                  {
3595                  default: break;
3596                  case 0x0a:      /* LF */
3597                  case 0x0b:      /* VT */
3598                  case 0x0c:      /* FF */
3599                  case 0x0d:      /* CR */
3600                  case 0x85:      /* NEL */
3601                  case 0x2028:    /* LINE SEPARATOR */
3602                  case 0x2029:    /* PARAGRAPH SEPARATOR */
3603                  RRETURN(MATCH_NOMATCH);
3604                  }
3605                break;
3606    
3607                case OP_VSPACE:
3608                switch(c)
3609                  {
3610                  default: RRETURN(MATCH_NOMATCH);
3611                  case 0x0a:      /* LF */
3612                  case 0x0b:      /* VT */
3613                  case 0x0c:      /* FF */
3614                  case 0x0d:      /* CR */
3615                  case 0x85:      /* NEL */
3616                  case 0x2028:    /* LINE SEPARATOR */
3617                  case 0x2029:    /* PARAGRAPH SEPARATOR */
3618                  break;
3619                  }
3620              break;              break;
3621    
3622              case OP_NOT_DIGIT:              case OP_NOT_DIGIT:
# Line 2882  for (;;) Line 3660  for (;;)
3660          {          {
3661          for (fi = min;; fi++)          for (fi = min;; fi++)
3662            {            {
3663            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);
3664            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3665            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject ||
3666                   (ctype == OP_ANY && IS_NEWLINE(eptr)))
3667                RRETURN(MATCH_NOMATCH);
3668    
3669            c = *eptr++;            c = *eptr++;
3670            switch(ctype)            switch(ctype)
3671              {              {
3672              case OP_ANY:              case OP_ANY:     /* This is the non-NL case */
3673              if ((ims & PCRE_DOTALL) == 0 && c == NEWLINE) RRETURN(MATCH_NOMATCH);              case OP_ALLANY:
3674                case OP_ANYBYTE:
3675              break;              break;
3676    
3677              case OP_ANYBYTE:              case OP_ANYNL:
3678                switch(c)
3679                  {
3680                  default: RRETURN(MATCH_NOMATCH);
3681                  case 0x000d:
3682                  if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3683                  break;
3684    
3685                  case 0x000a:
3686                  break;
3687    
3688                  case 0x000b:
3689                  case 0x000c:
3690                  case 0x0085:
3691                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3692                  break;
3693                  }
3694                break;
3695    
3696                case OP_NOT_HSPACE:
3697                switch(c)
3698                  {
3699                  default: break;
3700                  case 0x09:      /* HT */
3701                  case 0x20:      /* SPACE */
3702                  case 0xa0:      /* NBSP */
3703                  RRETURN(MATCH_NOMATCH);
3704                  }
3705                break;
3706    
3707                case OP_HSPACE:
3708                switch(c)
3709                  {
3710                  default: RRETURN(MATCH_NOMATCH);
3711                  case 0x09:      /* HT */
3712                  case 0x20:      /* SPACE */
3713                  case 0xa0:      /* NBSP */
3714                  break;
3715                  }
3716                break;
3717    
3718                case OP_NOT_VSPACE:
3719                switch(c)
3720                  {
3721                  default: break;
3722                  case 0x0a:      /* LF */
3723                  case 0x0b:      /* VT */
3724                  case 0x0c:      /* FF */
3725                  case 0x0d:      /* CR */
3726                  case 0x85:      /* NEL */
3727                  RRETURN(MATCH_NOMATCH);
3728                  }
3729                break;
3730    
3731                case OP_VSPACE:
3732                switch(c)
3733                  {
3734                  default: RRETURN(MATCH_NOMATCH);
3735                  case 0x0a:      /* LF */
3736                  case 0x0b:      /* VT */
3737                  case 0x0c:      /* FF */
3738                  case 0x0d:      /* CR */
3739                  case 0x85:      /* NEL */
3740                  break;
3741                  }
3742              break;              break;
3743    
3744              case OP_NOT_DIGIT:              case OP_NOT_DIGIT:
# Line 2927  for (;;) Line 3773  for (;;)
3773        /* Control never gets here */        /* Control never gets here */
3774        }        }
3775    
3776      /* 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
3777      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
3778      UTF-8 and UCP stuff separate. */      UTF-8 and UCP stuff separate. */
3779    
# Line 2957  for (;;) Line 3803  for (;;)
3803              int len = 1;              int len = 1;
3804              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3805              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3806              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3807              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3808                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3809                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 2972  for (;;) Line 3818  for (;;)
3818              int len = 1;              int len = 1;
3819              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3820              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3821              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3822              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3823                break;                break;
3824              eptr+= len;              eptr+= len;
# Line 2985  for (;;) Line 3831  for (;;)
3831              int len = 1;              int len = 1;
3832              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3833              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3834              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3835              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3836                break;                break;
3837              eptr+= len;              eptr+= len;
# Line 2998  for (;;) Line 3844  for (;;)
3844              int len = 1;              int len = 1;
3845              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3846              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3847              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3848              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3849                break;                break;
3850              eptr+= len;              eptr+= len;
# Line 3008  for (;;) Line 3854  for (;;)
3854    
3855          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
3856    
3857            if (possessive) continue;
3858          for(;;)          for(;;)
3859            {            {
3860            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44);
3861            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3862            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
3863            BACKCHAR(eptr);            if (utf8) BACKCHAR(eptr);
3864            }            }
3865          }          }
3866    
# Line 3026  for (;;) Line 3873  for (;;)
3873            {            {
3874            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
3875            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3876            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3877            if (prop_category == ucp_M) break;            if (prop_category == ucp_M) break;
3878            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3879              {              {
# Line 3035  for (;;) Line 3882  for (;;)
3882                {                {
3883                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3884                }                }
3885              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3886              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3887              eptr += len;              eptr += len;
3888              }              }
# Line 3043  for (;;) Line 3890  for (;;)
3890    
3891          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
3892    
3893            if (possessive) continue;
3894          for(;;)          for(;;)
3895            {            {
3896            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45);
3897            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3898            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
3899            for (;;)                        /* Move back over one extended */            for (;;)                        /* Move back over one extended */
3900              {              {
3901              int len = 1;              int len = 1;
             BACKCHAR(eptr);  
3902              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr; else
3903                {                {
3904                  BACKCHAR(eptr);
3905                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3906                }                }
3907              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3908              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3909              eptr--;              eptr--;
3910              }              }
# Line 3074  for (;;) Line 3922  for (;;)
3922          switch(ctype)          switch(ctype)
3923            {            {
3924            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. */  
   
3925            if (max < INT_MAX)            if (max < INT_MAX)
3926              {              {
3927              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  
3928                {                {
3929                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
3930                  {                eptr++;
3931                  eptr++;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
                 }  
3932                }                }
3933              }              }
3934    
# Line 3104  for (;;) Line 3936  for (;;)
3936    
3937            else            else
3938              {              {
3939              if ((ims & PCRE_DOTALL) == 0)              for (i = min; i < max; i++)
3940                {                {
3941                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
3942                  {                eptr++;
3943                  if (eptr >= md->end_subject || *eptr == NEWLINE) break;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
                 eptr++;  
                 }  
               break;  
3944                }                }
3945              else              }
3946              break;
3947    
3948              case OP_ALLANY:
3949              if (max < INT_MAX)
3950                {
3951                for (i = min; i < max; i++)
3952                {                {
3953                c = max - min;                if (eptr >= md->end_subject) break;
3954                if (c > md->end_subject - eptr) c = md->end_subject - eptr;                eptr++;
3955                eptr += c;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3956                }                }
3957              }              }
3958              else eptr = md->end_subject;   /* Unlimited UTF-8 repeat */
3959            break;            break;
3960    
3961            /* The byte case is the same as non-UTF8 */            /* The byte case is the same as non-UTF8 */
3962    
3963            case OP_ANYBYTE:            case OP_ANYBYTE:
3964            c = max - min;            c = max - min;
3965            if (c > md->end_subject - eptr) c = md->end_subject - eptr;            if (c > (unsigned int)(md->end_subject - eptr))
3966                c = md->end_subject - eptr;
3967            eptr += c;            eptr += c;
3968            break;            break;
3969    
3970              case OP_ANYNL:
3971              for (i = min; i < max; i++)
3972                {
3973                int len = 1;
3974                if (eptr >= md->end_subject) break;
3975                GETCHARLEN(c, eptr, len);
3976                if (c == 0x000d)
3977                  {
3978                  if (++eptr >= md->end_subject) break;
3979                  if (*eptr == 0x000a) eptr++;
3980                  }
3981                else
3982                  {
3983                  if (c != 0x000a &&
3984                      (md->bsr_anycrlf ||
3985                       (c != 0x000b && c != 0x000c &&
3986                        c != 0x0085 && c != 0x2028 && c != 0x2029)))
3987                    break;
3988                  eptr += len;
3989                  }
3990                }
3991              break;
3992    
3993              case OP_NOT_HSPACE:
3994              case OP_HSPACE:
3995              for (i = min; i < max; i++)
3996                {
3997                BOOL gotspace;
3998                int len = 1;
3999                if (eptr >= md->end_subject) break;
4000                GETCHARLEN(c, eptr, len);
4001                switch(c)
4002                  {
4003                  default: gotspace = FALSE; break;
4004                  case 0x09:      /* HT */
4005                  case 0x20:      /* SPACE */
4006                  case 0xa0:      /* NBSP */
4007                  case 0x1680:    /* OGHAM SPACE MARK */
4008                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
4009                  case 0x2000:    /* EN QUAD */
4010                  case 0x2001:    /* EM QUAD */
4011                  case 0x2002:    /* EN SPACE */
4012                  case 0x2003:    /* EM SPACE */
4013                  case 0x2004:    /* THREE-PER-EM SPACE */
4014                  case 0x2005:    /* FOUR-PER-EM SPACE */
4015                  case 0x2006:    /* SIX-PER-EM SPACE */
4016                  case 0x2007:    /* FIGURE SPACE */
4017                  case 0x2008:    /* PUNCTUATION SPACE */
4018                  case 0x2009:    /* THIN SPACE */
4019                  case 0x200A:    /* HAIR SPACE */
4020                  case 0x202f:    /* NARROW NO-BREAK SPACE */
4021                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
4022                  case 0x3000:    /* IDEOGRAPHIC SPACE */
4023                  gotspace = TRUE;
4024                  break;
4025                  }
4026                if (gotspace == (ctype == OP_NOT_HSPACE)) break;
4027                eptr += len;
4028                }
4029              break;
4030    
4031              case OP_NOT_VSPACE:
4032              case OP_VSPACE:
4033              for (i = min; i < max; i++)
4034                {
4035                BOOL gotspace;
4036                int len = 1;
4037                if (eptr >= md->end_subject) break;
4038                GETCHARLEN(c, eptr, len);
4039                switch(c)
4040                  {
4041                  default: gotspace = FALSE; break;
4042                  case 0x0a:      /* LF */
4043                  case 0x0b:      /* VT */
4044                  case 0x0c:      /* FF */
4045                  case 0x0d:      /* CR */
4046                  case 0x85:      /* NEL */
4047                  case 0x2028:    /* LINE SEPARATOR */
4048                  case 0x2029:    /* PARAGRAPH SEPARATOR */
4049                  gotspace = TRUE;
4050                  break;
4051                  }
4052                if (gotspace == (ctype == OP_NOT_VSPACE)) break;
4053                eptr += len;
4054                }
4055              break;
4056    
4057            case OP_NOT_DIGIT:            case OP_NOT_DIGIT:
4058            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4059              {              {
# Line 3202  for (;;) Line 4126  for (;;)
4126    
4127          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
4128    
4129            if (possessive) continue;
4130          for(;;)          for(;;)
4131            {            {
4132            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM46);
4133            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4134            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
4135            BACKCHAR(eptr);            BACKCHAR(eptr);
4136            }            }
4137          }          }
4138        else        else
4139  #endif  #endif  /* SUPPORT_UTF8 */
4140    
4141        /* Not UTF-8 mode */        /* Not UTF-8 mode */
4142          {          {
4143          switch(ctype)          switch(ctype)
4144            {            {
4145            case OP_ANY:            case OP_ANY:
4146            if ((ims & PCRE_DOTALL) == 0)            for (i = min; i < max; i++)
4147              {              {
4148              for (i = min; i < max; i++)              if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
4149                {              eptr++;
               if (eptr >= md->end_subject || *eptr == NEWLINE) break;  
               eptr++;  
               }  
             break;  
4150              }              }
4151            /* For DOTALL case, fall through and treat as \C */            break;
4152    
4153              case OP_ALLANY:
4154            case OP_ANYBYTE:            case OP_ANYBYTE:
4155            c = max - min;            c = max - min;
4156            if (c > md->end_subject - eptr) c = md->end_subject - eptr;            if (c > (unsigned int)(md->end_subject - eptr))
4157                c = md->end_subject - eptr;
4158            eptr += c;            eptr += c;
4159            break;            break;
4160    
4161              case OP_ANYNL:
4162              for (i = min; i < max; i++)
4163                {
4164                if (eptr >= md->end_subject) break;
4165                c = *eptr;
4166                if (c == 0x000d)
4167                  {
4168                  if (++eptr >= md->end_subject) break;
4169                  if (*eptr == 0x000a) eptr++;
4170                  }
4171                else
4172                  {
4173                  if (c != 0x000a &&
4174                      (md->bsr_anycrlf ||
4175                        (c != 0x000b && c != 0x000c && c != 0x0085)))
4176                    break;
4177                  eptr++;
4178                  }
4179                }
4180              break;
4181    
4182              case OP_NOT_HSPACE:
4183              for (i = min; i < max; i++)
4184                {
4185                if (eptr >= md->end_subject) break;
4186                c = *eptr;
4187                if (c == 0x09 || c == 0x20 || c == 0xa0) break;
4188                eptr++;
4189                }
4190              break;
4191    
4192              case OP_HSPACE:
4193              for (i = min; i < max; i++)
4194                {
4195                if (eptr >= md->end_subject) break;
4196                c = *eptr;
4197                if (c != 0x09 && c != 0x20 && c != 0xa0) break;
4198                eptr++;
4199                }
4200              break;
4201    
4202              case OP_NOT_VSPACE:
4203              for (i = min; i < max; i++)
4204                {
4205                if (eptr >= md->end_subject) break;
4206                c = *eptr;
4207                if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85)
4208                  break;
4209                eptr++;
4210                }
4211              break;
4212    
4213              case OP_VSPACE:
4214              for (i = min; i < max; i++)
4215                {
4216                if (eptr >= md->end_subject) break;
4217                c = *eptr;
4218                if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85)
4219                  break;
4220                eptr++;
4221                }
4222              break;
4223    
4224            case OP_NOT_DIGIT:            case OP_NOT_DIGIT:
4225            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4226              {              {
# Line 3295  for (;;) Line 4281  for (;;)
4281    
4282          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
4283    
4284            if (possessive) continue;
4285          while (eptr >= pp)          while (eptr >= pp)
4286            {            {
4287            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM47);
4288            eptr--;            eptr--;
4289            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4290            }            }
# Line 3309  for (;;) Line 4296  for (;;)
4296        }        }
4297      /* Control never gets here */      /* Control never gets here */
4298    
4299      /* 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
4300      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. */  
4301    
4302      default:      default:
4303      DPRINTF(("Unknown opcode %d\n", *ecode));      DPRINTF(("Unknown opcode %d\n", *ecode));
4304      RRETURN(PCRE_ERROR_UNKNOWN_NODE);      RRETURN(PCRE_ERROR_UNKNOWN_OPCODE);
4305      }      }
4306    
4307    /* 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 3325  for (;;) Line 4310  for (;;)
4310    
4311    }             /* End of main loop */    }             /* End of main loop */
4312  /* Control never reaches here */  /* Control never reaches here */
4313    
4314    
4315    /* When compiling to use the heap rather than the stack for recursive calls to
4316    match(), the RRETURN() macro jumps here. The number that is saved in
4317    frame->Xwhere indicates which label we actually want to return to. */
4318    
4319    #ifdef NO_RECURSE
4320    #define LBL(val) case val: goto L_RM##val;
4321    HEAP_RETURN:
4322    switch (frame->Xwhere)
4323      {
4324      LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8)
4325      LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17)
4326      LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33)
4327      LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52)
4328      LBL(53) LBL(54)
4329    #ifdef SUPPORT_UTF8
4330      LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30)
4331      LBL(32) LBL(34) LBL(42) LBL(46)
4332    #ifdef SUPPORT_UCP
4333      LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45)
4334    #endif  /* SUPPORT_UCP */
4335    #endif  /* SUPPORT_UTF8 */
4336      default:
4337      DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere));
4338      return PCRE_ERROR_INTERNAL;
4339      }
4340    #undef LBL
4341    #endif  /* NO_RECURSE */
4342  }  }
4343    
4344    
# Line 3337  Undefine all the macros that were define Line 4351  Undefine all the macros that were define
4351  #ifdef NO_RECURSE  #ifdef NO_RECURSE
4352  #undef eptr  #undef eptr
4353  #undef ecode  #undef ecode
4354    #undef mstart
4355  #undef offset_top  #undef offset_top
4356  #undef ims  #undef ims
4357  #undef eptrb  #undef eptrb
# Line 3354  Undefine all the macros that were define Line 4369  Undefine all the macros that were define
4369    
4370  #undef cur_is_word  #undef cur_is_word
4371  #undef condition  #undef condition
 #undef minimize  
4372  #undef prev_is_word  #undef prev_is_word
4373    
4374  #undef original_ims  #undef original_ims
# Line 3410  Returns:          > 0 => success; value Line 4424  Returns:          > 0 => success; value
4424                   < -1 => some kind of unexpected problem                   < -1 => some kind of unexpected problem
4425  */  */
4426    
4427  PCRE_DATA_SCOPE int  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
4428  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,
4429    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,
4430    int offsetcount)    int offsetcount)
# Line 3419  int rc, resetcount, ocount; Line 4433  int rc, resetcount, ocount;
4433  int first_byte = -1;  int first_byte = -1;
4434  int req_byte = -1;  int req_byte = -1;
4435  int req_byte2 = -1;  int req_byte2 = -1;
4436  unsigned long int ims = 0;  int newline;
4437    unsigned long int ims;
4438  BOOL using_temporary_offsets = FALSE;  BOOL using_temporary_offsets = FALSE;
4439  BOOL anchored;  BOOL anchored;
4440  BOOL startline;  BOOL startline;
4441  BOOL firstline;  BOOL firstline;
4442  BOOL first_byte_caseless = FALSE;  BOOL first_byte_caseless = FALSE;
4443  BOOL req_byte_caseless = FALSE;  BOOL req_byte_caseless = FALSE;
4444    BOOL utf8;
4445  match_data match_block;  match_data match_block;
4446    match_data *md = &match_block;
4447  const uschar *tables;  const uschar *tables;
4448  const uschar *start_bits = NULL;  const uschar *start_bits = NULL;
4449  USPTR start_match = (USPTR)subject + start_offset;  USPTR start_match = (USPTR)subject + start_offset;
# Line 3451  if (offsetcount < 0) return PCRE_ERROR_B Line 4468  if (offsetcount < 0) return PCRE_ERROR_B
4468  the default values. */  the default values. */
4469    
4470  study = NULL;  study = NULL;
4471  match_block.match_limit = MATCH_LIMIT;  md->match_limit = MATCH_LIMIT;
4472  match_block.match_limit_recursion = MATCH_LIMIT_RECURSION;  md->match_limit_recursion = MATCH_LIMIT_RECURSION;
4473  match_block.callout_data = NULL;  md->callout_data = NULL;
4474    
4475  /* The table pointer is always in native byte order. */  /* The table pointer is always in native byte order. */
4476    
# Line 3465  if (extra_data != NULL) Line 4482  if (extra_data != NULL)
4482    if ((flags & PCRE_EXTRA_STUDY_DATA) != 0)    if ((flags & PCRE_EXTRA_STUDY_DATA) != 0)
4483      study = (const pcre_study_data *)extra_data->study_data;      study = (const pcre_study_data *)extra_data->study_data;
4484    if ((flags & PCRE_EXTRA_MATCH_LIMIT) != 0)    if ((flags & PCRE_EXTRA_MATCH_LIMIT) != 0)
4485      match_block.match_limit = extra_data->match_limit;      md->match_limit = extra_data->match_limit;
4486    if ((flags & PCRE_EXTRA_MATCH_LIMIT_RECURSION) != 0)    if ((flags & PCRE_EXTRA_MATCH_LIMIT_RECURSION) != 0)
4487      match_block.match_limit_recursion = extra_data->match_limit_recursion;      md->match_limit_recursion = extra_data->match_limit_recursion;
4488    if ((flags & PCRE_EXTRA_CALLOUT_DATA) != 0)    if ((flags & PCRE_EXTRA_CALLOUT_DATA) != 0)
4489      match_block.callout_data = extra_data->callout_data;      md->callout_data = extra_data->callout_data;
4490    if ((flags & PCRE_EXTRA_TABLES) != 0) tables = extra_data->tables;    if ((flags & PCRE_EXTRA_TABLES) != 0) tables = extra_data->tables;
4491    }    }
4492    
# Line 3494  if (re->magic_number != MAGIC_NUMBER) Line 4511  if (re->magic_number != MAGIC_NUMBER)
4511  /* Set up other data */  /* Set up other data */
4512    
4513  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;
4514  startline = (re->options & PCRE_STARTLINE) != 0;  startline = (re->flags & PCRE_STARTLINE) != 0;
4515  firstline = (re->options & PCRE_FIRSTLINE) != 0;  firstline = (re->options & PCRE_FIRSTLINE) != 0;
4516    
4517  /* The code starts after the real_pcre block and the capture name table. */  /* The code starts after the real_pcre block and the capture name table. */
4518    
4519  match_block.start_code = (const uschar *)external_re + re->name_table_offset +  md->start_code = (const uschar *)external_re + re->name_table_offset +
4520    re->name_count * re->name_entry_size;    re->name_count * re->name_entry_size;
4521    
4522  match_block.start_subject = (USPTR)subject;  md->start_subject = (USPTR)subject;
4523  match_block.start_offset = start_offset;  md->start_offset = start_offset;
4524  match_block.end_subject = match_block.start_subject + length;  md->end_subject = md->start_subject + length;
4525  end_subject = match_block.end_subject;  end_subject = md->end_subject;
4526    
4527  match_block.endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
4528  match_block.utf8 = (re->options & PCRE_UTF8) != 0;  utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;
4529    md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;
4530  match_block.notbol = (options & PCRE_NOTBOL) != 0;  
4531  match_block.noteol = (options & PCRE_NOTEOL) != 0;  md->notbol = (options & PCRE_NOTBOL) != 0;
4532  match_block.notempty = (options & PCRE_NOTEMPTY) != 0;  md->noteol = (options & PCRE_NOTEOL) != 0;
4533  match_block.partial = (options & PCRE_PARTIAL) != 0;  md->notempty = (options & PCRE_NOTEMPTY) != 0;
4534  match_block.hitend = FALSE;  md->partial = (options & PCRE_PARTIAL) != 0;
4535    md->hitend = FALSE;
4536    
4537  match_block.recursive = NULL;                   /* No recursion at top level */  md->recursive = NULL;                   /* No recursion at top level */
4538    
4539  match_block.lcc = tables + lcc_offset;  md->lcc = tables + lcc_offset;
4540  match_block.ctypes = tables + ctypes_offset;  md->ctypes = tables + ctypes_offset;
4541    
4542    /* Handle different \R options. */
4543    
4544    switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE))
4545      {
4546      case 0:
4547      if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0)
4548        md->bsr_anycrlf = (re->options & PCRE_BSR_ANYCRLF) != 0;
4549      else
4550    #ifdef BSR_ANYCRLF
4551      md->bsr_anycrlf = TRUE;
4552    #else
4553      md->bsr_anycrlf = FALSE;
4554    #endif
4555      break;
4556    
4557      case PCRE_BSR_ANYCRLF:
4558      md->bsr_anycrlf = TRUE;
4559      break;
4560    
4561      case PCRE_BSR_UNICODE:
4562      md->bsr_anycrlf = FALSE;
4563      break;
4564    
4565      default: return PCRE_ERROR_BADNEWLINE;
4566      }
4567    
4568    /* Handle different types of newline. The three bits give eight cases. If
4569    nothing is set at run time, whatever was used at compile time applies. */
4570    
4571    switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options :
4572            (pcre_uint32)options) & PCRE_NEWLINE_BITS)
4573      {
4574      case 0: newline = NEWLINE; break;   /* Compile-time default */
4575      case PCRE_NEWLINE_CR: newline = CHAR_CR; break;
4576      case PCRE_NEWLINE_LF: newline = CHAR_NL; break;
4577      case PCRE_NEWLINE_CR+
4578           PCRE_NEWLINE_LF: newline = (CHAR_CR << 8) | CHAR_NL; break;
4579      case PCRE_NEWLINE_ANY: newline = -1; break;
4580      case PCRE_NEWLINE_ANYCRLF: newline = -2; break;
4581      default: return PCRE_ERROR_BADNEWLINE;
4582      }
4583    
4584    if (newline == -2)
4585      {
4586      md->nltype = NLTYPE_ANYCRLF;
4587      }
4588    else if (newline < 0)
4589      {
4590      md->nltype = NLTYPE_ANY;
4591      }
4592    else
4593      {
4594      md->nltype = NLTYPE_FIXED;
4595      if (newline > 255)
4596        {
4597        md->nllen = 2;
4598        md->nl[0] = (newline >> 8) & 255;
4599        md->nl[1] = newline & 255;
4600        }
4601      else
4602        {
4603        md->nllen = 1;
4604        md->nl[0] = newline;
4605        }
4606      }
4607    
4608  /* Partial matching is supported only for a restricted set of regexes at the  /* Partial matching is supported only for a restricted set of regexes at the
4609  moment. */  moment. */
4610    
4611  if (match_block.partial && (re->options & PCRE_NOPARTIAL) != 0)  if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0)
4612    return PCRE_ERROR_BADPARTIAL;    return PCRE_ERROR_BADPARTIAL;
4613    
4614  /* Check a UTF-8 string if required. Unfortunately there's no way of passing  /* Check a UTF-8 string if required. Unfortunately there's no way of passing
4615  back the character offset. */  back the character offset. */
4616    
4617  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
4618  if (match_block.utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)
4619    {    {
4620    if (_pcre_valid_utf8((uschar *)subject, length) >= 0)    if (_pcre_valid_utf8((uschar *)subject, length) >= 0)
4621      return PCRE_ERROR_BADUTF8;      return PCRE_ERROR_BADUTF8;
# Line 3563  ocount = offsetcount - (offsetcount % 3) Line 4647  ocount = offsetcount - (offsetcount % 3)
4647  if (re->top_backref > 0 && re->top_backref >= ocount/3)  if (re->top_backref > 0 && re->top_backref >= ocount/3)
4648    {    {
4649    ocount = re->top_backref * 3 + 3;    ocount = re->top_backref * 3 + 3;
4650    match_block.offset_vector = (int *)(pcre_malloc)(ocount * sizeof(int));    md->offset_vector = (int *)(pcre_malloc)(ocount * sizeof(int));
4651    if (match_block.offset_vector == NULL) return PCRE_ERROR_NOMEMORY;    if (md->offset_vector == NULL) return PCRE_ERROR_NOMEMORY;
4652    using_temporary_offsets = TRUE;    using_temporary_offsets = TRUE;
4653    DPRINTF(("Got memory to hold back references\n"));    DPRINTF(("Got memory to hold back references\n"));
4654    }    }
4655  else match_block.offset_vector = offsets;  else md->offset_vector = offsets;
4656    
4657  match_block.offset_end = ocount;  md->offset_end = ocount;
4658  match_block.offset_max = (2*ocount)/3;  md->offset_max = (2*ocount)/3;
4659  match_block.offset_overflow = FALSE;  md->offset_overflow = FALSE;
4660  match_block.capture_last = -1;  md->capture_last = -1;
4661    
4662  /* Compute the minimum number of offsets that we need to reset each time. Doing  /* Compute the minimum number of offsets that we need to reset each time. Doing
4663  this makes a huge difference to execution time when there aren't many brackets  this makes a huge difference to execution time when there aren't many brackets
# Line 3586  if (resetcount > offsetcount) resetcount Line 4670  if (resetcount > offsetcount) resetcount
4670  never be used unless previously set, but they get saved and restored, and so we  never be used unless previously set, but they get saved and restored, and so we
4671  initialize them to avoid reading uninitialized locations. */  initialize them to avoid reading uninitialized locations. */
4672    
4673  if (match_block.offset_vector != NULL)  if (md->offset_vector != NULL)
4674    {    {
4675    register int *iptr = match_block.offset_vector + ocount;    register int *iptr = md->offset_vector + ocount;
4676    register int *iend = iptr - resetcount/2 + 1;    register int *iend = iptr - resetcount/2 + 1;
4677    while (--iptr >= iend) *iptr = -1;    while (--iptr >= iend) *iptr = -1;
4678    }    }
# Line 3601  studied, there may be a bitmap of possib Line 4685  studied, there may be a bitmap of possib
4685    
4686  if (!anchored)  if (!anchored)
4687    {    {
4688    if ((re->options & PCRE_FIRSTSET) != 0)    if ((re->flags & PCRE_FIRSTSET) != 0)
4689      {      {
4690      first_byte = re->first_byte & 255;      first_byte = re->first_byte & 255;
4691      if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)      if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)
4692        first_byte = match_block.lcc[first_byte];        first_byte = md->lcc[first_byte];
4693      }      }
4694    else    else
4695      if (!startline && study != NULL &&      if (!startline && study != NULL &&
# Line 3616  if (!anchored) Line 4700  if (!anchored)
4700  /* For anchored or unanchored matches, there may be a "last known required  /* For anchored or unanchored matches, there may be a "last known required
4701  character" set. */  character" set. */
4702    
4703  if ((re->options & PCRE_REQCHSET) != 0)  if ((re->flags & PCRE_REQCHSET) != 0)
4704    {    {
4705    req_byte = re->req_byte & 255;    req_byte = re->req_byte & 255;
4706    req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;    req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;
4707    req_byte2 = (tables + fcc_offset)[req_byte];  /* case flipped */    req_byte2 = (tables + fcc_offset)[req_byte];  /* case flipped */
4708    }    }
4709    
4710    
4711    /* ==========================================================================*/
4712    
4713  /* Loop for handling unanchored repeated matching attempts; for anchored regexs  /* Loop for handling unanchored repeated matching attempts; for anchored regexs
4714  the loop runs just once. */  the loop runs just once. */
4715    
4716  do  for(;;)
4717    {    {
4718    USPTR save_end_subject = end_subject;    USPTR save_end_subject = end_subject;
4719      USPTR new_start_match;
4720    
4721    /* Reset the maximum number of extractions we might see. */    /* Reset the maximum number of extractions we might see. */
4722    
4723    if (match_block.offset_vector != NULL)    if (md->offset_vector != NULL)
4724      {      {
4725      register int *iptr = match_block.offset_vector;      register int *iptr = md->offset_vector;
4726      register int *iend = iptr + resetcount;      register int *iend = iptr + resetcount;
4727      while (iptr < iend) *iptr++ = -1;      while (iptr < iend) *iptr++ = -1;
4728      }      }
4729    
4730    /* Advance to a unique first char if possible. If firstline is TRUE, the    /* If firstline is TRUE, the start of the match is constrained to the first
4731    start of the match is constrained to the first line of a multiline string.    line of a multiline string. That is, the match must be before or at the first
4732    Implement this by temporarily adjusting end_subject so that we stop scanning    newline. Implement this by temporarily adjusting end_subject so that we stop
4733    at a newline. If the match fails at the newline, later code breaks this loop.    scanning at a newline. If the match fails at the newline, later code breaks
4734    */    this loop. */
4735    
4736    if (firstline)    if (firstline)
4737      {      {
4738      USPTR t = start_match;      USPTR t = start_match;
4739      while (t < save_end_subject && *t != '\n') t++;  #ifdef SUPPORT_UTF8
4740        if (utf8)
4741          {
4742          while (t < md->end_subject && !IS_NEWLINE(t))
4743            {
4744            t++;
4745            while (t < end_subject && (*t & 0xc0) == 0x80) t++;
4746            }
4747          }
4748        else
4749    #endif
4750        while (t < md->end_subject && !IS_NEWLINE(t)) t++;
4751      end_subject = t;      end_subject = t;
4752      }      }
4753    
4754    /* Now test for a unique first byte */    /* There are some optimizations that avoid running the match if a known
4755      starting point is not found, or if a known later character is not present.
4756      However, there is an option that disables these, for testing and for ensuring
4757      that all callouts do actually occur. */
4758    
4759    if (first_byte >= 0)    if ((options & PCRE_NO_START_OPTIMIZE) == 0)
4760      {      {
4761      if (first_byte_caseless)      /* Advance to a unique first byte if there is one. */
       while (start_match < end_subject &&  
              match_block.lcc[*start_match] != first_byte)  
         start_match++;  
     else  
       while (start_match < end_subject && *start_match != first_byte)  
         start_match++;  
     }  
4762    
4763    /* Or to just after \n for a multiline match if possible */      if (first_byte >= 0)
4764          {
4765          if (first_byte_caseless)
4766            while (start_match < end_subject && md->lcc[*start_match] != first_byte)
4767              start_match++;
4768          else
4769            while (start_match < end_subject && *start_match != first_byte)
4770              start_match++;
4771          }
4772    
4773    else if (startline)      /* Or to just after a linebreak for a multiline match */
4774      {  
4775      if (start_match > match_block.start_subject + start_offset)      else if (startline)
4776        {        {
4777        while (start_match < end_subject && start_match[-1] != NEWLINE)        if (start_match > md->start_subject + start_offset)
4778          start_match++;          {
4779    #ifdef SUPPORT_UTF8
4780            if (utf8)
4781              {
4782              while (start_match < end_subject && !WAS_NEWLINE(start_match))
4783                {
4784                start_match++;
4785                while(start_match < end_subject && (*start_match & 0xc0) == 0x80)
4786                  start_match++;
4787                }
4788              }
4789            else
4790    #endif
4791            while (start_match < end_subject && !WAS_NEWLINE(start_match))
4792              start_match++;
4793    
4794            /* If we have just passed a CR and the newline option is ANY or ANYCRLF,
4795            and we are now at a LF, advance the match position by one more character.
4796            */
4797    
4798            if (start_match[-1] == CHAR_CR &&
4799                 (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&
4800                 start_match < end_subject &&
4801                 *start_match == CHAR_NL)
4802              start_match++;
4803            }
4804        }        }
     }  
4805    
4806    /* Or to a non-unique first char after study */      /* Or to a non-unique first byte after study */
4807    
4808    else if (start_bits != NULL)      else if (start_bits != NULL)
     {  
     while (start_match < end_subject)