/[pcre]/code/branches/pcre16/pcre_compile.c
ViewVC logotype

Diff of /code/branches/pcre16/pcre_compile.c

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

code/trunk/pcre_compile.c revision 716 by ph10, Tue Oct 4 16:38:05 2011 UTC code/branches/pcre16/pcre_compile.c revision 781 by zherczeg, Sat Dec 3 07:58:30 2011 UTC
# Line 97  overrun before it actually does run off Line 97  overrun before it actually does run off
97    
98  #define WORK_SIZE_CHECK (COMPILE_WORK_SIZE - 100)  #define WORK_SIZE_CHECK (COMPILE_WORK_SIZE - 100)
99    
100    /* Private flags added to firstchar and reqchar. */
101    
102    #define REQ_CASELESS   0x10000000l      /* Indicates caselessness */
103    #define REQ_VARY       0x20000000l      /* Reqchar followed non-literal item */
104    
105  /* Table for handling escaped characters in the range '0'-'z'. Positive returns  /* Table for handling escaped characters in the range '0'-'z'. Positive returns
106  are simple data values; negative values are for special things like \d and so  are simple data values; negative values are for special things like \d and so
# Line 231  static const char posix_names[] = Line 235  static const char posix_names[] =
235    STRING_graph0 STRING_print0 STRING_punct0 STRING_space0    STRING_graph0 STRING_print0 STRING_punct0 STRING_space0
236    STRING_word0  STRING_xdigit;    STRING_word0  STRING_xdigit;
237    
238  static const uschar posix_name_lengths[] = {  static const pcre_uint8 posix_name_lengths[] = {
239    5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 6, 0 };    5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 6, 0 };
240    
241  /* Table of class bit maps for each POSIX class. Each class is formed from a  /* Table of class bit maps for each POSIX class. Each class is formed from a
# Line 266  substitutes must be in the order of the Line 270  substitutes must be in the order of the
270  both positive and negative cases. NULL means no substitute. */  both positive and negative cases. NULL means no substitute. */
271    
272  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
273  static const uschar *substitutes[] = {  static const pcre_uchar string_PNd[]  = {
274    (uschar *)"\\P{Nd}",    /* \D */    CHAR_BACKSLASH, CHAR_P, CHAR_LEFT_CURLY_BRACKET,
275    (uschar *)"\\p{Nd}",    /* \d */    CHAR_N, CHAR_d, CHAR_RIGHT_CURLY_BRACKET, '\0' };
276    (uschar *)"\\P{Xsp}",   /* \S */       /* NOTE: Xsp is Perl space */  static const pcre_uchar string_pNd[]  = {
277    (uschar *)"\\p{Xsp}",   /* \s */    CHAR_BACKSLASH, CHAR_p, CHAR_LEFT_CURLY_BRACKET,
278    (uschar *)"\\P{Xwd}",   /* \W */    CHAR_N, CHAR_d, CHAR_RIGHT_CURLY_BRACKET, '\0' };
279    (uschar *)"\\p{Xwd}"    /* \w */  static const pcre_uchar string_PXsp[] = {
280      CHAR_BACKSLASH, CHAR_P, CHAR_LEFT_CURLY_BRACKET,
281      CHAR_X, CHAR_s, CHAR_p, CHAR_RIGHT_CURLY_BRACKET, '\0' };
282    static const pcre_uchar string_pXsp[] = {
283      CHAR_BACKSLASH, CHAR_p, CHAR_LEFT_CURLY_BRACKET,
284      CHAR_X, CHAR_s, CHAR_p, CHAR_RIGHT_CURLY_BRACKET, '\0' };
285    static const pcre_uchar string_PXwd[] = {
286      CHAR_BACKSLASH, CHAR_P, CHAR_LEFT_CURLY_BRACKET,
287      CHAR_X, CHAR_w, CHAR_d, CHAR_RIGHT_CURLY_BRACKET, '\0' };
288    static const pcre_uchar string_pXwd[] = {
289      CHAR_BACKSLASH, CHAR_p, CHAR_LEFT_CURLY_BRACKET,
290      CHAR_X, CHAR_w, CHAR_d, CHAR_RIGHT_CURLY_BRACKET, '\0' };
291    
292    static const pcre_uchar *substitutes[] = {
293      string_PNd,           /* \D */
294      string_pNd,           /* \d */
295      string_PXsp,          /* \S */       /* NOTE: Xsp is Perl space */
296      string_pXsp,          /* \s */
297      string_PXwd,          /* \W */
298      string_pXwd           /* \w */
299  };  };
300    
301  static const uschar *posix_substitutes[] = {  static const pcre_uchar string_pL[] =   {
302    (uschar *)"\\p{L}",     /* alpha */    CHAR_BACKSLASH, CHAR_p, CHAR_LEFT_CURLY_BRACKET,
303    (uschar *)"\\p{Ll}",    /* lower */    CHAR_L, CHAR_RIGHT_CURLY_BRACKET, '\0' };
304    (uschar *)"\\p{Lu}",    /* upper */  static const pcre_uchar string_pLl[] =  {
305    (uschar *)"\\p{Xan}",   /* alnum */    CHAR_BACKSLASH, CHAR_p, CHAR_LEFT_CURLY_BRACKET,
306    NULL,                   /* ascii */    CHAR_L, CHAR_l, CHAR_RIGHT_CURLY_BRACKET, '\0' };
307    (uschar *)"\\h",        /* blank */  static const pcre_uchar string_pLu[] =  {
308    NULL,                   /* cntrl */    CHAR_BACKSLASH, CHAR_p, CHAR_LEFT_CURLY_BRACKET,
309    (uschar *)"\\p{Nd}",    /* digit */    CHAR_L, CHAR_u, CHAR_RIGHT_CURLY_BRACKET, '\0' };
310    NULL,                   /* graph */  static const pcre_uchar string_pXan[] = {
311    NULL,                   /* print */    CHAR_BACKSLASH, CHAR_p, CHAR_LEFT_CURLY_BRACKET,
312    NULL,                   /* punct */    CHAR_X, CHAR_a, CHAR_n, CHAR_RIGHT_CURLY_BRACKET, '\0' };
313    (uschar *)"\\p{Xps}",   /* space */    /* NOTE: Xps is POSIX space */  static const pcre_uchar string_h[] =    {
314    (uschar *)"\\p{Xwd}",   /* word */    CHAR_BACKSLASH, CHAR_h, '\0' };
315    NULL,                   /* xdigit */  static const pcre_uchar string_pXps[] = {
316      CHAR_BACKSLASH, CHAR_p, CHAR_LEFT_CURLY_BRACKET,
317      CHAR_X, CHAR_p, CHAR_s, CHAR_RIGHT_CURLY_BRACKET, '\0' };
318    static const pcre_uchar string_PL[] =   {
319      CHAR_BACKSLASH, CHAR_P, CHAR_LEFT_CURLY_BRACKET,
320      CHAR_L, CHAR_RIGHT_CURLY_BRACKET, '\0' };
321    static const pcre_uchar string_PLl[] =  {
322      CHAR_BACKSLASH, CHAR_P, CHAR_LEFT_CURLY_BRACKET,
323      CHAR_L, CHAR_l, CHAR_RIGHT_CURLY_BRACKET, '\0' };
324    static const pcre_uchar string_PLu[] =  {
325      CHAR_BACKSLASH, CHAR_P, CHAR_LEFT_CURLY_BRACKET,
326      CHAR_L, CHAR_u, CHAR_RIGHT_CURLY_BRACKET, '\0' };
327    static const pcre_uchar string_PXan[] = {
328      CHAR_BACKSLASH, CHAR_P, CHAR_LEFT_CURLY_BRACKET,
329      CHAR_X, CHAR_a, CHAR_n, CHAR_RIGHT_CURLY_BRACKET, '\0' };
330    static const pcre_uchar string_H[] =    {
331      CHAR_BACKSLASH, CHAR_H, '\0' };
332    static const pcre_uchar string_PXps[] = {
333      CHAR_BACKSLASH, CHAR_P, CHAR_LEFT_CURLY_BRACKET,
334      CHAR_X, CHAR_p, CHAR_s, CHAR_RIGHT_CURLY_BRACKET, '\0' };
335    
336    static const pcre_uchar *posix_substitutes[] = {
337      string_pL,            /* alpha */
338      string_pLl,           /* lower */
339      string_pLu,           /* upper */
340      string_pXan,          /* alnum */
341      NULL,                 /* ascii */
342      string_h,             /* blank */
343      NULL,                 /* cntrl */
344      string_pNd,           /* digit */
345      NULL,                 /* graph */
346      NULL,                 /* print */
347      NULL,                 /* punct */
348      string_pXps,          /* space */    /* NOTE: Xps is POSIX space */
349      string_pXwd,          /* word */
350      NULL,                 /* xdigit */
351    /* Negated cases */    /* Negated cases */
352    (uschar *)"\\P{L}",     /* ^alpha */    string_PL,            /* ^alpha */
353    (uschar *)"\\P{Ll}",    /* ^lower */    string_PLl,           /* ^lower */
354    (uschar *)"\\P{Lu}",    /* ^upper */    string_PLu,           /* ^upper */
355    (uschar *)"\\P{Xan}",   /* ^alnum */    string_PXan,          /* ^alnum */
356    NULL,                   /* ^ascii */    NULL,                 /* ^ascii */
357    (uschar *)"\\H",        /* ^blank */    string_H,             /* ^blank */
358    NULL,                   /* ^cntrl */    NULL,                 /* ^cntrl */
359    (uschar *)"\\P{Nd}",    /* ^digit */    string_PNd,           /* ^digit */
360    NULL,                   /* ^graph */    NULL,                 /* ^graph */
361    NULL,                   /* ^print */    NULL,                 /* ^print */
362    NULL,                   /* ^punct */    NULL,                 /* ^punct */
363    (uschar *)"\\P{Xps}",   /* ^space */   /* NOTE: Xps is POSIX space */    string_PXps,          /* ^space */   /* NOTE: Xps is POSIX space */
364    (uschar *)"\\P{Xwd}",   /* ^word */    string_PXwd,          /* ^word */
365    NULL                    /* ^xdigit */    NULL                  /* ^xdigit */
366  };  };
367  #define POSIX_SUBSIZE (sizeof(posix_substitutes)/sizeof(uschar *))  #define POSIX_SUBSIZE (sizeof(posix_substitutes) / sizeof(pcre_uchar *))
368  #endif  #endif
369    
370  #define STRING(a)  # a  #define STRING(a)  # a
# Line 410  static const char error_texts[] = Line 468  static const char error_texts[] =
468    "this version of PCRE is not compiled with PCRE_UCP support\0"    "this version of PCRE is not compiled with PCRE_UCP support\0"
469    "\\c must be followed by an ASCII character\0"    "\\c must be followed by an ASCII character\0"
470    "\\k is not followed by a braced, angle-bracketed, or quoted name\0"    "\\k is not followed by a braced, angle-bracketed, or quoted name\0"
471      /* 70 */
472      "internal error: unknown opcode in find_fixedlength()\0"
473      "Not allowed UTF-8 / UTF-16 code point (>= 0xd800 && <= 0xdfff)\0"
474    ;    ;
475    
476  /* Table to identify digits and hex digits. This is used when compiling  /* Table to identify digits and hex digits. This is used when compiling
# Line 428  For convenience, we use the same bit def Line 489  For convenience, we use the same bit def
489    
490  Then we can use ctype_digit and ctype_xdigit in the code. */  Then we can use ctype_digit and ctype_xdigit in the code. */
491    
492    /* Using a simple comparison for decimal numbers rather than a memory read
493    is much faster, and the resulting code is simpler (the compiler turns it
494    into a subtraction and unsigned comparison). */
495    
496    #define IS_DIGIT(x) ((x) >= CHAR_0 && (x) <= CHAR_9)
497    
498  #ifndef EBCDIC  #ifndef EBCDIC
499    
500  /* This is the "normal" case, for ASCII systems, and EBCDIC systems running in  /* This is the "normal" case, for ASCII systems, and EBCDIC systems running in
501  UTF-8 mode. */  UTF-8 mode. */
502    
503  static const unsigned char digitab[] =  static const pcre_uint8 digitab[] =
504    {    {
505    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   0-  7 */    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   0-  7 */
506    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   8- 15 */    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   8- 15 */
# Line 472  static const unsigned char digitab[] = Line 539  static const unsigned char digitab[] =
539    
540  /* This is the "abnormal" case, for EBCDIC systems not running in UTF-8 mode. */  /* This is the "abnormal" case, for EBCDIC systems not running in UTF-8 mode. */
541    
542  static const unsigned char digitab[] =  static const pcre_uint8 digitab[] =
543    {    {
544    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   0-  7  0 */    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   0-  7  0 */
545    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   8- 15    */    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   8- 15    */
# Line 507  static const unsigned char digitab[] = Line 574  static const unsigned char digitab[] =
574    0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c, /*  0 - 7  F0 */    0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c, /*  0 - 7  F0 */
575    0x0c,0x0c,0x00,0x00,0x00,0x00,0x00,0x00};/*  8 -255    */    0x0c,0x0c,0x00,0x00,0x00,0x00,0x00,0x00};/*  8 -255    */
576    
577  static const unsigned char ebcdic_chartab[] = { /* chartable partial dup */  static const pcre_uint8 ebcdic_chartab[] = { /* chartable partial dup */
578    0x80,0x00,0x00,0x00,0x00,0x01,0x00,0x00, /*   0-  7 */    0x80,0x00,0x00,0x00,0x00,0x01,0x00,0x00, /*   0-  7 */
579    0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00, /*   8- 15 */    0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00, /*   8- 15 */
580    0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00, /*  16- 23 */    0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00, /*  16- 23 */
# Line 546  static const unsigned char ebcdic_charta Line 613  static const unsigned char ebcdic_charta
613  /* Definition to allow mutual recursion */  /* Definition to allow mutual recursion */
614    
615  static BOOL  static BOOL
616    compile_regex(int, uschar **, const uschar **, int *, BOOL, BOOL, int, int,    compile_regex(int, pcre_uchar **, const pcre_uchar **, int *, BOOL, BOOL, int, int,
617      int *, int *, branch_chain *, compile_data *, int *);      int *, int *, branch_chain *, compile_data *, int *);
618    
619    
# Line 593  Returns:    TRUE or FALSE Line 660  Returns:    TRUE or FALSE
660  */  */
661    
662  static BOOL  static BOOL
663  is_counted_repeat(const uschar *p)  is_counted_repeat(const pcre_uchar *p)
664  {  {
665  if ((digitab[*p++] & ctype_digit) == 0) return FALSE;  if (!IS_DIGIT(*p)) return FALSE;
666  while ((digitab[*p] & ctype_digit) != 0) p++;  p++;
667    while (IS_DIGIT(*p)) p++;
668  if (*p == CHAR_RIGHT_CURLY_BRACKET) return TRUE;  if (*p == CHAR_RIGHT_CURLY_BRACKET) return TRUE;
669    
670  if (*p++ != CHAR_COMMA) return FALSE;  if (*p++ != CHAR_COMMA) return FALSE;
671  if (*p == CHAR_RIGHT_CURLY_BRACKET) return TRUE;  if (*p == CHAR_RIGHT_CURLY_BRACKET) return TRUE;
672    
673  if ((digitab[*p++] & ctype_digit) == 0) return FALSE;  if (!IS_DIGIT(*p)) return FALSE;
674  while ((digitab[*p] & ctype_digit) != 0) p++;  p++;
675    while (IS_DIGIT(*p)) p++;
676    
677  return (*p == CHAR_RIGHT_CURLY_BRACKET);  return (*p == CHAR_RIGHT_CURLY_BRACKET);
678  }  }
# Line 635  Returns:         zero or positive => a d Line 704  Returns:         zero or positive => a d
704  */  */
705    
706  static int  static int
707  check_escape(const uschar **ptrptr, int *errorcodeptr, int bracount,  check_escape(const pcre_uchar **ptrptr, int *errorcodeptr, int bracount,
708    int options, BOOL isclass)    int options, BOOL isclass)
709  {  {
710  BOOL utf8 = (options & PCRE_UTF8) != 0;  /* PCRE_UTF16 has the same value as PCRE_UTF8. */
711  const uschar *ptr = *ptrptr + 1;  BOOL utf = (options & PCRE_UTF8) != 0;
712  int c, i;  const pcre_uchar *ptr = *ptrptr + 1;
713    pcre_int32 c;
714    int i;
715    
716  GETCHARINCTEST(c, ptr);           /* Get character value, increment pointer */  GETCHARINCTEST(c, ptr);           /* Get character value, increment pointer */
717  ptr--;                            /* Set pointer back to the last byte */  ptr--;                            /* Set pointer back to the last byte */
# Line 654  in a table. A non-zero result is somethi Line 725  in a table. A non-zero result is somethi
725  Otherwise further processing may be required. */  Otherwise further processing may be required. */
726    
727  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
728  else if (c < CHAR_0 || c > CHAR_z) {}                     /* Not alphanumeric */  /* Not alphanumeric */
729    else if (c < CHAR_0 || c > CHAR_z) {}
730  else if ((i = escapes[c - CHAR_0]) != 0) c = i;  else if ((i = escapes[c - CHAR_0]) != 0) c = i;
731    
732  #else           /* EBCDIC coding */  #else           /* EBCDIC coding */
733  else if (c < 'a' || (ebcdic_chartab[c] & 0x0E) == 0) {}   /* Not alphanumeric */  /* Not alphanumeric */
734    else if (c < 'a' || (!MAX_255(c) || (ebcdic_chartab[c] & 0x0E) == 0)) {}
735  else if ((i = escapes[c - 0x48]) != 0)  c = i;  else if ((i = escapes[c - 0x48]) != 0)  c = i;
736  #endif  #endif
737    
# Line 666  else if ((i = escapes[c - 0x48]) != 0) Line 739  else if ((i = escapes[c - 0x48]) != 0)
739    
740  else  else
741    {    {
742    const uschar *oldptr;    const pcre_uchar *oldptr;
743    BOOL braced, negated;    BOOL braced, negated;
744    
745    switch (c)    switch (c)
# Line 676  else Line 749  else
749    
750      case CHAR_l:      case CHAR_l:
751      case CHAR_L:      case CHAR_L:
752        *errorcodeptr = ERR37;
753        break;
754    
755      case CHAR_u:      case CHAR_u:
756        if ((options & PCRE_JAVASCRIPT_COMPAT) != 0)
757          {
758          /* In JavaScript, \u must be followed by four hexadecimal numbers.
759          Otherwise it is a lowercase u letter. */
760          if (MAX_255(ptr[1]) && (digitab[ptr[1]] & ctype_xdigit) != 0
761            && MAX_255(ptr[2]) && (digitab[ptr[2]] & ctype_xdigit) != 0
762            && MAX_255(ptr[3]) && (digitab[ptr[3]] & ctype_xdigit) != 0
763            && MAX_255(ptr[4]) && (digitab[ptr[4]] & ctype_xdigit) != 0)
764            {
765            c = 0;
766            for (i = 0; i < 4; ++i)
767              {
768              register int cc = *(++ptr);
769    #ifndef EBCDIC  /* ASCII/UTF-8 coding */
770              if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
771              c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));
772    #else           /* EBCDIC coding */
773              if (cc >= CHAR_a && cc <= CHAR_z) cc += 64;  /* Convert to upper case */
774              c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));
775    #endif
776              }
777            }
778          }
779        else
780          *errorcodeptr = ERR37;
781        break;
782    
783      case CHAR_U:      case CHAR_U:
784      *errorcodeptr = ERR37;      /* In JavaScript, \U is an uppercase U letter. */
785        if ((options & PCRE_JAVASCRIPT_COMPAT) == 0) *errorcodeptr = ERR37;
786      break;      break;
787    
788      /* In a character class, \g is just a literal "g". Outside a character      /* In a character class, \g is just a literal "g". Outside a character
# Line 710  else Line 814  else
814    
815      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)
816        {        {
817        const uschar *p;        const pcre_uchar *p;
818        for (p = ptr+2; *p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET; p++)        for (p = ptr+2; *p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET; p++)
819          if (*p != CHAR_MINUS && (digitab[*p] & ctype_digit) == 0) break;          if (*p != CHAR_MINUS && !IS_DIGIT(*p)) break;
820        if (*p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET)        if (*p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET)
821          {          {
822          c = -ESC_k;          c = -ESC_k;
# Line 730  else Line 834  else
834        }        }
835      else negated = FALSE;      else negated = FALSE;
836    
837        /* The integer range is limited by the machine's int representation. */
838      c = 0;      c = 0;
839      while ((digitab[ptr[1]] & ctype_digit) != 0)      while (IS_DIGIT(ptr[1]))
840          {
841          if (((unsigned int)c) > INT_MAX / 10) /* Integer overflow */
842            {
843            c = -1;
844            break;
845            }
846        c = c * 10 + *(++ptr) - CHAR_0;        c = c * 10 + *(++ptr) - CHAR_0;
847          }
848      if (c < 0)   /* Integer overflow */      if (((unsigned int)c) > INT_MAX) /* Integer overflow */
849        {        {
850          while (IS_DIGIT(ptr[1]))
851            ptr++;
852        *errorcodeptr = ERR61;        *errorcodeptr = ERR61;
853        break;        break;
854        }        }
# Line 783  else Line 896  else
896      if (!isclass)      if (!isclass)
897        {        {
898        oldptr = ptr;        oldptr = ptr;
899          /* The integer range is limited by the machine's int representation. */
900        c -= CHAR_0;        c -= CHAR_0;
901        while ((digitab[ptr[1]] & ctype_digit) != 0)        while (IS_DIGIT(ptr[1]))
902            {
903            if (((unsigned int)c) > INT_MAX / 10) /* Integer overflow */
904              {
905              c = -1;
906              break;
907              }
908          c = c * 10 + *(++ptr) - CHAR_0;          c = c * 10 + *(++ptr) - CHAR_0;
909        if (c < 0)    /* Integer overflow */          }
910          if (((unsigned int)c) > INT_MAX) /* Integer overflow */
911          {          {
912            while (IS_DIGIT(ptr[1]))
913              ptr++;
914          *errorcodeptr = ERR61;          *errorcodeptr = ERR61;
915          break;          break;
916          }          }
# Line 820  else Line 943  else
943      c -= CHAR_0;      c -= CHAR_0;
944      while(i++ < 2 && ptr[1] >= CHAR_0 && ptr[1] <= CHAR_7)      while(i++ < 2 && ptr[1] >= CHAR_0 && ptr[1] <= CHAR_7)
945          c = c * 8 + *(++ptr) - CHAR_0;          c = c * 8 + *(++ptr) - CHAR_0;
946      if (!utf8 && c > 255) *errorcodeptr = ERR51;      if (!utf && c > 0xff) *errorcodeptr = ERR51;
947      break;      break;
948    
949      /* \x is complicated. \x{ddd} is a character number which can be greater      /* \x is complicated. \x{ddd} is a character number which can be greater
950      than 0xff in utf8 mode, but only if the ddd are hex digits. If not, { is      than 0xff in utf or non-8bit mode, but only if the ddd are hex digits.
951      treated as a data character. */      If not, { is treated as a data character. */
952    
953      case CHAR_x:      case CHAR_x:
954        if ((options & PCRE_JAVASCRIPT_COMPAT) != 0)
955          {
956          /* In JavaScript, \x must be followed by two hexadecimal numbers.
957          Otherwise it is a lowercase x letter. */
958          if (MAX_255(ptr[1]) && (digitab[ptr[1]] & ctype_xdigit) != 0
959            && MAX_255(ptr[2]) && (digitab[ptr[2]] & ctype_xdigit) != 0)
960            {
961            c = 0;
962            for (i = 0; i < 2; ++i)
963              {
964              register int cc = *(++ptr);
965    #ifndef EBCDIC  /* ASCII/UTF-8 coding */
966              if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
967              c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));
968    #else           /* EBCDIC coding */
969              if (cc >= CHAR_a && cc <= CHAR_z) cc += 64;  /* Convert to upper case */
970              c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));
971    #endif
972              }
973            }
974          break;
975          }
976    
977      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)
978        {        {
979        const uschar *pt = ptr + 2;        const pcre_uchar *pt = ptr + 2;
       int count = 0;  
980    
981        c = 0;        c = 0;
982        while ((digitab[*pt] & ctype_xdigit) != 0)        while (MAX_255(*pt) && (digitab[*pt] & ctype_xdigit) != 0)
983          {          {
984          register int cc = *pt++;          register int cc = *pt++;
985          if (c == 0 && cc == CHAR_0) continue;     /* Leading zeroes */          if (c == 0 && cc == CHAR_0) continue;     /* Leading zeroes */
         count++;  
986    
987  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
988          if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */          if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
# Line 847  else Line 991  else
991          if (cc >= CHAR_a && cc <= CHAR_z) cc += 64;  /* Convert to upper case */          if (cc >= CHAR_a && cc <= CHAR_z) cc += 64;  /* Convert to upper case */
992          c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));          c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));
993  #endif  #endif
994    
995    #ifdef COMPILE_PCRE8
996            if (c > (utf ? 0x10ffff : 0xff)) { c = -1; break; }
997    #else
998    #ifdef COMPILE_PCRE16
999            if (c > (utf ? 0x10ffff : 0xffff)) { c = -1; break; }
1000    #endif
1001    #endif
1002            }
1003    
1004          if (c < 0)
1005            {
1006            while (MAX_255(*pt) && (digitab[*pt] & ctype_xdigit) != 0) pt++;
1007            *errorcodeptr = ERR34;
1008          }          }
1009    
1010        if (*pt == CHAR_RIGHT_CURLY_BRACKET)        if (*pt == CHAR_RIGHT_CURLY_BRACKET)
1011          {          {
1012          if (c < 0 || count > (utf8? 8 : 2)) *errorcodeptr = ERR34;          if (utf && c >= 0xd800 && c <= 0xdfff) *errorcodeptr = ERR71;
1013          ptr = pt;          ptr = pt;
1014          break;          break;
1015          }          }
# Line 863  else Line 1021  else
1021      /* Read just a single-byte hex-defined char */      /* Read just a single-byte hex-defined char */
1022    
1023      c = 0;      c = 0;
1024      while (i++ < 2 && (digitab[ptr[1]] & ctype_xdigit) != 0)      while (i++ < 2 && MAX_255(ptr[1]) && (digitab[ptr[1]] & ctype_xdigit) != 0)
1025        {        {
1026        int cc;                                  /* Some compilers don't like */        int cc;                                  /* Some compilers don't like */
1027        cc = *(++ptr);                           /* ++ in initializers */        cc = *(++ptr);                           /* ++ in initializers */
# Line 961  Returns:         type value from ucp_typ Line 1119  Returns:         type value from ucp_typ
1119  */  */
1120    
1121  static int  static int
1122  get_ucp(const uschar **ptrptr, BOOL *negptr, int *dptr, int *errorcodeptr)  get_ucp(const pcre_uchar **ptrptr, BOOL *negptr, int *dptr, int *errorcodeptr)
1123  {  {
1124  int c, i, bot, top;  int c, i, bot, top;
1125  const uschar *ptr = *ptrptr;  const pcre_uchar *ptr = *ptrptr;
1126  char name[32];  pcre_uchar name[32];
1127    
1128  c = *(++ptr);  c = *(++ptr);
1129  if (c == 0) goto ERROR_RETURN;  if (c == 0) goto ERROR_RETURN;
# Line 1006  else Line 1164  else
1164  /* Search for a recognized property name using binary chop */  /* Search for a recognized property name using binary chop */
1165    
1166  bot = 0;  bot = 0;
1167  top = _pcre_utt_size;  top = PRIV(utt_size);
1168    
1169  while (bot < top)  while (bot < top)
1170    {    {
1171    i = (bot + top) >> 1;    i = (bot + top) >> 1;
1172    c = strcmp(name, _pcre_utt_names + _pcre_utt[i].name_offset);    c = STRCMP_UC_C8(name, PRIV(utt_names) + PRIV(utt)[i].name_offset);
1173    if (c == 0)    if (c == 0)
1174      {      {
1175      *dptr = _pcre_utt[i].value;      *dptr = PRIV(utt)[i].value;
1176      return _pcre_utt[i].type;      return PRIV(utt)[i].type;
1177      }      }
1178    if (c > 0) bot = i + 1; else top = i;    if (c > 0) bot = i + 1; else top = i;
1179    }    }
# Line 1053  Returns:         pointer to '}' on succe Line 1211  Returns:         pointer to '}' on succe
1211                   current ptr on error, with errorcodeptr set non-zero                   current ptr on error, with errorcodeptr set non-zero
1212  */  */
1213    
1214  static const uschar *  static const pcre_uchar *
1215  read_repeat_counts(const uschar *p, int *minp, int *maxp, int *errorcodeptr)  read_repeat_counts(const pcre_uchar *p, int *minp, int *maxp, int *errorcodeptr)
1216  {  {
1217  int min = 0;  int min = 0;
1218  int max = -1;  int max = -1;
# Line 1062  int max = -1; Line 1220  int max = -1;
1220  /* Read the minimum value and do a paranoid check: a negative value indicates  /* Read the minimum value and do a paranoid check: a negative value indicates
1221  an integer overflow. */  an integer overflow. */
1222    
1223  while ((digitab[*p] & ctype_digit) != 0) min = min * 10 + *p++ - CHAR_0;  while (IS_DIGIT(*p)) min = min * 10 + *p++ - CHAR_0;
1224  if (min < 0 || min > 65535)  if (min < 0 || min > 65535)
1225    {    {
1226    *errorcodeptr = ERR5;    *errorcodeptr = ERR5;
# Line 1077  if (*p == CHAR_RIGHT_CURLY_BRACKET) max Line 1235  if (*p == CHAR_RIGHT_CURLY_BRACKET) max
1235    if (*(++p) != CHAR_RIGHT_CURLY_BRACKET)    if (*(++p) != CHAR_RIGHT_CURLY_BRACKET)
1236      {      {
1237      max = 0;      max = 0;
1238      while((digitab[*p] & ctype_digit) != 0) max = max * 10 + *p++ - CHAR_0;      while(IS_DIGIT(*p)) max = max * 10 + *p++ - CHAR_0;
1239      if (max < 0 || max > 65535)      if (max < 0 || max > 65535)
1240        {        {
1241        *errorcodeptr = ERR5;        *errorcodeptr = ERR5;
# Line 1132  Arguments: Line 1290  Arguments:
1290    name         name to seek, or NULL if seeking a numbered subpattern    name         name to seek, or NULL if seeking a numbered subpattern
1291    lorn         name length, or subpattern number if name is NULL    lorn         name length, or subpattern number if name is NULL
1292    xmode        TRUE if we are in /x mode    xmode        TRUE if we are in /x mode
1293    utf8         TRUE if we are in UTF-8 mode    utf          TRUE if we are in UTF-8 / UTF-16 mode
1294    count        pointer to the current capturing subpattern number (updated)    count        pointer to the current capturing subpattern number (updated)
1295    
1296  Returns:       the number of the named subpattern, or -1 if not found  Returns:       the number of the named subpattern, or -1 if not found
1297  */  */
1298    
1299  static int  static int
1300  find_parens_sub(uschar **ptrptr, compile_data *cd, const uschar *name, int lorn,  find_parens_sub(pcre_uchar **ptrptr, compile_data *cd, const pcre_uchar *name, int lorn,
1301    BOOL xmode, BOOL utf8, int *count)    BOOL xmode, BOOL utf, int *count)
1302  {  {
1303  uschar *ptr = *ptrptr;  pcre_uchar *ptr = *ptrptr;
1304  int start_count = *count;  int start_count = *count;
1305  int hwm_count = start_count;  int hwm_count = start_count;
1306  BOOL dup_parens = FALSE;  BOOL dup_parens = FALSE;
# Line 1209  if (ptr[0] == CHAR_LEFT_PARENTHESIS) Line 1367  if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1367          ptr[1] != CHAR_EQUALS_SIGN) || *ptr == CHAR_APOSTROPHE)          ptr[1] != CHAR_EQUALS_SIGN) || *ptr == CHAR_APOSTROPHE)
1368        {        {
1369        int term;        int term;
1370        const uschar *thisname;        const pcre_uchar *thisname;
1371        *count += 1;        *count += 1;
1372        if (name == NULL && *count == lorn) return *count;        if (name == NULL && *count == lorn) return *count;
1373        term = *ptr++;        term = *ptr++;
# Line 1217  if (ptr[0] == CHAR_LEFT_PARENTHESIS) Line 1375  if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1375        thisname = ptr;        thisname = ptr;
1376        while (*ptr != term) ptr++;        while (*ptr != term) ptr++;
1377        if (name != NULL && lorn == ptr - thisname &&        if (name != NULL && lorn == ptr - thisname &&
1378            strncmp((const char *)name, (const char *)thisname, lorn) == 0)            STRNCMP_UC_UC(name, thisname, lorn) == 0)
1379          return *count;          return *count;
1380        term++;        term++;
1381        }        }
# Line 1260  for (; ptr < cd->end_pattern; ptr++) Line 1418  for (; ptr < cd->end_pattern; ptr++)
1418          {          {
1419          if (ptr[2] == CHAR_E)          if (ptr[2] == CHAR_E)
1420            ptr+= 2;            ptr+= 2;
1421          else if (strncmp((const char *)ptr+2,          else if (STRNCMP_UC_C8(ptr + 2,
1422                   STR_Q STR_BACKSLASH STR_E, 3) == 0)                   STR_Q STR_BACKSLASH STR_E, 3) == 0)
1423            ptr += 4;            ptr += 4;
1424          else          else
# Line 1309  for (; ptr < cd->end_pattern; ptr++) Line 1467  for (; ptr < cd->end_pattern; ptr++)
1467        if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }        if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }
1468        ptr++;        ptr++;
1469  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1470        if (utf8) while ((*ptr & 0xc0) == 0x80) ptr++;        if (utf) while ((*ptr & 0xc0) == 0x80) ptr++;
1471  #endif  #endif
1472        }        }
1473      if (*ptr == 0) goto FAIL_EXIT;      if (*ptr == 0) goto FAIL_EXIT;
# Line 1320  for (; ptr < cd->end_pattern; ptr++) Line 1478  for (; ptr < cd->end_pattern; ptr++)
1478    
1479    if (*ptr == CHAR_LEFT_PARENTHESIS)    if (*ptr == CHAR_LEFT_PARENTHESIS)
1480      {      {
1481      int rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf8, count);      int rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf, count);
1482      if (rc > 0) return rc;      if (rc > 0) return rc;
1483      if (*ptr == 0) goto FAIL_EXIT;      if (*ptr == 0) goto FAIL_EXIT;
1484      }      }
# Line 1366  Arguments: Line 1524  Arguments:
1524    name         name to seek, or NULL if seeking a numbered subpattern    name         name to seek, or NULL if seeking a numbered subpattern
1525    lorn         name length, or subpattern number if name is NULL    lorn         name length, or subpattern number if name is NULL
1526    xmode        TRUE if we are in /x mode    xmode        TRUE if we are in /x mode
1527    utf8         TRUE if we are in UTF-8 mode    utf          TRUE if we are in UTF-8 / UTF-16 mode
1528    
1529  Returns:       the number of the found subpattern, or -1 if not found  Returns:       the number of the found subpattern, or -1 if not found
1530  */  */
1531    
1532  static int  static int
1533  find_parens(compile_data *cd, const uschar *name, int lorn, BOOL xmode,  find_parens(compile_data *cd, const pcre_uchar *name, int lorn, BOOL xmode,
1534    BOOL utf8)    BOOL utf)
1535  {  {
1536  uschar *ptr = (uschar *)cd->start_pattern;  pcre_uchar *ptr = (pcre_uchar *)cd->start_pattern;
1537  int count = 0;  int count = 0;
1538  int rc;  int rc;
1539    
# Line 1386  matching closing parens. That is why we Line 1544  matching closing parens. That is why we
1544    
1545  for (;;)  for (;;)
1546    {    {
1547    rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf8, &count);    rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf, &count);
1548    if (rc > 0 || *ptr++ == 0) break;    if (rc > 0 || *ptr++ == 0) break;
1549    }    }
1550    
# Line 1413  Arguments: Line 1571  Arguments:
1571  Returns:       pointer to the first significant opcode  Returns:       pointer to the first significant opcode
1572  */  */
1573    
1574  static const uschar*  static const pcre_uchar*
1575  first_significant_code(const uschar *code, BOOL skipassert)  first_significant_code(const pcre_uchar *code, BOOL skipassert)
1576  {  {
1577  for (;;)  for (;;)
1578    {    {
# Line 1425  for (;;) Line 1583  for (;;)
1583      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
1584      if (!skipassert) return code;      if (!skipassert) return code;
1585      do code += GET(code, 1); while (*code == OP_ALT);      do code += GET(code, 1); while (*code == OP_ALT);
1586      code += _pcre_OP_lengths[*code];      code += PRIV(OP_lengths)[*code];
1587      break;      break;
1588    
1589      case OP_WORD_BOUNDARY:      case OP_WORD_BOUNDARY:
# Line 1439  for (;;) Line 1597  for (;;)
1597      case OP_RREF:      case OP_RREF:
1598      case OP_NRREF:      case OP_NRREF:
1599      case OP_DEF:      case OP_DEF:
1600      code += _pcre_OP_lengths[*code];      code += PRIV(OP_lengths)[*code];
1601      break;      break;
1602    
1603      default:      default:
# Line 1469  and doing the check at the end; a flag s Line 1627  and doing the check at the end; a flag s
1627    
1628  Arguments:  Arguments:
1629    code     points to the start of the pattern (the bracket)    code     points to the start of the pattern (the bracket)
1630    utf8     TRUE in UTF-8 mode    utf      TRUE in UTF-8 / UTF-16 mode
1631    atend    TRUE if called when the pattern is complete    atend    TRUE if called when the pattern is complete
1632    cd       the "compile data" structure    cd       the "compile data" structure
1633    
1634  Returns:   the fixed length,  Returns:   the fixed length,
1635               or -1 if there is no fixed length,               or -1 if there is no fixed length,
1636               or -2 if \C was encountered               or -2 if \C was encountered (in UTF-8 mode only)
1637               or -3 if an OP_RECURSE item was encountered and atend is FALSE               or -3 if an OP_RECURSE item was encountered and atend is FALSE
1638                 or -4 if an unknown opcode was encountered (internal error)
1639  */  */
1640    
1641  static int  static int
1642  find_fixedlength(uschar *code, BOOL utf8, BOOL atend, compile_data *cd)  find_fixedlength(pcre_uchar *code, BOOL utf, BOOL atend, compile_data *cd)
1643  {  {
1644  int length = -1;  int length = -1;
1645    
1646  register int branchlength = 0;  register int branchlength = 0;
1647  register uschar *cc = code + 1 + LINK_SIZE;  register pcre_uchar *cc = code + 1 + LINK_SIZE;
1648    
1649  /* Scan along the opcodes for this branch. If we get to the end of the  /* Scan along the opcodes for this branch. If we get to the end of the
1650  branch, check the length against that of the other branches. */  branch, check the length against that of the other branches. */
# Line 1493  branch, check the length against that of Line 1652  branch, check the length against that of
1652  for (;;)  for (;;)
1653    {    {
1654    int d;    int d;
1655    uschar *ce, *cs;    pcre_uchar *ce, *cs;
1656    register int op = *cc;    register int op = *cc;
1657    switch (op)    switch (op)
1658      {      {
1659      /* We only need to continue for OP_CBRA (normal capturing bracket) and      /* We only need to continue for OP_CBRA (normal capturing bracket) and
1660      OP_BRA (normal non-capturing bracket) because the other variants of these      OP_BRA (normal non-capturing bracket) because the other variants of these
1661      opcodes are all concerned with unlimited repeated groups, which of course      opcodes are all concerned with unlimited repeated groups, which of course
1662      are not of fixed length. They will cause a -1 response from the default      are not of fixed length. */
     case of this switch. */  
1663    
1664      case OP_CBRA:      case OP_CBRA:
1665      case OP_BRA:      case OP_BRA:
1666      case OP_ONCE:      case OP_ONCE:
1667        case OP_ONCE_NC:
1668      case OP_COND:      case OP_COND:
1669      d = find_fixedlength(cc + ((op == OP_CBRA)? 2:0), utf8, atend, cd);      d = find_fixedlength(cc + ((op == OP_CBRA)? IMM2_SIZE : 0), utf, atend, cd);
1670      if (d < 0) return d;      if (d < 0) return d;
1671      branchlength += d;      branchlength += d;
1672      do cc += GET(cc, 1); while (*cc == OP_ALT);      do cc += GET(cc, 1); while (*cc == OP_ALT);
1673      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1674      break;      break;
1675    
1676      /* Reached end of a branch; if it's a ket it is the end of a nested      /* Reached end of a branch; if it's a ket it is the end of a nested call.
1677      call. If it's ALT it is an alternation in a nested call. If it is      If it's ALT it is an alternation in a nested call. An ACCEPT is effectively
1678      END it's the end of the outer call. All can be handled by the same code.      an ALT. If it is END it's the end of the outer call. All can be handled by
1679      Note that we must not include the OP_KETRxxx opcodes here, because they      the same code. Note that we must not include the OP_KETRxxx opcodes here,
1680      all imply an unlimited repeat. */      because they all imply an unlimited repeat. */
1681    
1682      case OP_ALT:      case OP_ALT:
1683      case OP_KET:      case OP_KET:
1684      case OP_END:      case OP_END:
1685        case OP_ACCEPT:
1686        case OP_ASSERT_ACCEPT:
1687      if (length < 0) length = branchlength;      if (length < 0) length = branchlength;
1688        else if (length != branchlength) return -1;        else if (length != branchlength) return -1;
1689      if (*cc != OP_ALT) return length;      if (*cc != OP_ALT) return length;
# Line 1536  for (;;) Line 1697  for (;;)
1697    
1698      case OP_RECURSE:      case OP_RECURSE:
1699      if (!atend) return -3;      if (!atend) return -3;
1700      cs = ce = (uschar *)cd->start_code + GET(cc, 1);  /* Start subpattern */      cs = ce = (pcre_uchar *)cd->start_code + GET(cc, 1);  /* Start subpattern */
1701      do ce += GET(ce, 1); while (*ce == OP_ALT);       /* End subpattern */      do ce += GET(ce, 1); while (*ce == OP_ALT);           /* End subpattern */
1702      if (cc > cs && cc < ce) return -1;                /* Recursion */      if (cc > cs && cc < ce) return -1;                    /* Recursion */
1703      d = find_fixedlength(cs + 2, utf8, atend, cd);      d = find_fixedlength(cs + 2, utf, atend, cd);
1704      if (d < 0) return d;      if (d < 0) return d;
1705      branchlength += d;      branchlength += d;
1706      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
# Line 1556  for (;;) Line 1717  for (;;)
1717    
1718      /* Skip over things that don't match chars */      /* Skip over things that don't match chars */
1719    
1720      case OP_REVERSE:      case OP_MARK:
1721      case OP_CREF:      case OP_PRUNE_ARG:
1722      case OP_NCREF:      case OP_SKIP_ARG:
1723      case OP_RREF:      case OP_THEN_ARG:
1724      case OP_NRREF:      cc += cc[1] + PRIV(OP_lengths)[*cc];
1725      case OP_DEF:      break;
1726    
1727      case OP_CALLOUT:      case OP_CALLOUT:
     case OP_SOD:  
     case OP_SOM:  
     case OP_SET_SOM:  
     case OP_EOD:  
     case OP_EODN:  
1728      case OP_CIRC:      case OP_CIRC:
1729      case OP_CIRCM:      case OP_CIRCM:
1730        case OP_CLOSE:
1731        case OP_COMMIT:
1732        case OP_CREF:
1733        case OP_DEF:
1734      case OP_DOLL:      case OP_DOLL:
1735      case OP_DOLLM:      case OP_DOLLM:
1736        case OP_EOD:
1737        case OP_EODN:
1738        case OP_FAIL:
1739        case OP_NCREF:
1740        case OP_NRREF:
1741      case OP_NOT_WORD_BOUNDARY:      case OP_NOT_WORD_BOUNDARY:
1742        case OP_PRUNE:
1743        case OP_REVERSE:
1744        case OP_RREF:
1745        case OP_SET_SOM:
1746        case OP_SKIP:
1747        case OP_SOD:
1748        case OP_SOM:
1749        case OP_THEN:
1750      case OP_WORD_BOUNDARY:      case OP_WORD_BOUNDARY:
1751      cc += _pcre_OP_lengths[*cc];      cc += PRIV(OP_lengths)[*cc];
1752      break;      break;
1753    
1754      /* Handle literal characters */      /* Handle literal characters */
# Line 1586  for (;;) Line 1760  for (;;)
1760      branchlength++;      branchlength++;
1761      cc += 2;      cc += 2;
1762  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1763      if (utf8 && cc[-1] >= 0xc0) cc += _pcre_utf8_table4[cc[-1] & 0x3f];      if (utf && cc[-1] >= 0xc0) cc += PRIV(utf8_table4)[cc[-1] & 0x3f];
1764  #endif  #endif
1765      break;      break;
1766    
# Line 1594  for (;;) Line 1768  for (;;)
1768      need to skip over a multibyte character in UTF8 mode.  */      need to skip over a multibyte character in UTF8 mode.  */
1769    
1770      case OP_EXACT:      case OP_EXACT:
1771        case OP_EXACTI:
1772        case OP_NOTEXACT:
1773        case OP_NOTEXACTI:
1774      branchlength += GET2(cc,1);      branchlength += GET2(cc,1);
1775      cc += 4;      cc += 2 + IMM2_SIZE;
1776  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1777      if (utf8 && cc[-1] >= 0xc0) cc += _pcre_utf8_table4[cc[-1] & 0x3f];      if (utf && cc[-1] >= 0xc0) cc += PRIV(utf8_table4)[cc[-1] & 0x3f];
1778  #endif  #endif
1779      break;      break;
1780    
1781      case OP_TYPEEXACT:      case OP_TYPEEXACT:
1782      branchlength += GET2(cc,1);      branchlength += GET2(cc,1);
1783      if (cc[3] == OP_PROP || cc[3] == OP_NOTPROP) cc += 2;      if (cc[1 + IMM2_SIZE] == OP_PROP || cc[1 + IMM2_SIZE] == OP_NOTPROP) cc += 2;
1784      cc += 4;      cc += 1 + IMM2_SIZE + 1;
1785      break;      break;
1786    
1787      /* Handle single-char matchers */      /* Handle single-char matchers */
# Line 1614  for (;;) Line 1791  for (;;)
1791      cc += 2;      cc += 2;
1792      /* Fall through */      /* Fall through */
1793    
1794        case OP_HSPACE:
1795        case OP_VSPACE:
1796        case OP_NOT_HSPACE:
1797        case OP_NOT_VSPACE:
1798      case OP_NOT_DIGIT:      case OP_NOT_DIGIT:
1799      case OP_DIGIT:      case OP_DIGIT:
1800      case OP_NOT_WHITESPACE:      case OP_NOT_WHITESPACE:
# Line 1626  for (;;) Line 1807  for (;;)
1807      cc++;      cc++;
1808      break;      break;
1809    
1810      /* The single-byte matcher isn't allowed */      /* The single-byte matcher isn't allowed. This only happens in UTF-8 mode;
1811        otherwise \C is coded as OP_ALLANY. */
1812    
1813      case OP_ANYBYTE:      case OP_ANYBYTE:
1814      return -2;      return -2;
1815    
1816      /* Check a class for variable quantification */      /* Check a class for variable quantification */
1817    
1818  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || defined COMPILE_PCRE16
1819      case OP_XCLASS:      case OP_XCLASS:
1820      cc += GET(cc, 1) - 33;      cc += GET(cc, 1) - PRIV(OP_lengths)[OP_CLASS];
1821      /* Fall through */      /* Fall through */
1822  #endif  #endif
1823    
1824      case OP_CLASS:      case OP_CLASS:
1825      case OP_NCLASS:      case OP_NCLASS:
1826      cc += 33;      cc += PRIV(OP_lengths)[OP_CLASS];
1827    
1828      switch (*cc)      switch (*cc)
1829        {        {
1830          case OP_CRPLUS:
1831          case OP_CRMINPLUS:
1832        case OP_CRSTAR:        case OP_CRSTAR:
1833        case OP_CRMINSTAR:        case OP_CRMINSTAR:
1834        case OP_CRQUERY:        case OP_CRQUERY:
# Line 1653  for (;;) Line 1837  for (;;)
1837    
1838        case OP_CRRANGE:        case OP_CRRANGE:
1839        case OP_CRMINRANGE:        case OP_CRMINRANGE:
1840        if (GET2(cc,1) != GET2(cc,3)) return -1;        if (GET2(cc,1) != GET2(cc,1+IMM2_SIZE)) return -1;
1841        branchlength += GET2(cc,1);        branchlength += GET2(cc,1);
1842        cc += 5;        cc += 1 + 2 * IMM2_SIZE;
1843        break;        break;
1844    
1845        default:        default:
# Line 1665  for (;;) Line 1849  for (;;)
1849    
1850      /* Anything else is variable length */      /* Anything else is variable length */
1851    
1852      default:      case OP_ANYNL:
1853        case OP_BRAMINZERO:
1854        case OP_BRAPOS:
1855        case OP_BRAPOSZERO:
1856        case OP_BRAZERO:
1857        case OP_CBRAPOS:
1858        case OP_EXTUNI:
1859        case OP_KETRMAX:
1860        case OP_KETRMIN:
1861        case OP_KETRPOS:
1862        case OP_MINPLUS:
1863        case OP_MINPLUSI:
1864        case OP_MINQUERY:
1865        case OP_MINQUERYI:
1866        case OP_MINSTAR:
1867        case OP_MINSTARI:
1868        case OP_MINUPTO:
1869        case OP_MINUPTOI:
1870        case OP_NOTMINPLUS:
1871        case OP_NOTMINPLUSI:
1872        case OP_NOTMINQUERY:
1873        case OP_NOTMINQUERYI:
1874        case OP_NOTMINSTAR:
1875        case OP_NOTMINSTARI:
1876        case OP_NOTMINUPTO:
1877        case OP_NOTMINUPTOI:
1878        case OP_NOTPLUS:
1879        case OP_NOTPLUSI:
1880        case OP_NOTPOSPLUS:
1881        case OP_NOTPOSPLUSI:
1882        case OP_NOTPOSQUERY:
1883        case OP_NOTPOSQUERYI:
1884        case OP_NOTPOSSTAR:
1885        case OP_NOTPOSSTARI:
1886        case OP_NOTPOSUPTO:
1887        case OP_NOTPOSUPTOI:
1888        case OP_NOTQUERY:
1889        case OP_NOTQUERYI:
1890        case OP_NOTSTAR:
1891        case OP_NOTSTARI:
1892        case OP_NOTUPTO:
1893        case OP_NOTUPTOI:
1894        case OP_PLUS:
1895        case OP_PLUSI:
1896        case OP_POSPLUS:
1897        case OP_POSPLUSI:
1898        case OP_POSQUERY:
1899        case OP_POSQUERYI:
1900        case OP_POSSTAR:
1901        case OP_POSSTARI:
1902        case OP_POSUPTO:
1903        case OP_POSUPTOI:
1904        case OP_QUERY:
1905        case OP_QUERYI:
1906        case OP_REF:
1907        case OP_REFI:
1908        case OP_SBRA:
1909        case OP_SBRAPOS:
1910        case OP_SCBRA:
1911        case OP_SCBRAPOS:
1912        case OP_SCOND:
1913        case OP_SKIPZERO:
1914        case OP_STAR:
1915        case OP_STARI:
1916        case OP_TYPEMINPLUS:
1917        case OP_TYPEMINQUERY:
1918        case OP_TYPEMINSTAR:
1919        case OP_TYPEMINUPTO:
1920        case OP_TYPEPLUS:
1921        case OP_TYPEPOSPLUS:
1922        case OP_TYPEPOSQUERY:
1923        case OP_TYPEPOSSTAR:
1924        case OP_TYPEPOSUPTO:
1925        case OP_TYPEQUERY:
1926        case OP_TYPESTAR:
1927        case OP_TYPEUPTO:
1928        case OP_UPTO:
1929        case OP_UPTOI:
1930      return -1;      return -1;
1931    
1932        /* Catch unrecognized opcodes so that when new ones are added they
1933        are not forgotten, as has happened in the past. */
1934    
1935        default:
1936        return -4;
1937      }      }
1938    }    }
1939  /* Control never gets here */  /* Control never gets here */
# Line 1687  length. Line 1954  length.
1954    
1955  Arguments:  Arguments:
1956    code        points to start of expression    code        points to start of expression
1957    utf8        TRUE in UTF-8 mode    utf         TRUE in UTF-8 / UTF-16 mode
1958    number      the required bracket number or negative to find a lookbehind    number      the required bracket number or negative to find a lookbehind
1959    
1960  Returns:      pointer to the opcode for the bracket, or NULL if not found  Returns:      pointer to the opcode for the bracket, or NULL if not found
1961  */  */
1962    
1963  const uschar *  const pcre_uchar *
1964  _pcre_find_bracket(const uschar *code, BOOL utf8, int number)  PRIV(find_bracket)(const pcre_uchar *code, BOOL utf, int number)
1965  {  {
1966  for (;;)  for (;;)
1967    {    {
# Line 1712  for (;;) Line 1979  for (;;)
1979    
1980    else if (c == OP_REVERSE)    else if (c == OP_REVERSE)
1981      {      {
1982      if (number < 0) return (uschar *)code;      if (number < 0) return (pcre_uchar *)code;
1983      code += _pcre_OP_lengths[c];      code += PRIV(OP_lengths)[c];
1984      }      }
1985    
1986    /* Handle capturing bracket */    /* Handle capturing bracket */
# Line 1722  for (;;) Line 1989  for (;;)
1989             c == OP_CBRAPOS || c == OP_SCBRAPOS)             c == OP_CBRAPOS || c == OP_SCBRAPOS)
1990      {      {
1991      int n = GET2(code, 1+LINK_SIZE);      int n = GET2(code, 1+LINK_SIZE);
1992      if (n == number) return (uschar *)code;      if (n == number) return (pcre_uchar *)code;
1993      code += _pcre_OP_lengths[c];      code += PRIV(OP_lengths)[c];
1994      }      }
1995    
1996    /* Otherwise, we can get the item's length from the table, except that for    /* Otherwise, we can get the item's length from the table, except that for
# Line 1751  for (;;) Line 2018  for (;;)
2018        case OP_TYPEMINUPTO:        case OP_TYPEMINUPTO:
2019        case OP_TYPEEXACT:        case OP_TYPEEXACT:
2020        case OP_TYPEPOSUPTO:        case OP_TYPEPOSUPTO:
2021        if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2;        if (code[1 + IMM2_SIZE] == OP_PROP
2022            || code[1 + IMM2_SIZE] == OP_NOTPROP) code += 2;
2023        break;        break;
2024    
2025        case OP_MARK:        case OP_MARK:
# Line 1767  for (;;) Line 2035  for (;;)
2035    
2036      /* Add in the fixed length from the table */      /* Add in the fixed length from the table */
2037    
2038      code += _pcre_OP_lengths[c];      code += PRIV(OP_lengths)[c];
2039    
2040    /* In UTF-8 mode, opcodes that are followed by a character may be followed by    /* In UTF-8 mode, opcodes that are followed by a character may be followed by
2041    a multi-byte character. The length in the table is a minimum, so we have to    a multi-byte character. The length in the table is a minimum, so we have to
2042    arrange to skip the extra bytes. */    arrange to skip the extra bytes. */
2043    
2044  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2045      if (utf8) switch(c)      if (utf) switch(c)
2046        {        {
2047        case OP_CHAR:        case OP_CHAR:
2048        case OP_CHARI:        case OP_CHARI:
# Line 1804  for (;;) Line 2072  for (;;)
2072        case OP_MINQUERYI:        case OP_MINQUERYI:
2073        case OP_POSQUERY:        case OP_POSQUERY:
2074        case OP_POSQUERYI:        case OP_POSQUERYI:
2075        if (code[-1] >= 0xc0) code += _pcre_utf8_table4[code[-1] & 0x3f];        if (code[-1] >= 0xc0) code += PRIV(utf8_table4)[code[-1] & 0x3f];
2076        break;        break;
2077        }        }
2078  #else  #else
2079      (void)(utf8);  /* Keep compiler happy by referencing function argument */      (void)(utf);  /* Keep compiler happy by referencing function argument */
2080  #endif  #endif
2081      }      }
2082    }    }
# Line 1825  instance of OP_RECURSE. Line 2093  instance of OP_RECURSE.
2093    
2094  Arguments:  Arguments:
2095    code        points to start of expression    code        points to start of expression
2096    utf8        TRUE in UTF-8 mode    utf         TRUE in UTF-8 / UTF-16 mode
2097    
2098  Returns:      pointer to the opcode for OP_RECURSE, or NULL if not found  Returns:      pointer to the opcode for OP_RECURSE, or NULL if not found
2099  */  */
2100    
2101  static const uschar *  static const pcre_uchar *
2102  find_recurse(const uschar *code, BOOL utf8)  find_recurse(const pcre_uchar *code, BOOL utf)
2103  {  {
2104  for (;;)  for (;;)
2105    {    {
# Line 1870  for (;;) Line 2138  for (;;)
2138        case OP_TYPEUPTO:        case OP_TYPEUPTO:
2139        case OP_TYPEMINUPTO:        case OP_TYPEMINUPTO:
2140        case OP_TYPEEXACT:        case OP_TYPEEXACT:
2141        if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2;        if (code[1 + IMM2_SIZE] == OP_PROP
2142            || code[1 + IMM2_SIZE] == OP_NOTPROP) code += 2;
2143        break;        break;
2144    
2145        case OP_MARK:        case OP_MARK:
# Line 1886  for (;;) Line 2155  for (;;)
2155    
2156      /* Add in the fixed length from the table */      /* Add in the fixed length from the table */
2157    
2158      code += _pcre_OP_lengths[c];      code += PRIV(OP_lengths)[c];
2159    
2160      /* In UTF-8 mode, opcodes that are followed by a character may be followed      /* In UTF-8 mode, opcodes that are followed by a character may be followed
2161      by a multi-byte character. The length in the table is a minimum, so we have      by a multi-byte character. The length in the table is a minimum, so we have
2162      to arrange to skip the extra bytes. */      to arrange to skip the extra bytes. */
2163    
2164  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2165      if (utf8) switch(c)      if (utf) switch(c)
2166        {        {
2167        case OP_CHAR:        case OP_CHAR:
2168        case OP_CHARI:        case OP_CHARI:
# Line 1923  for (;;) Line 2192  for (;;)
2192        case OP_MINQUERYI:        case OP_MINQUERYI:
2193        case OP_POSQUERY:        case OP_POSQUERY:
2194        case OP_POSQUERYI:        case OP_POSQUERYI:
2195        if (code[-1] >= 0xc0) code += _pcre_utf8_table4[code[-1] & 0x3f];        if (code[-1] >= 0xc0) code += PRIV(utf8_table4)[code[-1] & 0x3f];
2196        break;        break;
2197        }        }
2198  #else  #else
2199      (void)(utf8);  /* Keep compiler happy by referencing function argument */      (void)(utf);  /* Keep compiler happy by referencing function argument */
2200  #endif  #endif
2201      }      }
2202    }    }
# Line 1950  bracket whose current branch will alread Line 2219  bracket whose current branch will alread
2219  Arguments:  Arguments:
2220    code        points to start of search    code        points to start of search
2221    endcode     points to where to stop    endcode     points to where to stop
2222    utf8        TRUE if in UTF8 mode    utf         TRUE if in UTF-8 / UTF-16 mode
2223    cd          contains pointers to tables etc.    cd          contains pointers to tables etc.
2224    
2225  Returns:      TRUE if what is matched could be empty  Returns:      TRUE if what is matched could be empty
2226  */  */
2227    
2228  static BOOL  static BOOL
2229  could_be_empty_branch(const uschar *code, const uschar *endcode, BOOL utf8,  could_be_empty_branch(const pcre_uchar *code, const pcre_uchar *endcode,
2230    compile_data *cd)    BOOL utf, compile_data *cd)
2231  {  {
2232  register int c;  register int c;
2233  for (code = first_significant_code(code + _pcre_OP_lengths[*code], TRUE);  for (code = first_significant_code(code + PRIV(OP_lengths)[*code], TRUE);
2234       code < endcode;       code < endcode;
2235       code = first_significant_code(code + _pcre_OP_lengths[c], TRUE))       code = first_significant_code(code + PRIV(OP_lengths)[c], TRUE))
2236    {    {
2237    const uschar *ccode;    const pcre_uchar *ccode;
2238    
2239    c = *code;    c = *code;
2240    
# Line 1988  for (code = first_significant_code(code Line 2257  for (code = first_significant_code(code
2257    
2258    if (c == OP_RECURSE)    if (c == OP_RECURSE)
2259      {      {
2260      const uschar *scode;      const pcre_uchar *scode;
2261      BOOL empty_branch;      BOOL empty_branch;
2262    
2263      /* Test for forward reference */      /* Test for forward reference */
# Line 2006  for (code = first_significant_code(code Line 2275  for (code = first_significant_code(code
2275    
2276      do      do
2277        {        {
2278        if (could_be_empty_branch(scode, endcode, utf8, cd))        if (could_be_empty_branch(scode, endcode, utf, cd))
2279          {          {
2280          empty_branch = TRUE;          empty_branch = TRUE;
2281          break;          break;
# Line 2024  for (code = first_significant_code(code Line 2293  for (code = first_significant_code(code
2293    if (c == OP_BRAZERO || c == OP_BRAMINZERO || c == OP_SKIPZERO ||    if (c == OP_BRAZERO || c == OP_BRAMINZERO || c == OP_SKIPZERO ||
2294        c == OP_BRAPOSZERO)        c == OP_BRAPOSZERO)
2295      {      {
2296      code += _pcre_OP_lengths[c];      code += PRIV(OP_lengths)[c];
2297      do code += GET(code, 1); while (*code == OP_ALT);      do code += GET(code, 1); while (*code == OP_ALT);
2298      c = *code;      c = *code;
2299      continue;      continue;
# Line 2045  for (code = first_significant_code(code Line 2314  for (code = first_significant_code(code
2314    
2315    if (c == OP_BRA  || c == OP_BRAPOS ||    if (c == OP_BRA  || c == OP_BRAPOS ||
2316        c == OP_CBRA || c == OP_CBRAPOS ||        c == OP_CBRA || c == OP_CBRAPOS ||
2317        c == OP_ONCE || c == OP_COND)        c == OP_ONCE || c == OP_ONCE_NC ||
2318          c == OP_COND)
2319      {      {
2320      BOOL empty_branch;      BOOL empty_branch;
2321      if (GET(code, 1) == 0) return TRUE;    /* Hit unclosed bracket */      if (GET(code, 1) == 0) return TRUE;    /* Hit unclosed bracket */
# Line 2061  for (code = first_significant_code(code Line 2331  for (code = first_significant_code(code
2331        empty_branch = FALSE;        empty_branch = FALSE;
2332        do        do
2333          {          {
2334          if (!empty_branch && could_be_empty_branch(code, endcode, utf8, cd))          if (!empty_branch && could_be_empty_branch(code, endcode, utf, cd))
2335            empty_branch = TRUE;            empty_branch = TRUE;
2336          code += GET(code, 1);          code += GET(code, 1);
2337          }          }
# Line 2079  for (code = first_significant_code(code Line 2349  for (code = first_significant_code(code
2349      {      {
2350      /* Check for quantifiers after a class. XCLASS is used for classes that      /* Check for quantifiers after a class. XCLASS is used for classes that
2351      cannot be represented just by a bit map. This includes negated single      cannot be represented just by a bit map. This includes negated single
2352      high-valued characters. The length in _pcre_OP_lengths[] is zero; the      high-valued characters. The length in PRIV(OP_lengths)[] is zero; the
2353      actual length is stored in the compiled code, so we must update "code"      actual length is stored in the compiled code, so we must update "code"
2354      here. */      here. */
2355    
# Line 2091  for (code = first_significant_code(code Line 2361  for (code = first_significant_code(code
2361    
2362      case OP_CLASS:      case OP_CLASS:
2363      case OP_NCLASS:      case OP_NCLASS:
2364      ccode = code + 33;      ccode = code + PRIV(OP_lengths)[OP_CLASS];
2365    
2366  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2367      CHECK_CLASS_REPEAT:      CHECK_CLASS_REPEAT:
# Line 2166  for (code = first_significant_code(code Line 2436  for (code = first_significant_code(code
2436      case OP_TYPEUPTO:      case OP_TYPEUPTO:
2437      case OP_TYPEMINUPTO:      case OP_TYPEMINUPTO:
2438      case OP_TYPEPOSUPTO:      case OP_TYPEPOSUPTO:
2439      if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2;      if (code[1 + IMM2_SIZE] == OP_PROP
2440          || code[1 + IMM2_SIZE] == OP_NOTPROP) code += 2;
2441      break;      break;
2442    
2443      /* End of branch */      /* End of branch */
# Line 2194  for (code = first_significant_code(code Line 2465  for (code = first_significant_code(code
2465      case OP_MINQUERYI:      case OP_MINQUERYI:
2466      case OP_POSQUERY:      case OP_POSQUERY:
2467      case OP_POSQUERYI:      case OP_POSQUERYI:
2468      if (utf8 && code[1] >= 0xc0) code += _pcre_utf8_table4[code[1] & 0x3f];      if (utf && code[1] >= 0xc0) code += PRIV(utf8_table4)[code[1] & 0x3f];
2469      break;      break;
2470    
2471      case OP_UPTO:      case OP_UPTO:
# Line 2203  for (code = first_significant_code(code Line 2474  for (code = first_significant_code(code
2474      case OP_MINUPTOI:      case OP_MINUPTOI:
2475      case OP_POSUPTO:      case OP_POSUPTO:
2476      case OP_POSUPTOI:      case OP_POSUPTOI:
2477      if (utf8 && code[3] >= 0xc0) code += _pcre_utf8_table4[code[3] & 0x3f];      if (utf && code[1 + IMM2_SIZE] >= 0xc0) code += PRIV(utf8_table4)[code[1 + IMM2_SIZE] & 0x3f];
2478      break;      break;
2479  #endif  #endif
2480    
# Line 2247  Arguments: Line 2518  Arguments:
2518    code        points to start of the recursion    code        points to start of the recursion
2519    endcode     points to where to stop (current RECURSE item)    endcode     points to where to stop (current RECURSE item)
2520    bcptr       points to the chain of current (unclosed) branch starts    bcptr       points to the chain of current (unclosed) branch starts
2521    utf8        TRUE if in UTF-8 mode    utf         TRUE if in UTF-8 / UTF-16 mode
2522    cd          pointers to tables etc    cd          pointers to tables etc
2523    
2524  Returns:      TRUE if what is matched could be empty  Returns:      TRUE if what is matched could be empty
2525  */  */
2526    
2527  static BOOL  static BOOL
2528  could_be_empty(const uschar *code, const uschar *endcode, branch_chain *bcptr,  could_be_empty(const pcre_uchar *code, const pcre_uchar *endcode,
2529    BOOL utf8, compile_data *cd)    branch_chain *bcptr, BOOL utf, compile_data *cd)
2530  {  {
2531  while (bcptr != NULL && bcptr->current_branch >= code)  while (bcptr != NULL && bcptr->current_branch >= code)
2532    {    {
2533    if (!could_be_empty_branch(bcptr->current_branch, endcode, utf8, cd))    if (!could_be_empty_branch(bcptr->current_branch, endcode, utf, cd))
2534      return FALSE;      return FALSE;
2535    bcptr = bcptr->outer;    bcptr = bcptr->outer;
2536    }    }
# Line 2311  Returns:   TRUE or FALSE Line 2582  Returns:   TRUE or FALSE
2582  */  */
2583    
2584  static BOOL  static BOOL
2585  check_posix_syntax(const uschar *ptr, const uschar **endptr)  check_posix_syntax(const pcre_uchar *ptr, const pcre_uchar **endptr)
2586  {  {
2587  int terminator;          /* Don't combine these lines; the Solaris cc */  int terminator;          /* Don't combine these lines; the Solaris cc */
2588  terminator = *(++ptr);   /* compiler warns about "non-constant" initializer. */  terminator = *(++ptr);   /* compiler warns about "non-constant" initializer. */
# Line 2355  Returns:     a value representing the na Line 2626  Returns:     a value representing the na
2626  */  */
2627    
2628  static int  static int
2629  check_posix_name(const uschar *ptr, int len)  check_posix_name(const pcre_uchar *ptr, int len)
2630  {  {
2631  const char *pn = posix_names;  const char *pn = posix_names;
2632  register int yield = 0;  register int yield = 0;
2633  while (posix_name_lengths[yield] != 0)  while (posix_name_lengths[yield] != 0)
2634    {    {
2635    if (len == posix_name_lengths[yield] &&    if (len == posix_name_lengths[yield] &&
2636      strncmp((const char *)ptr, pn, len) == 0) return yield;      STRNCMP_UC_C8(ptr, pn, len) == 0) return yield;
2637    pn += posix_name_lengths[yield] + 1;    pn += posix_name_lengths[yield] + 1;
2638    yield++;    yield++;
2639    }    }
# Line 2394  value in the reference (which is a group Line 2665  value in the reference (which is a group
2665  Arguments:  Arguments:
2666    group      points to the start of the group    group      points to the start of the group
2667    adjust     the amount by which the group is to be moved    adjust     the amount by which the group is to be moved
2668    utf8       TRUE in UTF-8 mode    utf        TRUE in UTF-8 / UTF-16 mode
2669    cd         contains pointers to tables etc.    cd         contains pointers to tables etc.
2670    save_hwm   the hwm forward reference pointer at the start of the group    save_hwm   the hwm forward reference pointer at the start of the group
2671    
# Line 2402  Returns:     nothing Line 2673  Returns:     nothing
2673  */  */
2674    
2675  static void  static void
2676  adjust_recurse(uschar *group, int adjust, BOOL utf8, compile_data *cd,  adjust_recurse(pcre_uchar *group, int adjust, BOOL utf, compile_data *cd,
2677    uschar *save_hwm)    pcre_uchar *save_hwm)
2678  {  {
2679  uschar *ptr = group;  pcre_uchar *ptr = group;
2680    
2681  while ((ptr = (uschar *)find_recurse(ptr, utf8)) != NULL)  while ((ptr = (pcre_uchar *)find_recurse(ptr, utf)) != NULL)
2682    {    {
2683    int offset;    int offset;
2684    uschar *hc;    pcre_uchar *hc;
2685    
2686    /* See if this recursion is on the forward reference list. If so, adjust the    /* See if this recursion is on the forward reference list. If so, adjust the
2687    reference. */    reference. */
# Line 2455  Arguments: Line 2726  Arguments:
2726  Returns:         new code pointer  Returns:         new code pointer
2727  */  */
2728    
2729  static uschar *  static pcre_uchar *
2730  auto_callout(uschar *code, const uschar *ptr, compile_data *cd)  auto_callout(pcre_uchar *code, const pcre_uchar *ptr, compile_data *cd)
2731  {  {
2732  *code++ = OP_CALLOUT;  *code++ = OP_CALLOUT;
2733  *code++ = 255;  *code++ = 255;
2734  PUT(code, 0, (int)(ptr - cd->start_pattern));  /* Pattern offset */  PUT(code, 0, (int)(ptr - cd->start_pattern));  /* Pattern offset */
2735  PUT(code, LINK_SIZE, 0);                       /* Default length */  PUT(code, LINK_SIZE, 0);                       /* Default length */
2736  return code + 2*LINK_SIZE;  return code + 2 * LINK_SIZE;
2737  }  }
2738    
2739    
# Line 2484  Returns:             nothing Line 2755  Returns:             nothing
2755  */  */
2756    
2757  static void  static void
2758  complete_callout(uschar *previous_callout, const uschar *ptr, compile_data *cd)  complete_callout(pcre_uchar *previous_callout, const pcre_uchar *ptr, compile_data *cd)
2759  {  {
2760  int length = (int)(ptr - cd->start_pattern - GET(previous_callout, 2));  int length = (int)(ptr - cd->start_pattern - GET(previous_callout, 2));
2761  PUT(previous_callout, 2 + LINK_SIZE, length);  PUT(previous_callout, 2 + LINK_SIZE, length);
# Line 2567  switch(ptype) Line 2838  switch(ptype)
2838            prop->chartype == ucp_Lt) == negated;            prop->chartype == ucp_Lt) == negated;
2839    
2840    case PT_GC:    case PT_GC:
2841    return (pdata == _pcre_ucp_gentype[prop->chartype]) == negated;    return (pdata == PRIV(ucp_gentype)[prop->chartype]) == negated;
2842    
2843    case PT_PC:    case PT_PC:
2844    return (pdata == prop->chartype) == negated;    return (pdata == prop->chartype) == negated;
# Line 2578  switch(ptype) Line 2849  switch(ptype)
2849    /* These are specials */    /* These are specials */
2850    
2851    case PT_ALNUM:    case PT_ALNUM:
2852    return (_pcre_ucp_gentype[prop->chartype] == ucp_L ||    return (PRIV(ucp_gentype)[prop->chartype] == ucp_L ||
2853            _pcre_ucp_gentype[prop->chartype] == ucp_N) == negated;            PRIV(ucp_gentype)[prop->chartype] == ucp_N) == negated;
2854    
2855    case PT_SPACE:    /* Perl space */    case PT_SPACE:    /* Perl space */
2856    return (_pcre_ucp_gentype[prop->chartype] == ucp_Z ||    return (PRIV(ucp_gentype)[prop->chartype] == ucp_Z ||
2857            c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR)            c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR)
2858            == negated;            == negated;
2859    
2860    case PT_PXSPACE:  /* POSIX space */    case PT_PXSPACE:  /* POSIX space */
2861    return (_pcre_ucp_gentype[prop->chartype] == ucp_Z ||    return (PRIV(ucp_gentype)[prop->chartype] == ucp_Z ||
2862            c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||            c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
2863            c == CHAR_FF || c == CHAR_CR)            c == CHAR_FF || c == CHAR_CR)
2864            == negated;            == negated;
2865    
2866    case PT_WORD:    case PT_WORD:
2867    return (_pcre_ucp_gentype[prop->chartype] == ucp_L ||    return (PRIV(ucp_gentype)[prop->chartype] == ucp_L ||
2868            _pcre_ucp_gentype[prop->chartype] == ucp_N ||            PRIV(ucp_gentype)[prop->chartype] == ucp_N ||
2869            c == CHAR_UNDERSCORE) == negated;            c == CHAR_UNDERSCORE) == negated;
2870    }    }
2871  return FALSE;  return FALSE;
# Line 2613  sense to automatically possessify the re Line 2884  sense to automatically possessify the re
2884    
2885  Arguments:  Arguments:
2886    previous      pointer to the repeated opcode    previous      pointer to the repeated opcode
2887    utf8          TRUE in UTF-8 mode    utf           TRUE in UTF-8 / UTF-16 mode
2888    ptr           next character in pattern    ptr           next character in pattern
2889    options       options bits    options       options bits
2890    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
# Line 2622  Returns:        TRUE if possessifying is Line 2893  Returns:        TRUE if possessifying is
2893  */  */
2894    
2895  static BOOL  static BOOL
2896  check_auto_possessive(const uschar *previous, BOOL utf8, const uschar *ptr,  check_auto_possessive(const pcre_uchar *previous, BOOL utf,
2897    int options, compile_data *cd)    const pcre_uchar *ptr, int options, compile_data *cd)
2898  {  {
2899  int c, next;  int c, next;
2900  int op_code = *previous++;  int op_code = *previous++;
# Line 2643  if ((options & PCRE_EXTENDED) != 0) Line 2914  if ((options & PCRE_EXTENDED) != 0)
2914          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }
2915          ptr++;          ptr++;
2916  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2917          if (utf8) while ((*ptr & 0xc0) == 0x80) ptr++;          if (utf) while ((*ptr & 0xc0) == 0x80) ptr++;
2918  #endif  #endif
2919          }          }
2920        }        }
# Line 2665  if (*ptr == CHAR_BACKSLASH) Line 2936  if (*ptr == CHAR_BACKSLASH)
2936  else if ((cd->ctypes[*ptr] & ctype_meta) == 0)  else if ((cd->ctypes[*ptr] & ctype_meta) == 0)
2937    {    {
2938  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2939    if (utf8) { GETCHARINC(next, ptr); } else    if (utf) { GETCHARINC(next, ptr); } else
2940  #endif  #endif
2941    next = *ptr++;    next = *ptr++;
2942    }    }
# Line 2687  if ((options & PCRE_EXTENDED) != 0) Line 2958  if ((options & PCRE_EXTENDED) != 0)
2958          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }
2959          ptr++;          ptr++;
2960  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2961          if (utf8) while ((*ptr & 0xc0) == 0x80) ptr++;          if (utf) while ((*ptr & 0xc0) == 0x80) ptr++;
2962  #endif  #endif
2963          }          }
2964        }        }
# Line 2698  if ((options & PCRE_EXTENDED) != 0) Line 2969  if ((options & PCRE_EXTENDED) != 0)
2969  /* If the next thing is itself optional, we have to give up. */  /* If the next thing is itself optional, we have to give up. */
2970    
2971  if (*ptr == CHAR_ASTERISK || *ptr == CHAR_QUESTION_MARK ||  if (*ptr == CHAR_ASTERISK || *ptr == CHAR_QUESTION_MARK ||
2972    strncmp((char *)ptr, STR_LEFT_CURLY_BRACKET STR_0 STR_COMMA, 3) == 0)    STRNCMP_UC_C8(ptr, STR_LEFT_CURLY_BRACKET STR_0 STR_COMMA, 3) == 0)
2973      return FALSE;      return FALSE;
2974    
2975  /* Now compare the next item with the previous opcode. First, handle cases when  /* Now compare the next item with the previous opcode. First, handle cases when
# Line 2726  if (next >= 0) switch(op_code) Line 2997  if (next >= 0) switch(op_code)
2997  #endif  #endif
2998    if (c == next) return FALSE;    if (c == next) return FALSE;
2999  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
3000    if (utf8)    if (utf)
3001      {      {
3002      unsigned int othercase;      unsigned int othercase;
3003      if (next < 128) othercase = cd->fcc[next]; else      if (next < 128) othercase = cd->fcc[next]; else
# Line 2751  if (next >= 0) switch(op_code) Line 3022  if (next >= 0) switch(op_code)
3022    case OP_NOTI:    case OP_NOTI:
3023    if ((c = *previous) == next) return TRUE;    if ((c = *previous) == next) return TRUE;
3024  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
3025    if (utf8)    if (utf)
3026      {      {
3027      unsigned int othercase;      unsigned int othercase;
3028      if (next < 128) othercase = cd->fcc[next]; else      if (next < 128) othercase = cd->fcc[next]; else
# Line 2960  switch(op_code) Line 3231  switch(op_code)
3231        to the original \d etc. At this point, ptr will point to a zero byte. */        to the original \d etc. At this point, ptr will point to a zero byte. */
3232    
3233        if (*ptr == CHAR_ASTERISK || *ptr == CHAR_QUESTION_MARK ||        if (*ptr == CHAR_ASTERISK || *ptr == CHAR_QUESTION_MARK ||
3234          strncmp((char *)ptr, STR_LEFT_CURLY_BRACKET STR_0 STR_COMMA, 3) == 0)          STRNCMP_UC_C8(ptr, STR_LEFT_CURLY_BRACKET STR_0 STR_COMMA, 3) == 0)
3235            return FALSE;            return FALSE;
3236    
3237        /* Do the property check. */        /* Do the property check. */
# Line 3038  Arguments: Line 3309  Arguments:
3309    codeptr        points to the pointer to the current code point    codeptr        points to the pointer to the current code point
3310    ptrptr         points to the current pattern pointer    ptrptr         points to the current pattern pointer
3311    errorcodeptr   points to error code variable    errorcodeptr   points to error code variable
3312    firstbyteptr   set to initial literal character, or < 0 (REQ_UNSET, REQ_NONE)    firstcharptr   set to initial literal character, or < 0 (REQ_UNSET, REQ_NONE)
3313    reqbyteptr     set to the last literal character required, else < 0    reqcharptr     set to the last literal character required, else < 0
3314    bcptr          points to current branch chain    bcptr          points to current branch chain
3315    cond_depth     conditional nesting depth    cond_depth     conditional nesting depth
3316    cd             contains pointers to tables etc.    cd             contains pointers to tables etc.
# Line 3051  Returns:         TRUE on success Line 3322  Returns:         TRUE on success
3322  */  */
3323    
3324  static BOOL  static BOOL
3325  compile_branch(int *optionsptr, uschar **codeptr, const uschar **ptrptr,  compile_branch(int *optionsptr, pcre_uchar **codeptr,
3326    int *errorcodeptr, int *firstbyteptr, int *reqbyteptr, branch_chain *bcptr,    const pcre_uchar **ptrptr, int *errorcodeptr, pcre_int32 *firstcharptr,
3327    int cond_depth, compile_data *cd, int *lengthptr)    pcre_int32 *reqcharptr, branch_chain *bcptr, int cond_depth,
3328      compile_data *cd, int *lengthptr)
3329  {  {
3330  int repeat_type, op_type;  int repeat_type, op_type;
3331  int repeat_min = 0, repeat_max = 0;      /* To please picky compilers */  int repeat_min = 0, repeat_max = 0;      /* To please picky compilers */
3332  int bravalue = 0;  int bravalue = 0;
3333  int greedy_default, greedy_non_default;  int greedy_default, greedy_non_default;
3334  int firstbyte, reqbyte;  pcre_int32 firstchar, reqchar;
3335  int zeroreqbyte, zerofirstbyte;  pcre_int32 zeroreqchar, zerofirstchar;
3336  int req_caseopt, reqvary, tempreqvary;  pcre_int32 req_caseopt, reqvary, tempreqvary;
3337  int options = *optionsptr;               /* May change dynamically */  int options = *optionsptr;               /* May change dynamically */
3338  int after_manual_callout = 0;  int after_manual_callout = 0;
3339  int length_prevgroup = 0;  int length_prevgroup = 0;
3340  register int c;  register int c;
3341  register uschar *code = *codeptr;  register pcre_uchar *code = *codeptr;
3342  uschar *last_code = code;  pcre_uchar *last_code = code;
3343  uschar *orig_code = code;  pcre_uchar *orig_code = code;
3344  uschar *tempcode;  pcre_uchar *tempcode;
3345  BOOL inescq = FALSE;  BOOL inescq = FALSE;
3346  BOOL groupsetfirstbyte = FALSE;  BOOL groupsetfirstchar = FALSE;
3347  const uschar *ptr = *ptrptr;  const pcre_uchar *ptr = *ptrptr;
3348  const uschar *tempptr;  const pcre_uchar *tempptr;
3349  const uschar *nestptr = NULL;  const pcre_uchar *nestptr = NULL;
3350  uschar *previous = NULL;  pcre_uchar *previous = NULL;
3351  uschar *previous_callout = NULL;  pcre_uchar *previous_callout = NULL;
3352  uschar *save_hwm = NULL;  pcre_uchar *save_hwm = NULL;
3353  uschar classbits[32];  pcre_uint8 classbits[32];
3354    
3355  /* We can fish out the UTF-8 setting once and for all into a BOOL, but we  /* We can fish out the UTF-8 setting once and for all into a BOOL, but we
3356  must not do this for other options (e.g. PCRE_EXTENDED) because they may change  must not do this for other options (e.g. PCRE_EXTENDED) because they may change
3357  dynamically as we process the pattern. */  dynamically as we process the pattern. */
3358    
3359  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
3360  BOOL class_utf8;  /* PCRE_UTF16 has the same value as PCRE_UTF8. */
3361  BOOL utf8 = (options & PCRE_UTF8) != 0;  BOOL utf = (options & PCRE_UTF8) != 0;
3362  uschar *class_utf8data;  pcre_uchar utf_chars[6];
 uschar *class_utf8data_base;  
 uschar utf8_char[6];  
3363  #else  #else
3364  BOOL utf8 = FALSE;  BOOL utf = FALSE;
3365    #endif
3366    
3367    /* Helper variables for OP_XCLASS opcode (for characters > 255). */
3368    
3369    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3370    BOOL xclass;
3371    pcre_uchar *class_uchardata;
3372    pcre_uchar *class_uchardata_base;
3373  #endif  #endif
3374    
3375  #ifdef PCRE_DEBUG  #ifdef PCRE_DEBUG
# Line 3105  greedy_non_default = greedy_default ^ 1; Line 3383  greedy_non_default = greedy_default ^ 1;
3383    
3384  /* Initialize no first byte, no required byte. REQ_UNSET means "no char  /* Initialize no first byte, no required byte. REQ_UNSET means "no char
3385  matching encountered yet". It gets changed to REQ_NONE if we hit something that  matching encountered yet". It gets changed to REQ_NONE if we hit something that
3386  matches a non-fixed char first char; reqbyte just remains unset if we never  matches a non-fixed char first char; reqchar just remains unset if we never
3387  find one.  find one.
3388    
3389  When we hit a repeat whose minimum is zero, we may have to adjust these values  When we hit a repeat whose minimum is zero, we may have to adjust these values
3390  to take the zero repeat into account. This is implemented by setting them to  to take the zero repeat into account. This is implemented by setting them to
3391  zerofirstbyte and zeroreqbyte when such a repeat is encountered. The individual  zerofirstbyte and zeroreqchar when such a repeat is encountered. The individual
3392  item types that can be repeated set these backoff variables appropriately. */  item types that can be repeated set these backoff variables appropriately. */
3393    
3394  firstbyte = reqbyte = zerofirstbyte = zeroreqbyte = REQ_UNSET;  firstchar = reqchar = zerofirstchar = zeroreqchar = REQ_UNSET;
3395    
3396  /* The variable req_caseopt contains either the REQ_CASELESS value or zero,  /* The variable req_caseopt contains either the REQ_CASELESS value
3397  according to the current setting of the caseless flag. REQ_CASELESS is a bit  or zero, according to the current setting of the caseless flag. The
3398  value > 255. It is added into the firstbyte or reqbyte variables to record the  REQ_CASELESS leaves the lower 28 bit empty. It is added into the
3399  case status of the value. This is used only for ASCII characters. */  firstchar or reqchar variables to record the case status of the
3400    value. This is used only for ASCII characters. */
3401    
3402  req_caseopt = ((options & PCRE_CASELESS) != 0)? REQ_CASELESS : 0;  req_caseopt = ((options & PCRE_CASELESS) != 0)? REQ_CASELESS:0;
3403    
3404  /* Switch on next character until the end of the branch */  /* Switch on next character until the end of the branch */
3405    
# Line 3138  for (;; ptr++) Line 3417  for (;; ptr++)
3417    int recno;    int recno;
3418    int refsign;    int refsign;
3419    int skipbytes;    int skipbytes;
3420    int subreqbyte;    int subreqchar;
3421    int subfirstbyte;    int subfirstchar;
3422    int terminator;    int terminator;
3423    int mclength;    int mclength;
3424    uschar mcbuffer[8];    int tempbracount;
3425      pcre_uchar mcbuffer[8];
3426    
3427    /* Get next byte in the pattern */    /* Get next byte in the pattern */
3428    
# Line 3189  for (;; ptr++) Line 3469  for (;; ptr++)
3469        }        }
3470    
3471      *lengthptr += (int)(code - last_code);      *lengthptr += (int)(code - last_code);
3472      DPRINTF(("length=%d added %d c=%c\n", *lengthptr, code - last_code, c));      DPRINTF(("length=%d added %d c=%c (0x%x)\n", *lengthptr,
3473          (int)(code - last_code), c, c));
3474    
3475      /* If "previous" is set and it is not at the start of the work space, move      /* If "previous" is set and it is not at the start of the work space, move
3476      it back to there, in order to avoid filling up the work space. Otherwise,      it back to there, in order to avoid filling up the work space. Otherwise,
# Line 3199  for (;; ptr++) Line 3480  for (;; ptr++)
3480        {        {
3481        if (previous > orig_code)        if (previous > orig_code)
3482          {          {
3483          memmove(orig_code, previous, code - previous);          memmove(orig_code, previous, IN_UCHARS(code - previous));
3484          code -= previous - orig_code;          code -= previous - orig_code;
3485          previous = orig_code;          previous = orig_code;
3486          }          }
# Line 3276  for (;; ptr++) Line 3557  for (;; ptr++)
3557          if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }
3558          ptr++;          ptr++;
3559  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
3560          if (utf8) while ((*ptr & 0xc0) == 0x80) ptr++;          if (utf) while ((*ptr & 0xc0) == 0x80) ptr++;
3561  #endif  #endif
3562          }          }
3563        if (*ptr != 0) continue;        if (*ptr != 0) continue;
# Line 3300  for (;; ptr++) Line 3581  for (;; ptr++)
3581      case 0:                        /* The branch terminates at string end */      case 0:                        /* The branch terminates at string end */
3582      case CHAR_VERTICAL_LINE:       /* or | or ) */      case CHAR_VERTICAL_LINE:       /* or | or ) */
3583      case CHAR_RIGHT_PARENTHESIS:      case CHAR_RIGHT_PARENTHESIS:
3584      *firstbyteptr = firstbyte;      *firstcharptr = firstchar;
3585      *reqbyteptr = reqbyte;      *reqcharptr = reqchar;
3586      *codeptr = code;      *codeptr = code;
3587      *ptrptr = ptr;      *ptrptr = ptr;
3588      if (lengthptr != NULL)      if (lengthptr != NULL)
# Line 3325  for (;; ptr++) Line 3606  for (;; ptr++)
3606      previous = NULL;      previous = NULL;
3607      if ((options & PCRE_MULTILINE) != 0)      if ((options & PCRE_MULTILINE) != 0)
3608        {        {
3609        if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;        if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
3610        *code++ = OP_CIRCM;        *code++ = OP_CIRCM;
3611        }        }
3612      else *code++ = OP_CIRC;      else *code++ = OP_CIRC;
# Line 3337  for (;; ptr++) Line 3618  for (;; ptr++)
3618      break;      break;
3619    
3620      /* There can never be a first char if '.' is first, whatever happens about      /* There can never be a first char if '.' is first, whatever happens about
3621      repeats. The value of reqbyte doesn't change either. */      repeats. The value of reqchar doesn't change either. */
3622    
3623      case CHAR_DOT:      case CHAR_DOT:
3624      if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;      if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
3625      zerofirstbyte = firstbyte;      zerofirstchar = firstchar;
3626      zeroreqbyte = reqbyte;      zeroreqchar = reqchar;
3627      previous = code;      previous = code;
3628      *code++ = ((options & PCRE_DOTALL) != 0)? OP_ALLANY: OP_ANY;      *code++ = ((options & PCRE_DOTALL) != 0)? OP_ALLANY: OP_ANY;
3629      break;      break;
# Line 3397  for (;; ptr++) Line 3678  for (;; ptr++)
3678          {          {
3679          if (ptr[1] == CHAR_E)          if (ptr[1] == CHAR_E)
3680            ptr++;            ptr++;
3681          else if (strncmp((const char *)ptr+1,          else if (STRNCMP_UC_C8(ptr + 1, STR_Q STR_BACKSLASH STR_E, 3) == 0)
                           STR_Q STR_BACKSLASH STR_E, 3) == 0)  
3682            ptr += 3;            ptr += 3;
3683          else          else
3684            break;            break;
# Line 3417  for (;; ptr++) Line 3697  for (;; ptr++)
3697          (cd->external_options & PCRE_JAVASCRIPT_COMPAT) != 0)          (cd->external_options & PCRE_JAVASCRIPT_COMPAT) != 0)
3698        {        {
3699        *code++ = negate_class? OP_ALLANY : OP_FAIL;        *code++ = negate_class? OP_ALLANY : OP_FAIL;
3700        if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;        if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
3701        zerofirstbyte = firstbyte;        zerofirstchar = firstchar;
3702        break;        break;
3703        }        }
3704    
# Line 3440  for (;; ptr++) Line 3720  for (;; ptr++)
3720      than 256), because in that case the compiled code doesn't use the bit map.      than 256), because in that case the compiled code doesn't use the bit map.
3721      */      */
3722    
3723      memset(classbits, 0, 32 * sizeof(uschar));      memset(classbits, 0, 32 * sizeof(pcre_uint8));
3724    
3725  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3726      class_utf8 = FALSE;                       /* No chars >= 256 */      xclass = FALSE;                           /* No chars >= 256 */
3727      class_utf8data = code + LINK_SIZE + 2;    /* For UTF-8 items */      class_uchardata = code + LINK_SIZE + 2;   /* For UTF-8 items */
3728      class_utf8data_base = class_utf8data;     /* For resetting in pass 1 */      class_uchardata_base = class_uchardata;   /* For resetting in pass 1 */
3729  #endif  #endif
3730    
3731      /* Process characters until ] is reached. By writing this as a "do" it      /* Process characters until ] is reached. By writing this as a "do" it
# Line 3454  for (;; ptr++) Line 3734  for (;; ptr++)
3734    
3735      if (c != 0) do      if (c != 0) do
3736        {        {
3737        const uschar *oldptr;        const pcre_uchar *oldptr;
3738    
3739  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
3740        if (utf8 && c > 127)        if (utf && c > 127)
3741          {                           /* Braces are required because the */          {                           /* Braces are required because the */
3742          GETCHARLEN(c, ptr, ptr);    /* macro generates multiple statements */          GETCHARLEN(c, ptr, ptr);    /* macro generates multiple statements */
3743          }          }
3744    #endif
3745    
3746        /* In the pre-compile phase, accumulate the length of any UTF-8 extra  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3747          /* In the pre-compile phase, accumulate the length of any extra
3748        data and reset the pointer. This is so that very large classes that        data and reset the pointer. This is so that very large classes that
3749        contain a zillion UTF-8 characters no longer overwrite the work space        contain a zillion > 255 characters no longer overwrite the work space
3750        (which is on the stack). */        (which is on the stack). */
3751    
3752        if (lengthptr != NULL)        if (lengthptr != NULL)
3753          {          {
3754          *lengthptr += class_utf8data - class_utf8data_base;          *lengthptr += class_uchardata - class_uchardata_base;
3755          class_utf8data = class_utf8data_base;          class_uchardata = class_uchardata_base;
3756          }          }
   
3757  #endif  #endif
3758    
3759        /* Inside \Q...\E everything is literal except \E */        /* Inside \Q...\E everything is literal except \E */
# Line 3500  for (;; ptr++) Line 3781  for (;; ptr++)
3781          {          {
3782          BOOL local_negate = FALSE;          BOOL local_negate = FALSE;
3783          int posix_class, taboffset, tabopt;          int posix_class, taboffset, tabopt;
3784          register const uschar *cbits = cd->cbits;          register const pcre_uint8 *cbits = cd->cbits;
3785          uschar pbits[32];          pcre_uint8 pbits[32];
3786    
3787          if (ptr[1] != CHAR_COLON)          if (ptr[1] != CHAR_COLON)
3788            {            {
# Line 3556  for (;; ptr++) Line 3837  for (;; ptr++)
3837          /* Copy in the first table (always present) */          /* Copy in the first table (always present) */
3838    
3839          memcpy(pbits, cbits + posix_class_maps[posix_class],          memcpy(pbits, cbits + posix_class_maps[posix_class],
3840            32 * sizeof(uschar));            32 * sizeof(pcre_uint8));
3841    
3842          /* If there is a second table, add or remove it as required. */          /* If there is a second table, add or remove it as required. */
3843    
# Line 3618  for (;; ptr++) Line 3899  for (;; ptr++)
3899    
3900          if (c < 0)          if (c < 0)
3901            {            {
3902            register const uschar *cbits = cd->cbits;            register const pcre_uint8 *cbits = cd->cbits;
3903            class_charcount += 2;     /* Greater than 1 is what matters */            class_charcount += 2;     /* Greater than 1 is what matters */
3904    
3905            switch (-c)            switch (-c)
# Line 3673  for (;; ptr++) Line 3954  for (;; ptr++)
3954              SETBIT(classbits, 0x09); /* VT */              SETBIT(classbits, 0x09); /* VT */
3955              SETBIT(classbits, 0x20); /* SPACE */              SETBIT(classbits, 0x20); /* SPACE */
3956              SETBIT(classbits, 0xa0); /* NSBP */              SETBIT(classbits, 0xa0); /* NSBP */
3957  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3958              if (utf8)              if (utf)
3959                {                {
3960                class_utf8 = TRUE;                xclass = TRUE;
3961                *class_utf8data++ = XCL_SINGLE;                *class_uchardata++ = XCL_SINGLE;
3962                class_utf8data += _pcre_ord2utf8(0x1680, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x1680, class_uchardata);
3963                *class_utf8data++ = XCL_SINGLE;                *class_uchardata++ = XCL_SINGLE;
3964                class_utf8data += _pcre_ord2utf8(0x180e, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x180e, class_uchardata);
3965                *class_utf8data++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
3966                class_utf8data += _pcre_ord2utf8(0x2000, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x2000, class_uchardata);
3967                class_utf8data += _pcre_ord2utf8(0x200A, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x200A, class_uchardata);
3968                *class_utf8data++ = XCL_SINGLE;                *class_uchardata++ = XCL_SINGLE;
3969                class_utf8data += _pcre_ord2utf8(0x202f, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x202f, class_uchardata);
3970                *class_utf8data++ = XCL_SINGLE;                *class_uchardata++ = XCL_SINGLE;
3971                class_utf8data += _pcre_ord2utf8(0x205f, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x205f, class_uchardata);
3972                *class_utf8data++ = XCL_SINGLE;                *class_uchardata++ = XCL_SINGLE;
3973                class_utf8data += _pcre_ord2utf8(0x3000, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x3000, class_uchardata);
3974                }                }
3975  #endif  #endif
3976              continue;              continue;
# Line 3708  for (;; ptr++) Line 3989  for (;; ptr++)
3989                classbits[c] |= x;                classbits[c] |= x;
3990                }                }
3991    
3992  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3993              if (utf8)              if (utf)
3994                {                {
3995                class_utf8 = TRUE;                xclass = TRUE;
3996                *class_utf8data++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
3997                class_utf8data += _pcre_ord2utf8(0x0100, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x0100, class_uchardata);
3998                class_utf8data += _pcre_ord2utf8(0x167f, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x167f, class_uchardata);
3999                *class_utf8data++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4000                class_utf8data += _pcre_ord2utf8(0x1681, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x1681, class_uchardata);
4001                class_utf8data += _pcre_ord2utf8(0x180d, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x180d, class_uchardata);
4002                *class_utf8data++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4003                class_utf8data += _pcre_ord2utf8(0x180f, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x180f, class_uchardata);
4004                class_utf8data += _pcre_ord2utf8(0x1fff, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x1fff, class_uchardata);
4005                *class_utf8data++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4006                class_utf8data += _pcre_ord2utf8(0x200B, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x200B, class_uchardata);
4007                class_utf8data += _pcre_ord2utf8(0x202e, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x202e, class_uchardata);
4008                *class_utf8data++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4009                class_utf8data += _pcre_ord2utf8(0x2030, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x2030, class_uchardata);
4010                class_utf8data += _pcre_ord2utf8(0x205e, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x205e, class_uchardata);
4011                *class_utf8data++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4012                class_utf8data += _pcre_ord2utf8(0x2060, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x2060, class_uchardata);
4013                class_utf8data += _pcre_ord2utf8(0x2fff, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x2fff, class_uchardata);
4014                *class_utf8data++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4015                class_utf8data += _pcre_ord2utf8(0x3001, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x3001, class_uchardata);
4016                class_utf8data += _pcre_ord2utf8(0x7fffffff, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x10ffff, class_uchardata);
4017                }                }
4018  #endif  #endif
4019              continue;              continue;
# Line 3743  for (;; ptr++) Line 4024  for (;; ptr++)
4024              SETBIT(classbits, 0x0c); /* FF */              SETBIT(classbits, 0x0c); /* FF */
4025              SETBIT(classbits, 0x0d); /* CR */              SETBIT(classbits, 0x0d); /* CR */
4026              SETBIT(classbits, 0x85); /* NEL */              SETBIT(classbits, 0x85); /* NEL */
4027  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4028              if (utf8)              if (utf)
4029                {                {
4030                class_utf8 = TRUE;                xclass = TRUE;
4031                *class_utf8data++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4032                class_utf8data += _pcre_ord2utf8(0x2028, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x2028, class_uchardata);
4033                class_utf8data += _pcre_ord2utf8(0x2029, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x2029, class_uchardata);
4034                }                }
4035  #endif  #endif
4036              continue;              continue;
# Line 3771  for (;; ptr++) Line 4052  for (;; ptr++)
4052                classbits[c] |= x;                classbits[c] |= x;
4053                }                }
4054    
4055  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4056              if (utf8)              if (utf)
4057                {                {
4058                class_utf8 = TRUE;                xclass = TRUE;
4059                *class_utf8data++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4060                class_utf8data += _pcre_ord2utf8(0x0100, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x0100, class_uchardata);
4061                class_utf8data += _pcre_ord2utf8(0x2027, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x2027, class_uchardata);
4062                *class_utf8data++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4063                class_utf8data += _pcre_ord2utf8(0x2029, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x2029, class_uchardata);
4064                class_utf8data += _pcre_ord2utf8(0x7fffffff, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x10ffff, class_uchardata);
4065                }                }
4066  #endif  #endif
4067              continue;              continue;
# Line 3793  for (;; ptr++) Line 4074  for (;; ptr++)
4074                int pdata;                int pdata;
4075                int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);                int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);
4076                if (ptype < 0) goto FAILED;                if (ptype < 0) goto FAILED;
4077                class_utf8 = TRUE;                xclass = TRUE;
4078                *class_utf8data++ = ((-c == ESC_p) != negated)?                *class_uchardata++ = ((-c == ESC_p) != negated)?
4079                  XCL_PROP : XCL_NOTPROP;                  XCL_PROP : XCL_NOTPROP;
4080                *class_utf8data++ = ptype;                *class_uchardata++ = ptype;
4081                *class_utf8data++ = pdata;                *class_uchardata++ = pdata;
4082                class_charcount -= 2;   /* Not a < 256 character */                class_charcount -= 2;   /* Not a < 256 character */
4083                continue;                continue;
4084                }                }
# Line 3819  for (;; ptr++) Line 4100  for (;; ptr++)
4100            }            }
4101    
4102          /* Fall through if we have a single character (c >= 0). This may be          /* Fall through if we have a single character (c >= 0). This may be
4103          greater than 256 in UTF-8 mode. */          greater than 256 mode. */
4104    
4105          }   /* End of backslash handling */          }   /* End of backslash handling */
4106    
# Line 3868  for (;; ptr++) Line 4149  for (;; ptr++)
4149            }            }
4150    
4151  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
4152          if (utf8)          if (utf)
4153            {                           /* Braces are required because the */            {                           /* Braces are required because the */
4154            GETCHARLEN(d, ptr, ptr);    /* macro generates multiple statements */            GETCHARLEN(d, ptr, ptr);    /* macro generates multiple statements */
4155            }            }
# Line 3917  for (;; ptr++) Line 4198  for (;; ptr++)
4198          matching for characters > 127 is available only if UCP support is          matching for characters > 127 is available only if UCP support is
4199          available. */          available. */
4200    
4201  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4202          if (utf8 && (d > 255 || ((options & PCRE_CASELESS) != 0 && d > 127)))          if (utf && (d > 255 || ((options & PCRE_CASELESS) != 0 && d > 127)))
4203    #endif
4204    #ifndef COMPILE_PCRE8
4205            if (d > 255)
4206    #endif
4207    #if defined SUPPORT_UTF || defined COMPILE_PCRE16
4208            {            {
4209            class_utf8 = TRUE;            xclass = TRUE;
4210    
4211            /* With UCP support, we can find the other case equivalents of            /* With UCP support, we can find the other case equivalents of
4212            the relevant characters. There may be several ranges. Optimize how            the relevant characters. There may be several ranges. Optimize how
# Line 3953  for (;; ptr++) Line 4239  for (;; ptr++)
4239    
4240                if (occ == ocd)                if (occ == ocd)
4241                  {                  {
4242                  *class_utf8data++ = XCL_SINGLE;                  *class_uchardata++ = XCL_SINGLE;
4243                  }                  }
4244                else                else
4245                  {                  {
4246                  *class_utf8data++ = XCL_RANGE;                  *class_uchardata++ = XCL_RANGE;
4247                  class_utf8data += _pcre_ord2utf8(occ, class_utf8data);                  class_uchardata += PRIV(ord2utf)(occ, class_uchardata);
4248                  }                  }
4249                class_utf8data += _pcre_ord2utf8(ocd, class_utf8data);                class_uchardata += PRIV(ord2utf)(ocd, class_uchardata);
4250                }                }
4251              }              }
4252  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
# Line 3968  for (;; ptr++) Line 4254  for (;; ptr++)
4254            /* Now record the original range, possibly modified for UCP caseless            /* Now record the original range, possibly modified for UCP caseless
4255            overlapping ranges. */            overlapping ranges. */
4256    
4257            *class_utf8data++ = XCL_RANGE;            *class_uchardata++ = XCL_RANGE;
4258            class_utf8data += _pcre_ord2utf8(c, class_utf8data);  #ifdef SUPPORT_UTF
4259            class_utf8data += _pcre_ord2utf8(d, class_utf8data);            class_uchardata += PRIV(ord2utf)(c, class_uchardata);
4260              class_uchardata += PRIV(ord2utf)(d, class_uchardata);
4261    #else
4262              *class_uchardata++ = c;
4263              *class_uchardata++ = d;
4264    #endif
4265    
4266            /* With UCP support, we are done. Without UCP support, there is no            /* With UCP support, we are done. Without UCP support, there is no
4267            caseless matching for UTF-8 characters > 127; we can use the bit map            caseless matching for UTF characters > 127; we can use the bit map
4268            for the smaller ones. */            for the smaller ones. As for 16 bit characters without UTF, we
4269              can still use  */
4270    
4271  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4272            continue;    /* With next character in the class */            continue;    /* With next character in the class */
4273  #else  #else
4274    #ifdef SUPPORT_UTF
4275            if ((options & PCRE_CASELESS) == 0 || c > 127) continue;            if ((options & PCRE_CASELESS) == 0 || c > 127) continue;
   
4276            /* Adjust upper limit and fall through to set up the map */            /* Adjust upper limit and fall through to set up the map */
   
4277            d = 127;            d = 127;
4278    #else
4279              if (c > 255) continue;
4280              /* Adjust upper limit and fall through to set up the map */
4281              d = 255;
4282    #endif  /* SUPPORT_UTF */
4283  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
4284            }            }
4285  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF8 || COMPILE_PCRE16 */
4286    
4287          /* We use the bit map for all cases when not in UTF-8 mode; else          /* We use the bit map for 8 bit mode, or when the characters fall
4288          ranges that lie entirely within 0-127 when there is UCP support; else          partially or entirely to [0-255] ([0-127] for UCP) ranges. */
         for partial ranges without UCP support. */  
4289    
4290          class_charcount += d - c + 1;          class_charcount += d - c + 1;
4291          class_lastchar = d;          class_lastchar = d;
# Line 4019  for (;; ptr++) Line 4313  for (;; ptr++)
4313    
4314        /* Handle a character that cannot go in the bit map */        /* Handle a character that cannot go in the bit map */
4315    
4316  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4317        if (utf8 && (c > 255 || ((options & PCRE_CASELESS) != 0 && c > 127)))        if (utf && (c > 255 || ((options & PCRE_CASELESS) != 0 && c > 127)))
4318    #endif
4319    #ifndef COMPILE_PCRE8
4320          if (c > 255)
4321    #endif
4322    #if defined SUPPORT_UTF || defined COMPILE_PCRE16
4323          {          {
4324          class_utf8 = TRUE;          xclass = TRUE;
4325          *class_utf8data++ = XCL_SINGLE;          *class_uchardata++ = XCL_SINGLE;
4326          class_utf8data += _pcre_ord2utf8(c, class_utf8data);  #ifdef SUPPORT_UTF
4327            class_uchardata += PRIV(ord2utf)(c, class_uchardata);
4328    #else
4329            *class_uchardata++ = c;
4330    #endif
4331    
4332  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4333          if ((options & PCRE_CASELESS) != 0)          if ((options & PCRE_CASELESS) != 0)
# Line 4032  for (;; ptr++) Line 4335  for (;; ptr++)
4335            unsigned int othercase;            unsigned int othercase;
4336            if ((othercase = UCD_OTHERCASE(c)) != c)            if ((othercase = UCD_OTHERCASE(c)) != c)
4337              {              {
4338              *class_utf8data++ = XCL_SINGLE;              *class_uchardata++ = XCL_SINGLE;
4339              class_utf8data += _pcre_ord2utf8(othercase, class_utf8data);              class_uchardata += PRIV(ord2utf)(othercase, class_uchardata);
4340              }              }
4341            }            }
4342  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
# Line 4085  for (;; ptr++) Line 4388  for (;; ptr++)
4388      The optimization throws away the bit map. We turn the item into a      The optimization throws away the bit map. We turn the item into a
4389      1-character OP_CHAR[I] if it's positive, or OP_NOT[I] if it's negative.      1-character OP_CHAR[I] if it's positive, or OP_NOT[I] if it's negative.
4390      Note that OP_NOT[I] does not support multibyte characters. In the positive      Note that OP_NOT[I] does not support multibyte characters. In the positive
4391      case, it can cause firstbyte to be set. Otherwise, there can be no first      case, it can cause firstchar to be set. Otherwise, there can be no first
4392      char if this item is first, whatever repeat count may follow. In the case      char if this item is first, whatever repeat count may follow. In the case
4393      of reqbyte, save the previous value for reinstating. */      of reqchar, save the previous value for reinstating. */
4394    
4395  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4396      if (class_charcount == 1 && !class_utf8 &&      if (class_charcount == 1 && !xclass &&
4397        (!utf8 || !negate_class || class_lastchar < 128))        (!utf || !negate_class || class_lastchar < 128))
4398  #else  #else
4399      if (class_charcount == 1)      if (class_charcount == 1)
4400  #endif  #endif
4401        {        {
4402        zeroreqbyte = reqbyte;        zeroreqchar = reqchar;
4403    
4404        /* The OP_NOT[I] opcodes work on one-byte characters only. */        /* The OP_NOT[I] opcodes work on one-byte characters only. */
4405    
4406        if (negate_class)        if (negate_class)
4407          {          {
4408          if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
4409          zerofirstbyte = firstbyte;          zerofirstchar = firstchar;
4410          *code++ = ((options & PCRE_CASELESS) != 0)? OP_NOTI: OP_NOT;          *code++ = ((options & PCRE_CASELESS) != 0)? OP_NOTI: OP_NOT;
4411          *code++ = class_lastchar;          *code++ = class_lastchar;
4412          break;          break;
# Line 4113  for (;; ptr++) Line 4416  for (;; ptr++)
4416        then we can handle this with the normal one-character code. */        then we can handle this with the normal one-character code. */
4417    
4418  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
4419        if (utf8 && class_lastchar > 127)        if (utf && class_lastchar > 127)
4420          mclength = _pcre_ord2utf8(class_lastchar, mcbuffer);          mclength = PRIV(ord2utf)(class_lastchar, mcbuffer);
4421        else        else
4422  #endif  #endif
4423          {          {
# Line 4126  for (;; ptr++) Line 4429  for (;; ptr++)
4429    
4430      /* The general case - not the one-char optimization. If this is the first      /* The general case - not the one-char optimization. If this is the first
4431      thing in the branch, there can be no first char setting, whatever the      thing in the branch, there can be no first char setting, whatever the
4432      repeat count. Any reqbyte setting must remain unchanged after any kind of      repeat count. Any reqchar setting must remain unchanged after any kind of
4433      repeat. */      repeat. */
4434    
4435      if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;      if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
4436      zerofirstbyte = firstbyte;      zerofirstchar = firstchar;
4437      zeroreqbyte = reqbyte;      zeroreqchar = reqchar;
4438    
4439      /* If there are characters with values > 255, we have to compile an      /* If there are characters with values > 255, we have to compile an
4440      extended class, with its own opcode, unless there was a negated special      extended class, with its own opcode, unless there was a negated special
# Line 4141  for (;; ptr++) Line 4444  for (;; ptr++)
4444      be listed) there are no characters < 256, we can omit the bitmap in the      be listed) there are no characters < 256, we can omit the bitmap in the
4445      actual compiled code. */      actual compiled code. */
4446    
4447  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4448      if (class_utf8 && (!should_flip_negation || (options & PCRE_UCP) != 0))      if (xclass && (!should_flip_negation || (options & PCRE_UCP) != 0))
4449    #endif
4450    #ifndef COMPILE_PCRE8
4451        if (xclass && !should_flip_negation)
4452    #endif
4453    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
4454        {        {
4455        *class_utf8data++ = XCL_END;    /* Marks the end of extra data */        *class_uchardata++ = XCL_END;    /* Marks the end of extra data */
4456        *code++ = OP_XCLASS;        *code++ = OP_XCLASS;
4457        code += LINK_SIZE;        code += LINK_SIZE;
4458        *code = negate_class? XCL_NOT : 0;        *code = negate_class? XCL_NOT:0;
4459    
4460        /* If the map is required, move up the extra data to make room for it;        /* If the map is required, move up the extra data to make room for it;
4461        otherwise just move the code pointer to the end of the extra data. */        otherwise just move the code pointer to the end of the extra data. */
# Line 4155  for (;; ptr++) Line 4463  for (;; ptr++)
4463        if (class_charcount > 0)        if (class_charcount > 0)
4464          {          {
4465          *code++ |= XCL_MAP;          *code++ |= XCL_MAP;
4466          memmove(code + 32, code, class_utf8data - code);          memmove(code + (32 / sizeof(pcre_uchar)), code,
4467              IN_UCHARS(class_uchardata - code));
4468          memcpy(code, classbits, 32);          memcpy(code, classbits, 32);
4469          code = class_utf8data + 32;          code = class_uchardata + (32 / sizeof(pcre_uchar));
4470          }          }
4471        else code = class_utf8data;        else code = class_uchardata;
4472    
4473        /* Now fill in the complete length of the item */        /* Now fill in the complete length of the item */
4474    
# Line 4175  for (;; ptr++) Line 4484  for (;; ptr++)
4484      negating it if necessary. */      negating it if necessary. */
4485    
4486      *code++ = (negate_class == should_flip_negation) ? OP_CLASS : OP_NCLASS;      *code++ = (negate_class == should_flip_negation) ? OP_CLASS : OP_NCLASS;
4487      if (negate_class)      if (lengthptr == NULL)    /* Save time in the pre-compile phase */
       {  
       if (lengthptr == NULL)    /* Save time in the pre-compile phase */  
         for (c = 0; c < 32; c++) code[c] = ~classbits[c];  
       }  
     else  
4488        {        {
4489          if (negate_class)
4490            for (c = 0; c < 32; c++) classbits[c] = ~classbits[c];
4491        memcpy(code, classbits, 32);        memcpy(code, classbits, 32);
4492        }        }
4493      code += 32;      code += 32 / sizeof(pcre_uchar);
4494      break;      break;
4495    
4496    
# Line 4221  for (;; ptr++) Line 4527  for (;; ptr++)
4527    
4528      if (repeat_min == 0)      if (repeat_min == 0)
4529        {        {
4530        firstbyte = zerofirstbyte;    /* Adjust for zero repeat */        firstchar = zerofirstchar;    /* Adjust for zero repeat */
4531        reqbyte = zeroreqbyte;        /* Ditto */        reqchar = zeroreqchar;        /* Ditto */
4532        }        }
4533    
4534      /* Remember whether this is a variable length repeat */      /* Remember whether this is a variable length repeat */
# Line 4261  for (;; ptr++) Line 4567  for (;; ptr++)
4567      past, but it no longer happens for non-repeated recursions. In fact, the      past, but it no longer happens for non-repeated recursions. In fact, the
4568      repeated ones could be re-implemented independently so as not to need this,      repeated ones could be re-implemented independently so as not to need this,
4569      but for the moment we rely on the code for repeating groups. */      but for the moment we rely on the code for repeating groups. */
4570    
4571      if (*previous == OP_RECURSE)      if (*previous == OP_RECURSE)
4572        {        {
4573        memmove(previous + 1 + LINK_SIZE, previous, 1 + LINK_SIZE);        memmove(previous + 1 + LINK_SIZE, previous, IN_UCHARS(1 + LINK_SIZE));
4574        *previous = OP_ONCE;        *previous = OP_ONCE;
4575        PUT(previous, 1, 2 + 2*LINK_SIZE);        PUT(previous, 1, 2 + 2*LINK_SIZE);
4576        previous[2 + 2*LINK_SIZE] = OP_KET;        previous[2 + 2*LINK_SIZE] = OP_KET;
# Line 4287  for (;; ptr++) Line 4593  for (;; ptr++)
4593    
4594      /* If previous was a character match, abolish the item and generate a      /* If previous was a character match, abolish the item and generate a
4595      repeat item instead. If a char item has a minumum of more than one, ensure      repeat item instead. If a char item has a minumum of more than one, ensure
4596      that it is set in reqbyte - it might not be if a sequence such as x{3} is      that it is set in reqchar - it might not be if a sequence such as x{3} is
4597      the first thing in a branch because the x will have gone into firstbyte      the first thing in a branch because the x will have gone into firstchar
4598      instead.  */      instead.  */
4599    
4600      if (*previous == OP_CHAR || *previous == OP_CHARI)      if (*previous == OP_CHAR || *previous == OP_CHARI)
# Line 4301  for (;; ptr++) Line 4607  for (;; ptr++)
4607        length rather than a small character. */        length rather than a small character. */
4608    
4609  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
4610        if (utf8 && (code[-1] & 0x80) != 0)        if (utf && (code[-1] & 0x80) != 0)
4611          {          {
4612          uschar *lastchar = code - 1;          pcre_uchar *lastchar = code - 1;
4613          while((*lastchar & 0xc0) == 0x80) lastchar--;          while((*lastchar & 0xc0) == 0x80) lastchar--;
4614          c = code - lastchar;            /* Length of UTF-8 character */          c = code - lastchar;            /* Length of UTF-8 character */
4615          memcpy(utf8_char, lastchar, c); /* Save the char */          memcpy(utf_chars, lastchar, c); /* Save the char */
4616          c |= 0x80;                      /* Flag c as a length */          c |= 0x80;                      /* Flag c as a length */
4617          }          }
4618        else        else
# Line 4317  for (;; ptr++) Line 4623  for (;; ptr++)
4623    
4624          {          {
4625          c = code[-1];          c = code[-1];
4626          if (repeat_min > 1) reqbyte = c | req_caseopt | cd->req_varyopt;          if (repeat_min > 1) reqchar = c | req_caseopt | cd->req_varyopt;
4627          }          }
4628    
4629        /* If the repetition is unlimited, it pays to see if the next thing on        /* If the repetition is unlimited, it pays to see if the next thing on
# Line 4327  for (;; ptr++) Line 4633  for (;; ptr++)
4633    
4634        if (!possessive_quantifier &&        if (!possessive_quantifier &&
4635            repeat_max < 0 &&            repeat_max < 0 &&
4636            check_auto_possessive(previous, utf8, ptr + 1, options, cd))            check_auto_possessive(previous, utf, ptr + 1, options, cd))
4637          {          {
4638          repeat_type = 0;    /* Force greedy */          repeat_type = 0;    /* Force greedy */
4639          possessive_quantifier = TRUE;          possessive_quantifier = TRUE;
# Line 4348  for (;; ptr++) Line 4654  for (;; ptr++)
4654        c = previous[1];        c = previous[1];
4655        if (!possessive_quantifier &&        if (!possessive_quantifier &&
4656            repeat_max < 0 &&            repeat_max < 0 &&
4657            check_auto_possessive(previous, utf8, ptr + 1, options, cd))            check_auto_possessive(previous, utf, ptr + 1, options, cd))
4658          {          {
4659          repeat_type = 0;    /* Force greedy */          repeat_type = 0;    /* Force greedy */
4660          possessive_quantifier = TRUE;          possessive_quantifier = TRUE;
# Line 4365  for (;; ptr++) Line 4671  for (;; ptr++)
4671    
4672      else if (*previous < OP_EODN)      else if (*previous < OP_EODN)
4673        {        {
4674        uschar *oldcode;        pcre_uchar *oldcode;
4675        int prop_type, prop_value;        int prop_type, prop_value;
4676        op_type = OP_TYPESTAR - OP_STAR;  /* Use type opcodes */        op_type = OP_TYPESTAR - OP_STAR;  /* Use type opcodes */
4677        c = *previous;        c = *previous;
4678    
4679        if (!possessive_quantifier &&        if (!possessive_quantifier &&
4680            repeat_max < 0 &&            repeat_max < 0 &&
4681            check_auto_possessive(previous, utf8, ptr + 1, options, cd))            check_auto_possessive(previous, utf, ptr + 1, options, cd))
4682          {          {
4683          repeat_type = 0;    /* Force greedy */          repeat_type = 0;    /* Force greedy */
4684          possessive_quantifier = TRUE;          possessive_quantifier = TRUE;
# Line 4457  for (;; ptr++) Line 4763  for (;; ptr++)
4763          if (repeat_max < 0)          if (repeat_max < 0)
4764            {            {
4765  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
4766            if (utf8 && c >= 128)            if (utf && c >= 128)
4767              {              {
4768              memcpy(code, utf8_char, c & 7);              memcpy(code, utf_chars, c & 7);
4769              code += c & 7;              code += c & 7;
4770              }              }
4771            else            else
# Line 4482  for (;; ptr++) Line 4788  for (;; ptr++)
4788          else if (repeat_max != repeat_min)          else if (repeat_max != repeat_min)
4789            {            {
4790  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
4791            if (utf8 && c >= 128)            if (utf && c >= 128)
4792              {              {
4793              memcpy(code, utf8_char, c & 7);              memcpy(code, utf_chars, c & 7);
4794              code += c & 7;              code += c & 7;
4795              }              }
4796            else            else
# Line 4512  for (;; ptr++) Line 4818  for (;; ptr++)
4818        /* The character or character type itself comes last in all cases. */        /* The character or character type itself comes last in all cases. */
4819    
4820  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
4821        if (utf8 && c >= 128)        if (utf && c >= 128)
4822          {          {
4823          memcpy(code, utf8_char, c & 7);          memcpy(code, utf_chars, c & 7);
4824          code += c & 7;          code += c & 7;
4825          }          }
4826        else        else
# Line 4538  for (;; ptr++) Line 4844  for (;; ptr++)
4844    
4845      else if (*previous == OP_CLASS ||      else if (*previous == OP_CLASS ||
4846               *previous == OP_NCLASS ||               *previous == OP_NCLASS ||
4847  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF8 || !defined COMPILE_PCRE8
4848               *previous == OP_XCLASS ||               *previous == OP_XCLASS ||
4849  #endif  #endif
4850               *previous == OP_REF ||               *previous == OP_REF ||
# Line 4587  for (;; ptr++) Line 4893  for (;; ptr++)
4893        {        {
4894        register int i;        register int i;
4895        int len = (int)(code - previous);        int len = (int)(code - previous);
4896        uschar *bralink = NULL;        pcre_uchar *bralink = NULL;
4897        uschar *brazeroptr = NULL;        pcre_uchar *brazeroptr = NULL;
4898    
4899        /* Repeating a DEFINE group is pointless, but Perl allows the syntax, so        /* Repeating a DEFINE group is pointless, but Perl allows the syntax, so
4900        we just ignore the repeat. */        we just ignore the repeat. */
# Line 4641  for (;; ptr++) Line 4947  for (;; ptr++)
4947          if (repeat_max <= 1)    /* Covers 0, 1, and unlimited */          if (repeat_max <= 1)    /* Covers 0, 1, and unlimited */
4948            {            {
4949            *code = OP_END;            *code = OP_END;
4950            adjust_recurse(previous, 1, utf8, cd, save_hwm);            adjust_recurse(previous, 1, utf, cd, save_hwm);
4951            memmove(previous+1, previous, len);            memmove(previous + 1, previous, IN_UCHARS(len));
4952            code++;            code++;
4953            if (repeat_max == 0)            if (repeat_max == 0)
4954              {              {
# Line 4665  for (;; ptr++) Line 4971  for (;; ptr++)
4971            {            {
4972            int offset;            int offset;
4973            *code = OP_END;            *code = OP_END;
4974            adjust_recurse(previous, 2 + LINK_SIZE, utf8, cd, save_hwm);            adjust_recurse(previous, 2 + LINK_SIZE, utf, cd, save_hwm);
4975            memmove(previous + 2 + LINK_SIZE, previous, len);            memmove(previous + 2 + LINK_SIZE, previous, IN_UCHARS(len));
4976            code += 2 + LINK_SIZE;            code += 2 + LINK_SIZE;
4977            *previous++ = OP_BRAZERO + repeat_type;            *previous++ = OP_BRAZERO + repeat_type;
4978            *previous++ = OP_BRA;            *previous++ = OP_BRA;
# Line 4716  for (;; ptr++) Line 5022  for (;; ptr++)
5022    
5023            else            else
5024              {              {
5025              if (groupsetfirstbyte && reqbyte < 0) reqbyte = firstbyte;              if (groupsetfirstchar && reqchar < 0) reqchar = firstchar;
5026              for (i = 1; i < repeat_min; i++)              for (i = 1; i < repeat_min; i++)
5027                {                {
5028                uschar *hc;                pcre_uchar *hc;
5029                uschar *this_hwm = cd->hwm;                pcre_uchar *this_hwm = cd->hwm;
5030                memcpy(code, previous, len);                memcpy(code, previous, IN_UCHARS(len));
5031                for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE)                for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE)
5032                  {                  {
5033                  PUT(cd->hwm, 0, GET(hc, 0) + len);                  PUT(cd->hwm, 0, GET(hc, 0) + len);
# Line 4771  for (;; ptr++) Line 5077  for (;; ptr++)
5077    
5078          else for (i = repeat_max - 1; i >= 0; i--)          else for (i = repeat_max - 1; i >= 0; i--)
5079            {            {
5080            uschar *hc;            pcre_uchar *hc;
5081            uschar *this_hwm = cd->hwm;            pcre_uchar *this_hwm = cd->hwm;
5082    
5083            *code++ = OP_BRAZERO + repeat_type;            *code++ = OP_BRAZERO + repeat_type;
5084    
# Line 4788  for (;; ptr++) Line 5094  for (;; ptr++)
5094              PUTINC(code, 0, offset);              PUTINC(code, 0, offset);
5095              }              }
5096    
5097            memcpy(code, previous, len);            memcpy(code, previous, IN_UCHARS(len));
5098            for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE)            for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE)
5099              {              {
5100              PUT(cd->hwm, 0, GET(hc, 0) + len + ((i != 0)? 2+LINK_SIZE : 1));              PUT(cd->hwm, 0, GET(hc, 0) + len + ((i != 0)? 2+LINK_SIZE : 1));
# Line 4805  for (;; ptr++) Line 5111  for (;; ptr++)
5111            {            {
5112            int oldlinkoffset;            int oldlinkoffset;
5113            int offset = (int)(code - bralink + 1);            int offset = (int)(code - bralink + 1);
5114            uschar *bra = code - offset;            pcre_uchar *bra = code - offset;
5115            oldlinkoffset = GET(bra, 1);            oldlinkoffset = GET(bra, 1);
5116            bralink = (oldlinkoffset == 0)? NULL : bralink - oldlinkoffset;            bralink = (oldlinkoffset == 0)? NULL : bralink - oldlinkoffset;
5117            *code++ = OP_KET;            *code++ = OP_KET;
# Line 4819  for (;; ptr++) Line 5125  for (;; ptr++)
5125        ONCE brackets can be converted into non-capturing brackets, as the        ONCE brackets can be converted into non-capturing brackets, as the
5126        behaviour of (?:xx)++ is the same as (?>xx)++ and this saves having to        behaviour of (?:xx)++ is the same as (?>xx)++ and this saves having to
5127        deal with possessive ONCEs specially.        deal with possessive ONCEs specially.
5128    
5129        Otherwise, if the quantifier was possessive, we convert the BRA code to        Otherwise, when we are doing the actual compile phase, check to see
5130        the POS form, and the KET code to KETRPOS. (It turns out to be convenient        whether this group is one that could match an empty string. If so,
5131        at runtime to detect this kind of subpattern at both the start and at the        convert the initial operator to the S form (e.g. OP_BRA -> OP_SBRA) so
5132        end.) The use of special opcodes makes it possible to reduce greatly the        that runtime checking can be done. [This check is also applied to ONCE
5133        stack usage in pcre_exec(). If the group is preceded by OP_BRAZERO,        groups at runtime, but in a different way.]
5134        convert this to OP_BRAPOSZERO. Then cancel the possessive flag so that  
5135        the default action below, of wrapping everything inside atomic brackets,        Then, if the quantifier was possessive and the bracket is not a
5136        does not happen.        conditional, we convert the BRA code to the POS form, and the KET code to
5137          KETRPOS. (It turns out to be convenient at runtime to detect this kind of
5138        Then, when we are doing the actual compile phase, check to see whether        subpattern at both the start and at the end.) The use of special opcodes
5139        this group is one that could match an empty string. If so, convert the        makes it possible to reduce greatly the stack usage in pcre_exec(). If
5140        initial operator to the S form (e.g. OP_BRA -> OP_SBRA) so that runtime        the group is preceded by OP_BRAZERO, convert this to OP_BRAPOSZERO.
5141        checking can be done. [This check is also applied to ONCE groups at  
5142        runtime, but in a different way.] */        Then, if the minimum number of matches is 1 or 0, cancel the possessive
5143          flag so that the default action below, of wrapping everything inside
5144          atomic brackets, does not happen. When the minimum is greater than 1,
5145          there will be earlier copies of the group, and so we still have to wrap
5146          the whole thing. */
5147    
5148        else        else
5149          {          {
5150          uschar *ketcode = code - 1 - LINK_SIZE;          pcre_uchar *ketcode = code - 1 - LINK_SIZE;
5151          uschar *bracode = ketcode - GET(ketcode, 1);          pcre_uchar *bracode = ketcode - GET(ketcode, 1);
5152    
5153          if (*bracode == OP_ONCE && possessive_quantifier) *bracode = OP_BRA;          /* Convert possessive ONCE brackets to non-capturing */
5154          if (*bracode == OP_ONCE)  
5155            if ((*bracode == OP_ONCE || *bracode == OP_ONCE_NC) &&
5156                possessive_quantifier) *bracode = OP_BRA;
5157    
5158            /* For non-possessive ONCE brackets, all we need to do is to
5159            set the KET. */
5160    
5161            if (*bracode == OP_ONCE || *bracode == OP_ONCE_NC)
5162            *ketcode = OP_KETRMAX + repeat_type;            *ketcode = OP_KETRMAX + repeat_type;
5163    
5164            /* Handle non-ONCE brackets and possessive ONCEs (which have been
5165            converted to non-capturing above). */
5166    
5167          else          else
5168            {            {
5169            if (possessive_quantifier)            /* In the compile phase, check for empty string matching. */
5170              {  
             *bracode += 1;                   /* Switch to xxxPOS opcodes */  
             *ketcode = OP_KETRPOS;  
             if (brazeroptr != NULL) *brazeroptr = OP_BRAPOSZERO;  
             possessive_quantifier = FALSE;  
             }  
           else *ketcode = OP_KETRMAX + repeat_type;  
   
5171            if (lengthptr == NULL)            if (lengthptr == NULL)
5172              {              {
5173              uschar *scode = bracode;              pcre_uchar *scode = bracode;
5174              do              do
5175                {                {
5176                if (could_be_empty_branch(scode, ketcode, utf8, cd))                if (could_be_empty_branch(scode, ketcode, utf, cd))
5177                  {                  {
5178                  *bracode += OP_SBRA - OP_BRA;                  *bracode += OP_SBRA - OP_BRA;
5179                  break;                  break;
# Line 4868  for (;; ptr++) Line 5182  for (;; ptr++)
5182                }                }
5183              while (*scode == OP_ALT);              while (*scode == OP_ALT);
5184              }              }
5185    
5186              /* Handle possessive quantifiers. */
5187    
5188              if (possessive_quantifier)
5189                {
5190                /* For COND brackets, we wrap the whole thing in a possessively
5191                repeated non-capturing bracket, because we have not invented POS
5192                versions of the COND opcodes. Because we are moving code along, we
5193                must ensure that any pending recursive references are updated. */
5194    
5195                if (*bracode == OP_COND || *bracode == OP_SCOND)
5196                  {
5197                  int nlen = (int)(code - bracode);
5198                  *code = OP_END;
5199                  adjust_recurse(bracode, 1 + LINK_SIZE, utf, cd, save_hwm);
5200                  memmove(bracode + 1 + LINK_SIZE, bracode, IN_UCHARS(nlen));
5201                  code += 1 + LINK_SIZE;
5202                  nlen += 1 + LINK_SIZE;
5203                  *bracode = OP_BRAPOS;
5204                  *code++ = OP_KETRPOS;
5205                  PUTINC(code, 0, nlen);
5206                  PUT(bracode, 1, nlen);
5207                  }
5208    
5209                /* For non-COND brackets, we modify the BRA code and use KETRPOS. */
5210    
5211                else
5212                  {
5213                  *bracode += 1;              /* Switch to xxxPOS opcodes */
5214                  *ketcode = OP_KETRPOS;
5215                  }
5216    
5217                /* If the minimum is zero, mark it as possessive, then unset the
5218                possessive flag when the minimum is 0 or 1. */
5219    
5220                if (brazeroptr != NULL) *brazeroptr = OP_BRAPOSZERO;
5221                if (repeat_min < 2) possessive_quantifier = FALSE;
5222                }
5223    
5224              /* Non-possessive quantifier */
5225    
5226              else *ketcode = OP_KETRMAX + repeat_type;
5227            }            }
5228          }          }
5229        }        }
# Line 4894  for (;; ptr++) Line 5250  for (;; ptr++)
5250      notation is just syntactic sugar, taken from Sun's Java package, but the      notation is just syntactic sugar, taken from Sun's Java package, but the
5251      special opcodes can optimize it.      special opcodes can optimize it.
5252    
5253      Possessively repeated subpatterns have already been handled in the code      Some (but not all) possessively repeated subpatterns have already been
5254      just above, so possessive_quantifier is always FALSE for them at this      completely handled in the code just above. For them, possessive_quantifier
5255      stage.      is always FALSE at this stage.
5256    
5257      Note that the repeated item starts at tempcode, not at previous, which      Note that the repeated item starts at tempcode, not at previous, which
5258      might be the first part of a string whose (former) last char we repeated.      might be the first part of a string whose (former) last char we repeated.
# Line 4910  for (;; ptr++) Line 5266  for (;; ptr++)
5266        int len;        int len;
5267    
5268        if (*tempcode == OP_TYPEEXACT)        if (*tempcode == OP_TYPEEXACT)
5269          tempcode += _pcre_OP_lengths[*tempcode] +          tempcode += PRIV(OP_lengths)[*tempcode] +
5270            ((tempcode[3] == OP_PROP || tempcode[3] == OP_NOTPROP)? 2 : 0);            ((tempcode[1 + IMM2_SIZE] == OP_PROP
5271              || tempcode[1 + IMM2_SIZE] == OP_NOTPROP)? 2 : 0);
5272    
5273        else if (*tempcode == OP_EXACT || *tempcode == OP_NOTEXACT)        else if (*tempcode == OP_EXACT || *tempcode == OP_NOTEXACT)
5274          {          {
5275          tempcode += _pcre_OP_lengths[*tempcode];          tempcode += PRIV(OP_lengths)[*tempcode];
5276  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
5277          if (utf8 && tempcode[-1] >= 0xc0)          if (utf && tempcode[-1] >= 0xc0)
5278            tempcode += _pcre_utf8_table4[tempcode[-1] & 0x3f];            tempcode += PRIV(utf8_table4)[tempcode[-1] & 0x3f];
5279  #endif  #endif
5280          }          }
5281    
# Line 4955  for (;; ptr++) Line 5312  for (;; ptr++)
5312    
5313          default:          default:
5314          *code = OP_END;          *code = OP_END;
5315          adjust_recurse(tempcode, 1 + LINK_SIZE, utf8, cd, save_hwm);          adjust_recurse(tempcode, 1 + LINK_SIZE, utf, cd, save_hwm);
5316          memmove(tempcode + 1+LINK_SIZE, tempcode, len);          memmove(tempcode + 1 + LINK_SIZE, tempcode, IN_UCHARS(len));
5317          code += 1 + LINK_SIZE;          code += 1 + LINK_SIZE;
5318          len += 1 + LINK_SIZE;          len += 1 + LINK_SIZE;
5319          tempcode[0] = OP_ONCE;          tempcode[0] = OP_ONCE;
# Line 4968  for (;; ptr++) Line 5325  for (;; ptr++)
5325        }        }
5326    
5327      /* In all case we no longer have a previous item. We also set the      /* In all case we no longer have a previous item. We also set the
5328      "follows varying string" flag for subsequently encountered reqbytes if      "follows varying string" flag for subsequently encountered reqchars if
5329      it isn't already set and we have just passed a varying length item. */      it isn't already set and we have just passed a varying length item. */
5330    
5331      END_REPEAT:      END_REPEAT:
# Line 4997  for (;; ptr++) Line 5354  for (;; ptr++)
5354        int i, namelen;        int i, namelen;
5355        int arglen = 0;        int arglen = 0;
5356        const char *vn = verbnames;        const char *vn = verbnames;
5357        const uschar *name = ptr + 1;        const pcre_uchar *name = ptr + 1;
5358        const uschar *arg = NULL;        const pcre_uchar *arg = NULL;
5359        previous = NULL;        previous = NULL;
5360        while ((cd->ctypes[*++ptr] & ctype_letter) != 0) {};        while ((cd->ctypes[*++ptr] & ctype_letter) != 0) {};
5361        namelen = (int)(ptr - name);        namelen = (int)(ptr - name);
# Line 5025  for (;; ptr++) Line 5382  for (;; ptr++)
5382        for (i = 0; i < verbcount; i++)        for (i = 0; i < verbcount; i++)
5383          {          {
5384          if (namelen == verbs[i].len &&          if (namelen == verbs[i].len &&
5385              strncmp((char *)name, vn, namelen) == 0)              STRNCMP_UC_C8(name, vn, namelen) == 0)
5386            {            {
5387            /* Check for open captures before ACCEPT and convert it to            /* Check for open captures before ACCEPT and convert it to
5388            ASSERT_ACCEPT if in an assertion. */            ASSERT_ACCEPT if in an assertion. */
# Line 5046  for (;; ptr++) Line 5403  for (;; ptr++)
5403                }                }
5404              *code++ = (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;              *code++ = (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;
5405    
5406              /* Do not set firstbyte after *ACCEPT */              /* Do not set firstchar after *ACCEPT */
5407              if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;              if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
5408              }              }
5409    
5410            /* Handle other cases with/without an argument */            /* Handle other cases with/without an argument */
# Line 5073  for (;; ptr++) Line 5430  for (;; ptr++)
5430              *code = verbs[i].op_arg;              *code = verbs[i].op_arg;
5431              if (*code++ == OP_THEN_ARG) cd->external_flags |= PCRE_HASTHEN;              if (*code++ == OP_THEN_ARG) cd->external_flags |= PCRE_HASTHEN;
5432              *code++ = arglen;              *code++ = arglen;
5433              memcpy(code, arg, arglen);              memcpy(code, arg, IN_UCHARS(arglen));
5434              code += arglen;              code += arglen;
5435              *code++ = 0;              *code++ = 0;
5436              }              }
# Line 5096  for (;; ptr++) Line 5453  for (;; ptr++)
5453        {        {
5454        int i, set, unset, namelen;        int i, set, unset, namelen;
5455        int *optset;        int *optset;
5456        const uschar *name;        const pcre_uchar *name;
5457        uschar *slot;        pcre_uchar *slot;
5458    
5459        switch (*(++ptr))        switch (*(++ptr))
5460          {          {
# Line 5150  for (;; ptr++) Line 5507  for (;; ptr++)
5507            break;            break;
5508    
5509          /* Most other conditions use OP_CREF (a couple change to OP_RREF          /* Most other conditions use OP_CREF (a couple change to OP_RREF
5510          below), and all need to skip 3 bytes at the start of the group. */          below), and all need to skip 1+IMM2_SIZE bytes at the start of the group. */
5511    
5512          code[1+LINK_SIZE] = OP_CREF;          code[1+LINK_SIZE] = OP_CREF;
5513          skipbytes = 3;          skipbytes = 1+IMM2_SIZE;
5514          refsign = -1;          refsign = -1;
5515    
5516          /* Check for a test for recursion in a named group. */          /* Check for a test for recursion in a named group. */
# Line 5200  for (;; ptr++) Line 5557  for (;; ptr++)
5557          while ((cd->ctypes[*ptr] & ctype_word) != 0)          while ((cd->ctypes[*ptr] & ctype_word) != 0)
5558            {            {
5559            if (recno >= 0)            if (recno >= 0)
5560              recno = ((digitab[*ptr] & ctype_digit) != 0)?              recno = (IS_DIGIT(*ptr))? recno * 10 + *ptr - CHAR_0 : -1;
               recno * 10 + *ptr - CHAR_0 : -1;  
5561            ptr++;            ptr++;
5562            }            }
5563          namelen = (int)(ptr - name);          namelen = (int)(ptr - name);
# Line 5249  for (;; ptr++) Line 5605  for (;; ptr++)
5605          slot = cd->name_table;          slot = cd->name_table;
5606          for (i = 0; i < cd->names_found; i++)          for (i = 0; i < cd->names_found; i++)
5607            {            {
5608            if (strncmp((char *)name, (char *)slot+2, namelen) == 0) break;            if (STRNCMP_UC_UC(name, slot+IMM2_SIZE, namelen) == 0) break;
5609            slot += cd->name_entry_size;            slot += cd->name_entry_size;
5610            }            }
5611    
# Line 5265  for (;; ptr++) Line 5621  for (;; ptr++)
5621          /* Search the pattern for a forward reference */          /* Search the pattern for a forward reference */
5622    
5623          else if ((i = find_parens(cd, name, namelen,          else if ((i = find_parens(cd, name, namelen,
5624                          (options & PCRE_EXTENDED) != 0, utf8)) > 0)                          (options & PCRE_EXTENDED) != 0, utf)) > 0)
5625            {            {
5626            PUT2(code, 2+LINK_SIZE, i);            PUT2(code, 2+LINK_SIZE, i);
5627            code[1+LINK_SIZE]++;            code[1+LINK_SIZE]++;
# Line 5291  for (;; ptr++) Line 5647  for (;; ptr++)
5647            recno = 0;            recno = 0;
5648            for (i = 1; i < namelen; i++)            for (i = 1; i < namelen; i++)
5649              {              {
5650              if ((digitab[name[i]] & ctype_digit) == 0)              if (!IS_DIGIT(name[i]))
5651                {                {
5652                *errorcodeptr = ERR15;                *errorcodeptr = ERR15;
5653                goto FAILED;                goto FAILED;
# Line 5306  for (;; ptr++) Line 5662  for (;; ptr++)
5662          /* Similarly, check for the (?(DEFINE) "condition", which is always          /* Similarly, check for the (?(DEFINE) "condition", which is always
5663          false. */          false. */
5664    
5665          else if (namelen == 6 && strncmp((char *)name, STRING_DEFINE, 6) == 0)          else if (namelen == 6 && STRNCMP_UC_C8(name, STRING_DEFINE, 6) == 0)
5666            {            {
5667            code[1+LINK_SIZE] = OP_DEF;            code[1+LINK_SIZE] = OP_DEF;
5668            skipbytes = 1;            skipbytes = 1;
# Line 5386  for (;; ptr++) Line 5742  for (;; ptr++)
5742    
5743          /* ------------------------------------------------------------ */          /* ------------------------------------------------------------ */
5744          case CHAR_C:                 /* Callout - may be followed by digits; */          case CHAR_C:                 /* Callout - may be followed by digits; */
5745          previous_callout = code;  /* Save for later completion */          previous_callout = code;     /* Save for later completion */
5746          after_manual_callout = 1; /* Skip one item before completing */          after_manual_callout = 1;    /* Skip one item before completing */
5747          *code++ = OP_CALLOUT;          *code++ = OP_CALLOUT;
5748            {            {
5749            int n = 0;            int n = 0;
5750            while ((digitab[*(++ptr)] & ctype_digit) != 0)            ptr++;
5751              n = n * 10 + *ptr - CHAR_0;            while(IS_DIGIT(*ptr))
5752                n = n * 10 + *ptr++ - CHAR_0;
5753            if (*ptr != CHAR_RIGHT_PARENTHESIS)            if (*ptr != CHAR_RIGHT_PARENTHESIS)
5754              {              {
5755              *errorcodeptr = ERR39;              *errorcodeptr = ERR39;
# Line 5509  for (;; ptr++) Line 5866  for (;; ptr++)
5866                if (crc < 0)                if (crc < 0)
5867                  {                  {
5868                  memmove(slot + cd->name_entry_size, slot,                  memmove(slot + cd->name_entry_size, slot,
5869                    (cd->names_found - i) * cd->name_entry_size);                    IN_UCHARS((cd->names_found - i) * cd->name_entry_size));
5870                  break;                  break;
5871                  }                  }
5872    
# Line 5523  for (;; ptr++) Line 5880  for (;; ptr++)
5880    
5881              if (!dupname)              if (!dupname)
5882                {                {
5883                uschar *cslot = cd->name_table;                pcre_uchar *cslot = cd->name_table;
5884                for (i = 0; i < cd->names_found; i++)                for (i = 0; i < cd->names_found; i++)
5885                  {                  {
5886                  if (cslot != slot)                  if (cslot != slot)
# Line 5540  for (;; ptr++) Line 5897  for (;; ptr++)
5897                }                }
5898    
5899              PUT2(slot, 0, cd->bracount + 1);              PUT2(slot, 0, cd->bracount + 1);
5900              memcpy(slot + 2, name, namelen);              memcpy(slot + 2, name, IN_UCHARS(namelen));
5901              slot[2+namelen] = 0;              slot[2 + namelen] = 0;
5902              }              }
5903            }            }
5904    
# Line 5579  for (;; ptr++) Line 5936  for (;; ptr++)
5936    
5937          if (lengthptr != NULL)          if (lengthptr != NULL)
5938            {            {
5939            const uschar *temp;            const pcre_uchar *temp;
5940    
5941            if (namelen == 0)            if (namelen == 0)
5942              {              {
# Line 5609  for (;; ptr++) Line 5966  for (;; ptr++)
5966            temp = cd->end_pattern;            temp = cd->end_pattern;
5967            cd->end_pattern = ptr;            cd->end_pattern = ptr;
5968            recno = find_parens(cd, name, namelen,            recno = find_parens(cd, name, namelen,
5969              (options & PCRE_EXTENDED) != 0, utf8);              (options & PCRE_EXTENDED) != 0, utf);
5970            cd->end_pattern = temp;            cd->end_pattern = temp;
5971            if (recno < 0) recno = 0;    /* Forward ref; set dummy number */            if (recno < 0) recno = 0;    /* Forward ref; set dummy number */
5972            }            }
# Line 5624  for (;; ptr++) Line 5981  for (;; ptr++)
5981            slot = cd->name_table;            slot = cd->name_table;
5982            for (i = 0; i < cd->names_found; i++)            for (i = 0; i < cd->names_found; i++)
5983              {              {
5984              if (strncmp((char *)name, (char *)slot+2, namelen) == 0 &&              if (STRNCMP_UC_UC(name, slot+IMM2_SIZE, namelen) == 0 &&
5985                  slot[2+namelen] == 0)                  slot[2+namelen] == 0)
5986                break;                break;
5987              slot += cd->name_entry_size;              slot += cd->name_entry_size;
# Line 5636  for (;; ptr++) Line 5993  for (;; ptr++)
5993              }              }
5994            else if ((recno =                /* Forward back reference */            else if ((recno =                /* Forward back reference */
5995                      find_parens(cd, name, namelen,                      find_parens(cd, name, namelen,
5996                        (options & PCRE_EXTENDED) != 0, utf8)) <= 0)                        (options & PCRE_EXTENDED) != 0, utf)) <= 0)
5997              {              {
5998              *errorcodeptr = ERR15;              *errorcodeptr = ERR15;
5999              goto FAILED;              goto FAILED;
# Line 5661  for (;; ptr++) Line 6018  for (;; ptr++)
6018          case CHAR_0: case CHAR_1: case CHAR_2: case CHAR_3: case CHAR_4:          case CHAR_0: case CHAR_1: case CHAR_2: case CHAR_3: case CHAR_4:
6019          case CHAR_5: case CHAR_6: case CHAR_7: case CHAR_8: case CHAR_9:          case CHAR_5: case CHAR_6: case CHAR_7: case CHAR_8: case CHAR_9:
6020            {            {
6021            const uschar *called;            const pcre_uchar *called;
6022            terminator = CHAR_RIGHT_PARENTHESIS;            terminator = CHAR_RIGHT_PARENTHESIS;
6023    
6024            /* Come here from the \g<...> and \g'...' code (Oniguruma            /* Come here from the \g<...> and \g'...' code (Oniguruma
# Line 5675  for (;; ptr++) Line 6032  for (;; ptr++)
6032            if ((refsign = *ptr) == CHAR_PLUS)            if ((refsign = *ptr) == CHAR_PLUS)
6033              {              {
6034              ptr++;              ptr++;
6035              if ((digitab[*ptr] & ctype_digit) == 0)              if (!IS_DIGIT(*ptr))
6036                {                {
6037                *errorcodeptr = ERR63;                *errorcodeptr = ERR63;
6038                goto FAILED;                goto FAILED;
# Line 5683  for (;; ptr++) Line 6040  for (;; ptr++)
6040              }              }
6041            else if (refsign == CHAR_MINUS)            else if (refsign == CHAR_MINUS)
6042              {              {
6043              if ((digitab[ptr[1]] & ctype_digit) == 0)              if (!IS_DIGIT(ptr[1]))
6044                goto OTHER_CHAR_AFTER_QUERY;                goto OTHER_CHAR_AFTER_QUERY;
6045              ptr++;              ptr++;
6046              }              }
6047    
6048            recno = 0;            recno = 0;
6049            while((digitab[*ptr] & ctype_digit) != 0)            while(IS_DIGIT(*ptr))
6050              recno = recno * 10 + *ptr++ - CHAR_0;              recno = recno * 10 + *ptr++ - CHAR_0;
6051    
6052            if (*ptr != terminator)            if (*ptr != terminator)
# Line 5740  for (;; ptr++) Line 6097  for (;; ptr++)
6097              {              {
6098              *code = OP_END;              *code = OP_END;
6099              if (recno != 0)              if (recno != 0)
6100                called = _pcre_find_bracket(cd->start_code, utf8, recno);                called = PRIV(find_bracket)(cd->start_code, utf, recno);
6101    
6102              /* Forward reference */              /* Forward reference */
6103    
6104              if (called == NULL)              if (called == NULL)
6105                {                {
6106                if (find_parens(cd, NULL, recno,                if (find_parens(cd, NULL, recno,
6107                      (options & PCRE_EXTENDED) != 0, utf8) < 0)                      (options & PCRE_EXTENDED) != 0, utf) < 0)
6108                  {                  {
6109                  *errorcodeptr = ERR15;                  *errorcodeptr = ERR15;
6110                  goto FAILED;                  goto FAILED;
# Line 5771  for (;; ptr++) Line 6128  for (;; ptr++)
6128              conditional subpatterns will be picked up then. */              conditional subpatterns will be picked up then. */
6129    
6130              else if (GET(called, 1) == 0 && cond_depth <= 0 &&              else if (GET(called, 1) == 0 && cond_depth <= 0 &&
6131                       could_be_empty(called, code, bcptr, utf8, cd))                       could_be_empty(called, code, bcptr, utf, cd))
6132                {                {
6133                *errorcodeptr = ERR40;                *errorcodeptr = ERR40;
6134                goto FAILED;                goto FAILED;
# Line 5787  for (;; ptr++) Line 6144  for (;; ptr++)
6144    
6145          /* Can't determine a first byte now */          /* Can't determine a first byte now */
6146    
6147          if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
6148          continue;          continue;
6149    
6150    
# Line 5844  for (;; ptr++) Line 6201  for (;; ptr++)
6201          both phases.          both phases.
6202    
6203          If we are not at the pattern start, reset the greedy defaults and the          If we are not at the pattern start, reset the greedy defaults and the
6204          case value for firstbyte and reqbyte. */          case value for firstchar and reqchar. */
6205    
6206          if (*ptr == CHAR_RIGHT_PARENTHESIS)          if (*ptr == CHAR_RIGHT_PARENTHESIS)
6207            {            {
# Line 5857  for (;; ptr++) Line 6214  for (;; ptr++)
6214              {              {
6215              greedy_default = ((newoptions & PCRE_UNGREEDY) != 0);              greedy_default = ((newoptions & PCRE_UNGREEDY) != 0);
6216              greedy_non_default = greedy_default ^ 1;              greedy_non_default = greedy_default ^ 1;
6217              req_caseopt = ((newoptions & PCRE_CASELESS) != 0)? REQ_CASELESS : 0;              req_caseopt = ((newoptions & PCRE_CASELESS) != 0)? REQ_CASELESS:0;
6218              }              }
6219    
6220            /* Change options at this level, and pass them back for use            /* Change options at this level, and pass them back for use
# Line 5894  for (;; ptr++) Line 6251  for (;; ptr++)
6251        NUMBERED_GROUP:        NUMBERED_GROUP:
6252        cd->bracount += 1;        cd->bracount += 1;
6253        PUT2(code, 1+LINK_SIZE, cd->bracount);        PUT2(code, 1+LINK_SIZE, cd->bracount);
6254        skipbytes = 2;        skipbytes = IMM2_SIZE;
6255        }        }
6256    
6257      /* Process nested bracketed regex. Assertions used not to be repeatable,      /* Process nested bracketed regex. Assertions used not to be repeatable,
# Line 5906  for (;; ptr++) Line 6263  for (;; ptr++)
6263      *code = bravalue;      *code = bravalue;
6264      tempcode = code;      tempcode = code;
6265      tempreqvary = cd->req_varyopt;        /* Save value before bracket */      tempreqvary = cd->req_varyopt;        /* Save value before bracket */
6266        tempbracount = cd->bracount;          /* Save value before bracket */
6267      length_prevgroup = 0;                 /* Initialize for pre-compile phase */      length_prevgroup = 0;                 /* Initialize for pre-compile phase */
6268    
6269      if (!compile_regex(      if (!compile_regex(
# Line 5919  for (;; ptr++) Line 6277  for (;; ptr++)
6277           skipbytes,                       /* Skip over bracket number */           skipbytes,                       /* Skip over bracket number */
6278           cond_depth +           cond_depth +
6279             ((bravalue == OP_COND)?1:0),   /* Depth of condition subpatterns */             ((bravalue == OP_COND)?1:0),   /* Depth of condition subpatterns */
6280           &subfirstbyte,                   /* For possible first char */           &subfirstchar,                   /* For possible first char */
6281           &subreqbyte,                     /* For possible last char */           &subreqchar,                     /* For possible last char */
6282           bcptr,                           /* Current branch chain */           bcptr,                           /* Current branch chain */
6283           cd,                              /* Tables block */           cd,                              /* Tables block */
6284           (lengthptr == NULL)? NULL :      /* Actual compile phase */           (lengthptr == NULL)? NULL :      /* Actual compile phase */
# Line 5928  for (;; ptr++) Line 6286  for (;; ptr++)
6286           ))           ))
6287        goto FAILED;        goto FAILED;
6288    
6289        /* If this was an atomic group and there are no capturing groups within it,
6290        generate OP_ONCE_NC instead of OP_ONCE. */
6291    
6292        if (bravalue == OP_ONCE && cd->bracount <= tempbracount)
6293          *code = OP_ONCE_NC;
6294    
6295      if (bravalue >= OP_ASSERT && bravalue <= OP_ASSERTBACK_NOT)      if (bravalue >= OP_ASSERT && bravalue <= OP_ASSERTBACK_NOT)
6296        cd->assert_depth -= 1;        cd->assert_depth -= 1;
6297    
6298      /* At the end of compiling, code is still pointing to the start of the      /* At the end of compiling, code is still pointing to the start of the
6299      group, while tempcode has been updated to point past the end of the group      group, while tempcode has been updated to point past the end of the group.
6300      and any option resetting that may follow it. The pattern pointer (ptr)      The pattern pointer (ptr) is on the bracket.
     is on the bracket. */  
6301    
6302      /* If this is a conditional bracket, check that there are no more than      If this is a conditional bracket, check that there are no more than
6303      two branches in the group, or just one if it's a DEFINE group. We do this      two branches in the group, or just one if it's a DEFINE group. We do this
6304      in the real compile phase, not in the pre-pass, where the whole group may      in the real compile phase, not in the pre-pass, where the whole group may
6305      not be available. */      not be available. */
6306    
6307      if (bravalue == OP_COND && lengthptr == NULL)      if (bravalue == OP_COND && lengthptr == NULL)
6308        {        {
6309        uschar *tc = code;        pcre_uchar *tc = code;
6310        int condcount = 0;        int condcount = 0;
6311    
6312        do {        do {
# Line 5966  for (;; ptr++) Line 6329  for (;; ptr++)
6329          }          }
6330    
6331        /* A "normal" conditional group. If there is just one branch, we must not        /* A "normal" conditional group. If there is just one branch, we must not
6332        make use of its firstbyte or reqbyte, because this is equivalent to an        make use of its firstchar or reqchar, because this is equivalent to an
6333        empty second branch. */        empty second branch. */
6334    
6335        else        else
# Line 5976  for (;; ptr++) Line 6339  for (;; ptr++)
6339            *errorcodeptr = ERR27;            *errorcodeptr = ERR27;
6340            goto FAILED;            goto FAILED;
6341            }            }
6342          if (condcount == 1) subfirstbyte = subreqbyte = REQ_NONE;          if (condcount == 1) subfirstchar = subreqchar = REQ_NONE;
6343          }          }
6344        }        }
6345    
# Line 6020  for (;; ptr++) Line 6383  for (;; ptr++)
6383      /* Handle updating of the required and first characters for other types of      /* Handle updating of the required and first characters for other types of
6384      group. Update for normal brackets of all kinds, and conditions with two      group. Update for normal brackets of all kinds, and conditions with two
6385      branches (see code above). If the bracket is followed by a quantifier with      branches (see code above). If the bracket is followed by a quantifier with
6386      zero repeat, we have to back off. Hence the definition of zeroreqbyte and      zero repeat, we have to back off. Hence the definition of zeroreqchar and
6387      zerofirstbyte outside the main loop so that they can be accessed for the      zerofirstchar outside the main loop so that they can be accessed for the
6388      back off. */      back off. */
6389    
6390      zeroreqbyte = reqbyte;      zeroreqchar = reqchar;
6391      zerofirstbyte = firstbyte;      zerofirstchar = firstchar;
6392      groupsetfirstbyte = FALSE;      groupsetfirstchar = FALSE;
6393    
6394      if (bravalue >= OP_ONCE)      if (bravalue >= OP_ONCE)
6395        {        {
6396        /* If we have not yet set a firstbyte in this branch, take it from the        /* If we have not yet set a firstchar in this branch, take it from the
6397        subpattern, remembering that it was set here so that a repeat of more        subpattern, remembering that it was set here so that a repeat of more
6398        than one can replicate it as reqbyte if necessary. If the subpattern has        than one can replicate it as reqchar if necessary. If the subpattern has
6399        no firstbyte, set "none" for the whole branch. In both cases, a zero        no firstchar, set "none" for the whole branch. In both cases, a zero
6400        repeat forces firstbyte to "none". */        repeat forces firstchar to "none". */
6401    
6402        if (firstbyte == REQ_UNSET)        if (firstchar == REQ_UNSET)
6403          {          {
6404          if (subfirstbyte >= 0)          if (subfirstchar >= 0)
6405            {            {
6406            firstbyte = subfirstbyte;            firstchar = subfirstchar;
6407            groupsetfirstbyte = TRUE;            groupsetfirstchar = TRUE;
6408            }            }
6409          else firstbyte = REQ_NONE;          else firstchar = REQ_NONE;
6410          zerofirstbyte = REQ_NONE;          zerofirstchar = REQ_NONE;
6411          }          }
6412    
6413        /* If firstbyte was previously set, convert the subpattern's firstbyte        /* If firstchar was previously set, convert the subpattern's firstchar
6414        into reqbyte if there wasn't one, using the vary flag that was in        into reqchar if there wasn't one, using the vary flag that was in
6415        existence beforehand. */        existence beforehand. */
6416    
6417        else if (subfirstbyte >= 0 && subreqbyte < 0)        else if (subfirstchar >= 0 && subreqchar < 0)
6418          subreqbyte = subfirstbyte | tempreqvary;          subreqchar = subfirstchar | tempreqvary;
6419    
6420        /* If the subpattern set a required byte (or set a first byte that isn't        /* If the subpattern set a required byte (or set a first byte that isn't
6421        really the first byte - see above), set it. */        really the first byte - see above), set it. */
6422    
6423        if (subreqbyte >= 0) reqbyte = subreqbyte;        if (subreqchar >= 0) reqchar = subreqchar;
6424        }        }
6425    
6426      /* For a forward assertion, we take the reqbyte, if set. This can be      /* For a forward assertion, we take the reqchar, if set. This can be
6427      helpful if the pattern that follows the assertion doesn't set a different      helpful if the pattern that follows the assertion doesn't set a different
6428      char. For example, it's useful for /(?=abcde).+/. We can't set firstbyte      char. For example, it's useful for /(?=abcde).+/. We can't set firstchar
6429      for an assertion, however because it leads to incorrect effect for patterns      for an assertion, however because it leads to incorrect effect for patterns
6430      such as /(?=a)a.+/ when the "real" "a" would then become a reqbyte instead      such as /(?=a)a.+/ when the "real" "a" would then become a reqchar instead
6431      of a firstbyte. This is overcome by a scan at the end if there's no      of a firstchar. This is overcome by a scan at the end if there's no
6432      firstbyte, looking for an asserted first char. */      firstchar, looking for an asserted first char. */
6433    
6434      else if (bravalue == OP_ASSERT && subreqbyte >= 0) reqbyte = subreqbyte;      else if (bravalue == OP_ASSERT && subreqchar >= 0) reqchar = subreqchar;
6435      break;     /* End of processing '(' */      break;     /* End of processing '(' */
6436    
6437    
# Line 6101  for (;; ptr++) Line 6464  for (;; ptr++)
6464        /* For metasequences that actually match a character, we disable the        /* For metasequences that actually match a character, we disable the
6465        setting of a first character if it hasn't already been set. */        setting of a first character if it hasn't already been set. */
6466    
6467        if (firstbyte == REQ_UNSET && -c > ESC_b && -c < ESC_Z)        if (firstchar == REQ_UNSET && -c > ESC_b && -c < ESC_Z)
6468          firstbyte = REQ_NONE;          firstchar = REQ_NONE;
6469    
6470        /* Set values to reset to if this is followed by a zero repeat. */        /* Set values to reset to if this is followed by a zero repeat. */
6471    
6472        zerofirstbyte = firstbyte;        zerofirstchar = firstchar;
6473        zeroreqbyte = reqbyte;        zeroreqchar = reqchar;
6474    
6475        /* \g<name> or \g'name' is a subroutine call by name and \g<n> or \g'n'        /* \g<name> or \g'name' is a subroutine call by name and \g<n> or \g'n'
6476        is a subroutine call by number (Oniguruma syntax). In fact, the value        is a subroutine call by number (Oniguruma syntax). In fact, the value
# Line 6118  for (;; ptr++) Line 6481  for (;; ptr++)
6481    
6482        if (-c == ESC_g)        if (-c == ESC_g)
6483          {          {
6484          const uschar *p;          const pcre_uchar *p;
6485          save_hwm = cd->hwm;   /* Normally this is set when '(' is read */          save_hwm = cd->hwm;   /* Normally this is set when '(' is read */
6486          terminator = (*(++ptr) == CHAR_LESS_THAN_SIGN)?          terminator = (*(++ptr) == CHAR_LESS_THAN_SIGN)?
6487            CHAR_GREATER_THAN_SIGN : CHAR_APOSTROPHE;            CHAR_GREATER_THAN_SIGN : CHAR_APOSTROPHE;
# Line 6158  for (;; ptr++) Line 6521  for (;; ptr++)
6521          /* Test a signed number in angle brackets or quotes. */          /* Test a signed number in angle brackets or quotes. */
6522    
6523          p = ptr + 2;          p = ptr + 2;
6524          while ((digitab[*p] & ctype_digit) != 0) p++;          while (IS_DIGIT(*p)) p++;
6525          if (*p != terminator)          if (*p != terminator)
6526            {            {
6527            *errorcodeptr = ERR57;            *errorcodeptr = ERR57;
# Line 6186  for (;; ptr++) Line 6549  for (;; ptr++)
6549          goto NAMED_REF_OR_RECURSE;          goto NAMED_REF_OR_RECURSE;
6550          }          }
6551    
6552        /* Back references are handled specially; must disable firstbyte if        /* Back references are handled specially; must disable firstchar if
6553        not set to cope with cases like (?=(\w+))\1: which would otherwise set        not set to cope with cases like (?=(\w+))\1: which would otherwise set
6554        ':' later. */        ':' later. */
6555    
# Line 6196  for (;; ptr++) Line 6559  for (;; ptr++)
6559          recno = -c - ESC_REF;          recno = -c - ESC_REF;
6560    
6561          HANDLE_REFERENCE:    /* Come here from named backref handling */          HANDLE_REFERENCE:    /* Come here from named backref handling */
6562          if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
6563          previous = code;          previous = code;
6564          *code++ = ((options & PCRE_CASELESS) != 0)? OP_REFI : OP_REF;          *code++ = ((options & PCRE_CASELESS) != 0)? OP_REFI : OP_REF;
6565          PUT2INC(code, 0, recno);          PUT2INC(code, 0, recno);
# Line 6258  for (;; ptr++) Line 6621  for (;; ptr++)
6621            }            }
6622          else          else
6623  #endif  #endif
6624            {          /* In non-UTF-8 mode, we turn \C into OP_ALLANY instead of OP_ANYBYTE
6625            so that it works in DFA mode and in lookbehinds. */
6626    
6627              {
6628            previous = (-c > ESC_b && -c < ESC_Z)? code : NULL;            previous = (-c > ESC_b && -c < ESC_Z)? code : NULL;
6629            *code++ = -c;            *code++ = (!utf && c == -ESC_C)? OP_ALLANY : -c;
6630            }            }
6631          }          }
6632        continue;        continue;
# Line 6271  for (;; ptr++) Line 6637  for (;; ptr++)
6637      handle it as a data character. */      handle it as a data character. */
6638    
6639  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
6640      if (utf8 && c > 127)      if (utf && c > 127)
6641        mclength = _pcre_ord2utf8(c, mcbuffer);        mclength = PRIV(ord2utf)(c, mcbuffer);
6642      else      else
6643  #endif  #endif
6644    
# Line 6294  for (;; ptr++) Line 6660  for (;; ptr++)
6660      mcbuffer[0] = c;      mcbuffer[0] = c;
6661    
6662  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
6663      if (utf8 && c >= 0xc0)      if (utf && c >= 0xc0)
6664        {        {
6665        while ((ptr[1] & 0xc0) == 0x80)        while ((ptr[1] & 0xc0) == 0x80)
6666          mcbuffer[mclength++] = *(++ptr);          mcbuffer[mclength++] = *(++ptr);
# Line 6316  for (;; ptr++) Line 6682  for (;; ptr++)
6682    
6683      /* Set the first and required bytes appropriately. If no previous first      /* Set the first and required bytes appropriately. If no previous first
6684      byte, set it from this character, but revert to none on a zero repeat.      byte, set it from this character, but revert to none on a zero repeat.
6685      Otherwise, leave the firstbyte value alone, and don't change it on a zero      Otherwise, leave the firstchar value alone, and don't change it on a zero
6686      repeat. */      repeat. */
6687    
6688      if (firstbyte == REQ_UNSET)      if (firstchar == REQ_UNSET)
6689        {        {
6690        zerofirstbyte = REQ_NONE;        zerofirstchar = REQ_NONE;
6691        zeroreqbyte = reqbyte;        zeroreqchar = reqchar;
6692    
6693        /* If the character is more than one byte long, we can set firstbyte        /* If the character is more than one byte long, we can set firstchar
6694        only if it is not to be matched caselessly. */        only if it is not to be matched caselessly. */
6695    
6696        if (mclength == 1 || req_caseopt == 0)        if (mclength == 1 || req_caseopt == 0)
6697          {          {
6698          firstbyte = mcbuffer[0] | req_caseopt;          firstchar = mcbuffer[0] | req_caseopt;
6699          if (mclength != 1) reqbyte = code[-1] | cd->req_varyopt;          if (mclength != 1) reqchar = code[-1] | cd->req_varyopt;
6700          }          }
6701        else firstbyte = reqbyte = REQ_NONE;        else firstchar = reqchar = REQ_NONE;
6702        }        }
6703    
6704      /* firstbyte was previously set; we can set reqbyte only if the length is      /* firstchar was previously set; we can set reqchar only if the length is
6705      1 or the matching is caseful. */      1 or the matching is caseful. */
6706    
6707      else      else
6708        {        {
6709        zerofirstbyte = firstbyte;        zerofirstchar = firstchar;
6710        zeroreqbyte = reqbyte;        zeroreqchar = reqchar;
6711        if (mclength == 1 || req_caseopt == 0)        if (mclength == 1 || req_caseopt == 0)
6712          reqbyte = code[-1] | req_caseopt | cd->req_varyopt;          reqchar = code[-1] | req_caseopt | cd->req_varyopt;
6713        }        }
6714    
6715      break;            /* End of literal character handling */      break;            /* End of literal character handling */
# Line 6383  Arguments: Line 6749  Arguments:
6749    reset_bracount TRUE to reset the count for each branch    reset_bracount TRUE to reset the count for each branch
6750    skipbytes      skip this many bytes at start (for brackets and OP_COND)    skipbytes      skip this many bytes at start (for brackets and OP_COND)
6751    cond_depth     depth of nesting for conditional subpatterns    cond_depth     depth of nesting for conditional subpatterns
6752    firstbyteptr   place to put the first required character, or a negative number    firstcharptr   place to put the first required character, or a negative number
6753    reqbyteptr     place to put the last required character, or a negative number    reqcharptr     place to put the last required character, or a negative number
6754    bcptr          pointer to the chain of currently open branches    bcptr          pointer to the chain of currently open branches
6755    cd             points to the data block with tables pointers etc.    cd             points to the data block with tables pointers etc.
6756    lengthptr      NULL during the real compile phase    lengthptr      NULL during the real compile phase
# Line 6394  Returns:         TRUE on success Line 6760  Returns:         TRUE on success
6760  */  */
6761    
6762  static BOOL  static BOOL
6763  compile_regex(int options, uschar **codeptr, const uschar **ptrptr,  compile_regex(int options, pcre_uchar **codeptr, const pcre_uchar **ptrptr,
6764    int *errorcodeptr, BOOL lookbehind, BOOL reset_bracount, int skipbytes,    int *errorcodeptr, BOOL lookbehind, BOOL reset_bracount, int skipbytes,
6765    int cond_depth, int *firstbyteptr, int *reqbyteptr, branch_chain *bcptr,    int cond_depth, pcre_int32 *firstcharptr, pcre_int32 *reqcharptr,
6766    compile_data *cd, int *lengthptr)    branch_chain *bcptr, compile_data *cd, int *lengthptr)
6767  {  {
6768  const uschar *ptr = *ptrptr;  const pcre_uchar *ptr = *ptrptr;
6769  uschar *code = *codeptr;  pcre_uchar *code = *codeptr;
6770  uschar *last_branch = code;  pcre_uchar *last_branch = code;
6771  uschar *start_bracket = code;  pcre_uchar *start_bracket = code;
6772  uschar *reverse_count = NULL;  pcre_uchar *reverse_count = NULL;
6773  open_capitem capitem;  open_capitem capitem;
6774  int capnumber = 0;  int capnumber = 0;
6775  int firstbyte, reqbyte;  pcre_int32 firstchar, reqchar;
6776  int branchfirstbyte, branchreqbyte;  pcre_int32 branchfirstchar, branchreqchar;
6777  int length;  int length;
6778  int orig_bracount;  int orig_bracount;
6779  int max_bracount;  int max_bracount;
# Line 6416  branch_chain bc; Line 6782  branch_chain bc;
6782  bc.outer = bcptr;  bc.outer = bcptr;
6783  bc.current_branch = code;  bc.current_branch = code;
6784    
6785  firstbyte = reqbyte = REQ_UNSET;  firstchar = reqchar = REQ_UNSET;
6786    
6787  /* Accumulate the length for use in the pre-compile phase. Start with the  /* Accumulate the length for use in the pre-compile phase. Start with the
6788  length of the BRA and KET and any extra bytes that are required at the  length of the BRA and KET and any extra bytes that are required at the
# Line 6475  for (;;) Line 6841  for (;;)
6841    /* Now compile the branch; in the pre-compile phase its length gets added    /* Now compile the branch; in the pre-compile phase its length gets added
6842    into the length. */    into the length. */
6843    
6844    if (!compile_branch(&options, &code, &ptr, errorcodeptr, &branchfirstbyte,    if (!compile_branch(&options, &code, &ptr, errorcodeptr, &branchfirstchar,
6845          &branchreqbyte, &bc, cond_depth, cd,          &branchreqchar, &bc, cond_depth, cd,
6846          (lengthptr == NULL)? NULL : &length))          (lengthptr == NULL)? NULL : &length))
6847      {      {
6848      *ptrptr = ptr;      *ptrptr = ptr;
# Line 6492  for (;;) Line 6858  for (;;)
6858    
6859    if (lengthptr == NULL)    if (lengthptr == NULL)
6860      {      {
6861      /* If this is the first branch, the firstbyte and reqbyte values for the      /* If this is the first branch, the firstchar and reqchar values for the
6862      branch become the values for the regex. */      branch become the values for the regex. */
6863    
6864      if (*last_branch != OP_ALT)      if (*last_branch != OP_ALT)
6865        {        {
6866        firstbyte = branchfirstbyte;        firstchar = branchfirstchar;
6867        reqbyte = branchreqbyte;        reqchar = branchreqchar;
6868        }        }
6869    
6870      /* If this is not the first branch, the first char and reqbyte have to      /* If this is not the first branch, the first char and reqchar have to
6871      match the values from all the previous branches, except that if the      match the values from all the previous branches, except that if the
6872      previous value for reqbyte didn't have REQ_VARY set, it can still match,      previous value for reqchar didn't have REQ_VARY set, it can still match,
6873      and we set REQ_VARY for the regex. */      and we set REQ_VARY for the regex. */
6874    
6875      else      else
6876        {        {
6877        /* If we previously had a firstbyte, but it doesn't match the new branch,        /* If we previously had a firstchar, but it doesn't match the new branch,
6878        we have to abandon the firstbyte for the regex, but if there was        we have to abandon the firstchar for the regex, but if there was
6879        previously no reqbyte, it takes on the value of the old firstbyte. */        previously no reqchar, it takes on the value of the old firstchar. */
6880    
6881        if (firstbyte >= 0 && firstbyte != branchfirstbyte)        if (firstchar >= 0 && firstchar != branchfirstchar)
6882          {          {
6883          if (reqbyte < 0) reqbyte = firstbyte;          if (reqchar < 0) reqchar = firstchar;
6884          firstbyte = REQ_NONE;          firstchar = REQ_NONE;
6885          }          }
6886    
6887        /* If we (now or from before) have no firstbyte, a firstbyte from the        /* If we (now or from before) have no firstchar, a firstchar from the
6888        branch becomes a reqbyte if there isn't a branch reqbyte. */        branch becomes a reqchar if there isn't a branch reqchar. */
6889    
6890        if (firstbyte < 0 && branchfirstbyte >= 0 && branchreqbyte < 0)        if (firstchar < 0 && branchfirstchar >= 0 && branchreqchar < 0)
6891            branchreqbyte = branchfirstbyte;            branchreqchar = branchfirstchar;
6892    
6893        /* Now ensure that the reqbytes match */        /* Now ensure that the reqchars match */
6894    
6895        if ((reqbyte & ~REQ_VARY) != (branchreqbyte & ~REQ_VARY))        if ((reqchar & ~REQ_VARY) != (branchreqchar & ~REQ_VARY))
6896          reqbyte = REQ_NONE;          reqchar = REQ_NONE;
6897        else reqbyte |= branchreqbyte;   /* To "or" REQ_VARY */        else reqchar |= branchreqchar;   /* To "or" REQ_VARY */
6898        }        }
6899    
6900      /* If lookbehind, check that this branch matches a fixed-length string, and      /* If lookbehind, check that this branch matches a fixed-length string, and
# Line 6552  for (;;) Line 6918  for (;;)
6918          }          }
6919        else if (fixed_length < 0)        else if (fixed_length < 0)
6920          {          {
6921          *errorcodeptr = (fixed_length == -2)? ERR36 : ERR25;          *errorcodeptr = (fixed_length == -2)? ERR36 :
6922                            (fixed_length == -4)? ERR70: ERR25;
6923          *ptrptr = ptr;          *ptrptr = ptr;
6924          return FALSE;          return FALSE;
6925          }          }
# Line 6597  for (;;) Line 6964  for (;;)
6964        if (cd->open_caps->flag)        if (cd->open_caps->flag)
6965          {          {
6966          memmove(start_bracket + 1 + LINK_SIZE, start_bracket,          memmove(start_bracket + 1 + LINK_SIZE, start_bracket,
6967            code - start_bracket);            IN_UCHARS(code - start_bracket));
6968          *start_bracket = OP_ONCE;          *start_bracket = OP_ONCE;
6969          code += 1 + LINK_SIZE;          code += 1 + LINK_SIZE;
6970          PUT(start_bracket, 1, (int)(code - start_bracket));          PUT(start_bracket, 1, (int)(code - start_bracket));
# Line 6617  for (;;) Line 6984  for (;;)
6984    
6985      *codeptr = code;      *codeptr = code;
6986      *ptrptr = ptr;      *ptrptr = ptr;
6987      *firstbyteptr = firstbyte;      *firstcharptr = firstchar;
6988      *reqbyteptr = reqbyte;      *reqcharptr = reqchar;
6989      if (lengthptr != NULL)      if (lengthptr != NULL)
6990        {        {
6991        if (OFLOW_MAX - *lengthptr < length)        if (OFLOW_MAX - *lengthptr < length)
# Line 6699  Returns:     TRUE or FALSE Line 7066  Returns:     TRUE or FALSE
7066  */  */
7067    
7068  static BOOL  static BOOL
7069  is_anchored(register const uschar *code, unsigned int bracket_map,  is_anchored(register const pcre_uchar *code, unsigned int bracket_map,
7070    unsigned int backref_map)    unsigned int backref_map)
7071  {  {
7072  do {  do {
7073     const uschar *scode = first_significant_code(code + _pcre_OP_lengths[*code],     const pcre_uchar *scode = first_significant_code(
7074       FALSE);       code + PRIV(OP_lengths)[*code], FALSE);
7075     register int op = *scode;     register int op = *scode;
7076    
7077     /* Non-capturing brackets */     /* Non-capturing brackets */
# Line 6727  do { Line 7094  do {
7094    
7095     /* Other brackets */     /* Other brackets */
7096    
7097     else if (op == OP_ASSERT || op == OP_ONCE || op == OP_COND)     else if (op == OP_ASSERT || op == OP_ONCE || op == OP_ONCE_NC ||
7098                op == OP_COND)
7099       {       {
7100       if (!is_anchored(scode, bracket_map, backref_map)) return FALSE;       if (!is_anchored(scode, bracket_map, backref_map)) return FALSE;
7101       }       }
# Line 6775  Returns:         TRUE or FALSE Line 7143  Returns:         TRUE or FALSE
7143  */  */
7144    
7145  static BOOL  static BOOL
7146  is_startline(const uschar *code, unsigned int bracket_map,  is_startline(const pcre_uchar *code, unsigned int bracket_map,
7147    unsigned int backref_map)    unsigned int backref_map)
7148  {  {
7149  do {  do {
7150     const uschar *scode = first_significant_code(code + _pcre_OP_lengths[*code],     const pcre_uchar *scode = first_significant_code(
7151       FALSE);       code + PRIV(OP_lengths)[*code], FALSE);
7152     register int op = *scode;     register int op = *scode;
7153    
7154     /* If we are at the start of a conditional assertion group, *both* the     /* If we are at the start of a conditional assertion group, *both* the
# Line 6791  do { Line 7159  do {
7159     if (op == OP_COND)     if (op == OP_COND)
7160       {       {
7161       scode += 1 + LINK_SIZE;       scode += 1 + LINK_SIZE;
7162       if (*scode == OP_CALLOUT) scode += _pcre_OP_lengths[OP_CALLOUT];       if (*scode == OP_CALLOUT) scode += PRIV(OP_lengths)[OP_CALLOUT];
7163       switch (*scode)       switch (*scode)
7164         {         {
7165         case OP_CREF:         case OP_CREF:
# Line 6831  do { Line 7199  do {
7199    
7200     /* Other brackets */     /* Other brackets */
7201    
7202     else if (op == OP_ASSERT || op == OP_ONCE)     else if (op == OP_ASSERT || op == OP_ONCE || op == OP_ONCE_NC)
7203       {       {
7204       if (!is_startline(scode, bracket_map, backref_map)) return FALSE;       if (!is_startline(scode, bracket_map, backref_map)) return FALSE;
7205       }       }
# Line 6878  Returns:     -1 or the fixed first char Line 7246  Returns:     -1 or the fixed first char
7246  */  */
7247    
7248  static int  static int
7249  find_firstassertedchar(const uschar *code, BOOL inassert)  find_firstassertedchar(const pcre_uchar *code, BOOL inassert)
7250  {  {
7251  register int c = -1;  register int c = -1;
7252  do {  do {
7253     int d;     int d;
7254     int xl = (*code == OP_CBRA || *code == OP_SCBRA ||     int xl = (*code == OP_CBRA || *code == OP_SCBRA ||
7255               *code == OP_CBRAPOS || *code == OP_SCBRAPOS)? 2:0;               *code == OP_CBRAPOS || *code == OP_SCBRAPOS)? IMM2_SIZE:0;
7256     const uschar *scode = first_significant_code(code + 1+LINK_SIZE + xl, TRUE);     const pcre_uchar *scode = first_significant_code(code + 1+LINK_SIZE + xl,
7257         TRUE);
7258     register int op = *scode;     register int op = *scode;
7259    
7260     switch(op)     switch(op)
# Line 6901  do { Line 7270  do {
7270       case OP_SCBRAPOS:       case OP_SCBRAPOS:
7271       case OP_ASSERT:       case OP_ASSERT:
7272       case OP_ONCE:       case OP_ONCE:
7273         case OP_ONCE_NC:
7274       case OP_COND:       case OP_COND:
7275       if ((d = find_firstassertedchar(scode, op == OP_ASSERT)) < 0)       if ((d = find_firstassertedchar(scode, op == OP_ASSERT)) < 0)
7276         return -1;         return -1;
# Line 6908  do { Line 7278  do {
7278       break;       break;
7279    
7280       case OP_EXACT:       case OP_EXACT:
7281       scode += 2;       scode += IMM2_SIZE;
7282       /* Fall through */       /* Fall through */
7283    
7284       case OP_CHAR:       case OP_CHAR:
# Line 6921  do { Line 7291  do {
7291       break;       break;
7292    
7293       case OP_EXACTI:       case OP_EXACTI:
7294       scode += 2;       scode += IMM2_SIZE;
7295       /* Fall through */       /* Fall through */
7296    
7297       case OP_CHARI:       case OP_CHARI:
# Line 6964  Returns:        pointer to compiled data Line 7334  Returns:        pointer to compiled data
7334                  with errorptr and erroroffset set                  with errorptr and erroroffset set
7335  */  */
7336    
7337    #ifdef COMPILE_PCRE8
7338  PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION  PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION
7339  pcre_compile(const char *pattern, int options, const char **errorptr,  pcre_compile(const char *pattern, int options, const char **errorptr,
7340    int *erroroffset, const unsigned char *tables)    int *erroroffset, const unsigned char *tables)
7341    #else
7342    PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION
7343    pcre16_compile(PCRE_SPTR16 pattern, int options, const char **errorptr,
7344      int *erroroffset, const unsigned char *tables)
7345    #endif
7346  {  {
7347    #ifdef COMPILE_PCRE8
7348  return pcre_compile2(pattern, options, NULL, errorptr, erroroffset, tables);  return pcre_compile2(pattern, options, NULL, errorptr, erroroffset, tables);
7349    #else
7350    return pcre16_compile2(pattern, options, NULL, errorptr, erroroffset, tables);
7351    #endif
7352  }  }
7353    
7354    
7355    #ifdef COMPILE_PCRE8
7356  PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION  PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION
7357  pcre_compile2(const char *pattern, int options, int *errorcodeptr,  pcre_compile2(const char *pattern, int options, int *errorcodeptr,
7358    const char **errorptr, int *erroroffset, const unsigned char *tables)    const char **errorptr, int *erroroffset, const unsigned char *tables)
7359    #else
7360    PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION
7361    pcre16_compile2(PCRE_SPTR16 pattern, int options, int *errorcodeptr,
7362      const char **errorptr, int *erroroffset, const unsigned char *tables)
7363    #endif
7364  {  {
7365  real_pcre *re;  real_pcre *re;
7366  int length = 1;  /* For final END opcode */  int length = 1;  /* For final END opcode */
7367  int firstbyte, reqbyte, newline;  pcre_int32 firstchar, reqchar;
7368    int newline;
7369  int errorcode = 0;  int errorcode = 0;
7370  int skipatstart = 0;  int skipatstart = 0;
7371  BOOL utf8;  BOOL utf;
7372  size_t size;  size_t size;
7373  uschar *code;  pcre_uchar *code;
7374  const uschar *codestart;  const pcre_uchar *codestart;
7375  const uschar *ptr;  const pcre_uchar *ptr;
7376  compile_data compile_block;  compile_data compile_block;
7377  compile_data *cd = &compile_block;  compile_data *cd = &compile_block;
7378    
# Line 6995  as soon as possible, so that a fairly la Line 7382  as soon as possible, so that a fairly la
7382  this purpose. The same space is used in the second phase for remembering where  this purpose. The same space is used in the second phase for remembering where
7383  to fill in forward references to subpatterns. */  to fill in forward references to subpatterns. */
7384    
7385  uschar cworkspace[COMPILE_WORK_SIZE];  pcre_uchar cworkspace[COMPILE_WORK_SIZE];
7386    
7387  /* Set this early so that early errors get offset 0. */  /* Set this early so that early errors get offset 0. */
7388    
7389  ptr = (const uschar *)pattern;  ptr = (const pcre_uchar *)pattern;
7390    
7391  /* We can't pass back an error message if errorptr is NULL; I guess the best we  /* We can't pass back an error message if errorptr is NULL; I guess the best we
7392  can do is just return NULL, but we can set a code value if there is a code  can do is just return NULL, but we can set a code value if there is a code
# Line 7026  if (erroroffset == NULL) Line 7413  if (erroroffset == NULL)
7413    
7414  /* Set up pointers to the individual character tables */  /* Set up pointers to the individual character tables */
7415    
7416  if (tables == NULL) tables = _pcre_default_tables;  if (tables == NULL) tables = PRIV(default_tables);
7417  cd->lcc = tables + lcc_offset;  cd->lcc = tables + lcc_offset;
7418  cd->fcc = tables + fcc_offset;  cd->fcc = tables + fcc_offset;
7419  cd->cbits = tables + cbits_offset;  cd->cbits = tables + cbits_offset;
# Line 7049  while (ptr[skipatstart] == CHAR_LEFT_PAR Line 7436  while (ptr[skipatstart] == CHAR_LEFT_PAR
7436    int newnl = 0;    int newnl = 0;
7437    int newbsr = 0;    int newbsr = 0;
7438    
7439    if (strncmp((char *)(ptr+skipatstart+2), STRING_UTF8_RIGHTPAR, 5) == 0)    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF8_RIGHTPAR, 5) == 0)
7440      { skipatstart += 7; options |= PCRE_UTF8; continue; }      { skipatstart += 7; options |= PCRE_UTF8; continue; }
7441    else if (strncmp((char *)(ptr+skipatstart+2), STRING_UCP_RIGHTPAR, 4) == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UCP_RIGHTPAR, 4) == 0)
7442      { skipatstart += 6; options |= PCRE_UCP; continue; }      { skipatstart += 6; options |= PCRE_UCP; continue; }
7443    else if (strncmp((char *)(ptr+skipatstart+2), STRING_NO_START_OPT_RIGHTPAR, 13) == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_NO_START_OPT_RIGHTPAR, 13) == 0)
7444      { skipatstart += 15; options |= PCRE_NO_START_OPTIMIZE; continue; }      { skipatstart += 15; options |= PCRE_NO_START_OPTIMIZE; continue; }
7445    
7446    if (strncmp((char *)(ptr+skipatstart+2), STRING_CR_RIGHTPAR, 3) == 0)    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_CR_RIGHTPAR, 3) == 0)
7447      { skipatstart += 5; newnl = PCRE_NEWLINE_CR; }      { skipatstart += 5; newnl = PCRE_NEWLINE_CR; }
7448    else if (strncmp((char *)(ptr+skipatstart+2), STRING_LF_RIGHTPAR, 3)  == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_LF_RIGHTPAR, 3)  == 0)
7449      { skipatstart += 5; newnl = PCRE_NEWLINE_LF; }      { skipatstart += 5; newnl = PCRE_NEWLINE_LF; }
7450    else if (strncmp((char *)(ptr+skipatstart+2), STRING_CRLF_RIGHTPAR, 5)  == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_CRLF_RIGHTPAR, 5)  == 0)
7451      { skipatstart += 7; newnl = PCRE_NEWLINE_CR + PCRE_NEWLINE_LF; }      { skipatstart += 7; newnl = PCRE_NEWLINE_CR + PCRE_NEWLINE_LF; }
7452    else if (strncmp((char *)(ptr+skipatstart+2), STRING_ANY_RIGHTPAR, 4) == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_ANY_RIGHTPAR, 4) == 0)
7453      { skipatstart += 6; newnl = PCRE_NEWLINE_ANY; }      { skipatstart += 6; newnl = PCRE_NEWLINE_ANY; }
7454    else if (strncmp((char *)(ptr+skipatstart+2), STRING_ANYCRLF_RIGHTPAR, 8) == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_ANYCRLF_RIGHTPAR, 8) == 0)
7455      { skipatstart += 10; newnl = PCRE_NEWLINE_ANYCRLF; }      { skipatstart += 10; newnl = PCRE_NEWLINE_ANYCRLF; }
7456    
7457    else if (strncmp((char *)(ptr+skipatstart+2), STRING_BSR_ANYCRLF_RIGHTPAR, 12) == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_BSR_ANYCRLF_RIGHTPAR, 12) == 0)
7458      { skipatstart += 14; newbsr = PCRE_BSR_ANYCRLF; }      { skipatstart += 14; newbsr = PCRE_BSR_ANYCRLF; }
7459    else if (strncmp((char *)(ptr+skipatstart+2), STRING_BSR_UNICODE_RIGHTPAR, 12) == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_BSR_UNICODE_RIGHTPAR, 12) == 0)
7460      { skipatstart += 14; newbsr = PCRE_BSR_UNICODE; }      { skipatstart += 14; newbsr = PCRE_BSR_UNICODE; }
7461    
7462    if (newnl != 0)    if (newnl != 0)
# Line 7079  while (ptr[skipatstart] == CHAR_LEFT_PAR Line 7466  while (ptr[skipatstart] == CHAR_LEFT_PAR
7466    else break;    else break;
7467    }    }
7468    
7469  utf8 = (options & PCRE_UTF8) != 0;  /* PCRE_UTF16 has the same value as PCRE_UTF8. */
7470    utf = (options & PCRE_UTF8) != 0;
7471    
7472  /* Can't support UTF8 unless PCRE has been compiled to include the code. The  /* Can't support UTF8 unless PCRE has been compiled to include the code. The
7473  return of an error code from _pcre_valid_utf8() is a new feature, introduced in  return of an error code from PRIV(valid_utf)() is a new feature, introduced in
7474  release 8.13. It is passed back from pcre_[dfa_]exec(), but at the moment is  release 8.13. It is passed back from pcre_[dfa_]exec(), but at the moment is
7475  not used here. */  not used here. */
7476    
7477  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
7478  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0 &&  if (utf && (options & PCRE_NO_UTF8_CHECK) == 0 &&
7479       (errorcode = _pcre_valid_utf8((USPTR)pattern, -1, erroroffset)) != 0)       (errorcode = PRIV(valid_utf)((PCRE_PUCHAR)pattern, -1, erroroffset)) != 0)
7480    {    {
7481    errorcode = ERR44;    errorcode = ERR44;
7482    goto PCRE_EARLY_ERROR_RETURN2;    goto PCRE_EARLY_ERROR_RETURN2;
7483    }    }
7484  #else  #else
7485  if (utf8)  if (utf)
7486    {    {
7487    errorcode = ERR32;    errorcode = ERR32;
7488    goto PCRE_EARLY_ERROR_RETURN;    goto PCRE_EARLY_ERROR_RETURN;
# Line 7170  cd->backref_map = 0; Line 7558  cd->backref_map = 0;
7558  /* Reflect pattern for debugging output */  /* Reflect pattern for debugging output */
7559    
7560  DPRINTF(("------------------------------------------------------------------\n"));  DPRINTF(("------------------------------------------------------------------\n"));
7561  DPRINTF(("%s\n", pattern));  #ifdef PCRE_DEBUG
7562    print_puchar(stdout, (PCRE_PUCHAR)pattern);
7563    #endif
7564    DPRINTF(("\n"));
7565    
7566  /* Pretend to compile the pattern while actually just accumulating the length  /* Pretend to compile the pattern while actually just accumulating the length
7567  of memory required. This behaviour is triggered by passing a non-NULL final  of memory required. This behaviour is triggered by passing a non-NULL final
# Line 7186  cd->name_table = NULL; Line 7577  cd->name_table = NULL;
7577  cd->start_workspace = cworkspace;  cd->start_workspace = cworkspace;
7578  cd->start_code = cworkspace;  cd->start_code = cworkspace;
7579  cd->hwm = cworkspace;  cd->hwm = cworkspace;
7580  cd->start_pattern = (const uschar *)pattern;  cd->start_pattern = (const pcre_uchar *)pattern;
7581  cd->end_pattern = (const uschar *)(pattern + strlen(pattern));  cd->end_pattern = (const pcre_uchar *)(pattern + STRLEN_UC((const pcre_uchar *)pattern));
7582  cd->req_varyopt = 0;  cd->req_varyopt = 0;
7583  cd->external_options = options;  cd->external_options = options;
7584  cd->external_flags = 0;  cd->external_flags = 0;
# Line 7203  ptr += skipatstart; Line 7594  ptr += skipatstart;