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

Diff of /code/trunk/pcre_compile.c

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

revision 702 by ph10, Tue Sep 20 15:45:06 2011 UTC revision 760 by ph10, Tue Nov 22 11:23:43 2011 UTC
# Line 410  static const char error_texts[] = Line 410  static const char error_texts[] =
410    "this version of PCRE is not compiled with PCRE_UCP support\0"    "this version of PCRE is not compiled with PCRE_UCP support\0"
411    "\\c must be followed by an ASCII character\0"    "\\c must be followed by an ASCII character\0"
412    "\\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"
413      /* 70 */
414      "internal error: unknown opcode in find_fixedlength()\0"
415      "\\N is not supported in a class\0"
416      "too many forward references\0"
417    ;    ;
418    
419  /* 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 676  else Line 680  else
680    
681      case CHAR_l:      case CHAR_l:
682      case CHAR_L:      case CHAR_L:
683        *errorcodeptr = ERR37;
684        break;
685    
686      case CHAR_u:      case CHAR_u:
687        if ((options & PCRE_JAVASCRIPT_COMPAT) != 0)
688          {
689          /* In JavaScript, \u must be followed by four hexadecimal numbers.
690          Otherwise it is a lowercase u letter. */
691          if ((digitab[ptr[1]] & ctype_xdigit) != 0 && (digitab[ptr[2]] & ctype_xdigit) != 0
692               && (digitab[ptr[3]] & ctype_xdigit) != 0 && (digitab[ptr[4]] & ctype_xdigit) != 0)
693            {
694            c = 0;
695            for (i = 0; i < 4; ++i)
696              {
697              register int cc = *(++ptr);
698    #ifndef EBCDIC  /* ASCII/UTF-8 coding */
699              if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
700              c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));
701    #else           /* EBCDIC coding */
702              if (cc >= CHAR_a && cc <= CHAR_z) cc += 64;  /* Convert to upper case */
703              c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));
704    #endif
705              }
706            }
707          }
708        else
709          *errorcodeptr = ERR37;
710        break;
711    
712      case CHAR_U:      case CHAR_U:
713      *errorcodeptr = ERR37;      /* In JavaScript, \U is an uppercase U letter. */
714        if ((options & PCRE_JAVASCRIPT_COMPAT) == 0) *errorcodeptr = ERR37;
715      break;      break;
716    
717      /* 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 828  else Line 861  else
861      treated as a data character. */      treated as a data character. */
862    
863      case CHAR_x:      case CHAR_x:
864        if ((options & PCRE_JAVASCRIPT_COMPAT) != 0)
865          {
866          /* In JavaScript, \x must be followed by two hexadecimal numbers.
867          Otherwise it is a lowercase x letter. */
868          if ((digitab[ptr[1]] & ctype_xdigit) != 0 && (digitab[ptr[2]] & ctype_xdigit) != 0)
869            {
870            c = 0;
871            for (i = 0; i < 2; ++i)
872              {
873              register int cc = *(++ptr);
874    #ifndef EBCDIC  /* ASCII/UTF-8 coding */
875              if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
876              c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));
877    #else           /* EBCDIC coding */
878              if (cc >= CHAR_a && cc <= CHAR_z) cc += 64;  /* Convert to upper case */
879              c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));
880    #endif
881              }
882            }
883          break;
884          }
885    
886      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)
887        {        {
888        const uschar *pt = ptr + 2;        const uschar *pt = ptr + 2;
# Line 1475  Arguments: Line 1530  Arguments:
1530    
1531  Returns:   the fixed length,  Returns:   the fixed length,
1532               or -1 if there is no fixed length,               or -1 if there is no fixed length,
1533               or -2 if \C was encountered               or -2 if \C was encountered (in UTF-8 mode only)
1534               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
1535                 or -4 if an unknown opcode was encountered (internal error)
1536  */  */
1537    
1538  static int  static int
# Line 1500  for (;;) Line 1556  for (;;)
1556      /* We only need to continue for OP_CBRA (normal capturing bracket) and      /* We only need to continue for OP_CBRA (normal capturing bracket) and
1557      OP_BRA (normal non-capturing bracket) because the other variants of these      OP_BRA (normal non-capturing bracket) because the other variants of these
1558      opcodes are all concerned with unlimited repeated groups, which of course      opcodes are all concerned with unlimited repeated groups, which of course
1559      are not of fixed length. They will cause a -1 response from the default      are not of fixed length. */
     case of this switch. */  
1560    
1561      case OP_CBRA:      case OP_CBRA:
1562      case OP_BRA:      case OP_BRA:
1563      case OP_ONCE:      case OP_ONCE:
1564        case OP_ONCE_NC:
1565      case OP_COND:      case OP_COND:
1566      d = find_fixedlength(cc + ((op == OP_CBRA)? 2:0), utf8, atend, cd);      d = find_fixedlength(cc + ((op == OP_CBRA)? 2:0), utf8, atend, cd);
1567      if (d < 0) return d;      if (d < 0) return d;
# Line 1514  for (;;) Line 1570  for (;;)
1570      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1571      break;      break;
1572    
1573      /* 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.
1574      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
1575      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
1576      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,
1577      all imply an unlimited repeat. */      because they all imply an unlimited repeat. */
1578    
1579      case OP_ALT:      case OP_ALT:
1580      case OP_KET:      case OP_KET:
1581      case OP_END:      case OP_END:
1582        case OP_ACCEPT:
1583        case OP_ASSERT_ACCEPT:
1584      if (length < 0) length = branchlength;      if (length < 0) length = branchlength;
1585        else if (length != branchlength) return -1;        else if (length != branchlength) return -1;
1586      if (*cc != OP_ALT) return length;      if (*cc != OP_ALT) return length;
# Line 1556  for (;;) Line 1614  for (;;)
1614    
1615      /* Skip over things that don't match chars */      /* Skip over things that don't match chars */
1616    
1617      case OP_REVERSE:      case OP_MARK:
1618      case OP_CREF:      case OP_PRUNE_ARG:
1619      case OP_NCREF:      case OP_SKIP_ARG:
1620      case OP_RREF:      case OP_THEN_ARG:
1621      case OP_NRREF:      cc += cc[1] + _pcre_OP_lengths[*cc];
1622      case OP_DEF:      break;
1623    
1624      case OP_CALLOUT:      case OP_CALLOUT:
     case OP_SOD:  
     case OP_SOM:  
     case OP_SET_SOM:  
     case OP_EOD:  
     case OP_EODN:  
1625      case OP_CIRC:      case OP_CIRC:
1626      case OP_CIRCM:      case OP_CIRCM:
1627        case OP_CLOSE:
1628        case OP_COMMIT:
1629        case OP_CREF:
1630        case OP_DEF:
1631      case OP_DOLL:      case OP_DOLL:
1632      case OP_DOLLM:      case OP_DOLLM:
1633        case OP_EOD:
1634        case OP_EODN:
1635        case OP_FAIL:
1636        case OP_NCREF:
1637        case OP_NRREF:
1638      case OP_NOT_WORD_BOUNDARY:      case OP_NOT_WORD_BOUNDARY:
1639        case OP_PRUNE:
1640        case OP_REVERSE:
1641        case OP_RREF:
1642        case OP_SET_SOM:
1643        case OP_SKIP:
1644        case OP_SOD:
1645        case OP_SOM:
1646        case OP_THEN:
1647      case OP_WORD_BOUNDARY:      case OP_WORD_BOUNDARY:
1648      cc += _pcre_OP_lengths[*cc];      cc += _pcre_OP_lengths[*cc];
1649      break;      break;
# Line 1594  for (;;) Line 1665  for (;;)
1665      need to skip over a multibyte character in UTF8 mode.  */      need to skip over a multibyte character in UTF8 mode.  */
1666    
1667      case OP_EXACT:      case OP_EXACT:
1668        case OP_EXACTI:
1669        case OP_NOTEXACT:
1670        case OP_NOTEXACTI:
1671      branchlength += GET2(cc,1);      branchlength += GET2(cc,1);
1672      cc += 4;      cc += 4;
1673  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1614  for (;;) Line 1688  for (;;)
1688      cc += 2;      cc += 2;
1689      /* Fall through */      /* Fall through */
1690    
1691        case OP_HSPACE:
1692        case OP_VSPACE:
1693        case OP_NOT_HSPACE:
1694        case OP_NOT_VSPACE:
1695      case OP_NOT_DIGIT:      case OP_NOT_DIGIT:
1696      case OP_DIGIT:      case OP_DIGIT:
1697      case OP_NOT_WHITESPACE:      case OP_NOT_WHITESPACE:
# Line 1626  for (;;) Line 1704  for (;;)
1704      cc++;      cc++;
1705      break;      break;
1706    
1707      /* The single-byte matcher isn't allowed */      /* The single-byte matcher isn't allowed. This only happens in UTF-8 mode;
1708        otherwise \C is coded as OP_ALLANY. */
1709    
1710      case OP_ANYBYTE:      case OP_ANYBYTE:
1711      return -2;      return -2;
# Line 1645  for (;;) Line 1724  for (;;)
1724    
1725      switch (*cc)      switch (*cc)
1726        {        {
1727          case OP_CRPLUS:
1728          case OP_CRMINPLUS:
1729        case OP_CRSTAR:        case OP_CRSTAR:
1730        case OP_CRMINSTAR:        case OP_CRMINSTAR:
1731        case OP_CRQUERY:        case OP_CRQUERY:
# Line 1665  for (;;) Line 1746  for (;;)
1746    
1747      /* Anything else is variable length */      /* Anything else is variable length */
1748    
1749      default:      case OP_ANYNL:
1750        case OP_BRAMINZERO:
1751        case OP_BRAPOS:
1752        case OP_BRAPOSZERO:
1753        case OP_BRAZERO:
1754        case OP_CBRAPOS:
1755        case OP_EXTUNI:
1756        case OP_KETRMAX:
1757        case OP_KETRMIN:
1758        case OP_KETRPOS:
1759        case OP_MINPLUS:
1760        case OP_MINPLUSI:
1761        case OP_MINQUERY:
1762        case OP_MINQUERYI:
1763        case OP_MINSTAR:
1764        case OP_MINSTARI:
1765        case OP_MINUPTO:
1766        case OP_MINUPTOI:
1767        case OP_NOTMINPLUS:
1768        case OP_NOTMINPLUSI:
1769        case OP_NOTMINQUERY:
1770        case OP_NOTMINQUERYI:
1771        case OP_NOTMINSTAR:
1772        case OP_NOTMINSTARI:
1773        case OP_NOTMINUPTO:
1774        case OP_NOTMINUPTOI:
1775        case OP_NOTPLUS:
1776        case OP_NOTPLUSI:
1777        case OP_NOTPOSPLUS:
1778        case OP_NOTPOSPLUSI:
1779        case OP_NOTPOSQUERY:
1780        case OP_NOTPOSQUERYI:
1781        case OP_NOTPOSSTAR:
1782        case OP_NOTPOSSTARI:
1783        case OP_NOTPOSUPTO:
1784        case OP_NOTPOSUPTOI:
1785        case OP_NOTQUERY:
1786        case OP_NOTQUERYI:
1787        case OP_NOTSTAR:
1788        case OP_NOTSTARI:
1789        case OP_NOTUPTO:
1790        case OP_NOTUPTOI:
1791        case OP_PLUS:
1792        case OP_PLUSI:
1793        case OP_POSPLUS:
1794        case OP_POSPLUSI:
1795        case OP_POSQUERY:
1796        case OP_POSQUERYI:
1797        case OP_POSSTAR:
1798        case OP_POSSTARI:
1799        case OP_POSUPTO:
1800        case OP_POSUPTOI:
1801        case OP_QUERY:
1802        case OP_QUERYI:
1803        case OP_REF:
1804        case OP_REFI:
1805        case OP_SBRA:
1806        case OP_SBRAPOS:
1807        case OP_SCBRA:
1808        case OP_SCBRAPOS:
1809        case OP_SCOND:
1810        case OP_SKIPZERO:
1811        case OP_STAR:
1812        case OP_STARI:
1813        case OP_TYPEMINPLUS:
1814        case OP_TYPEMINQUERY:
1815        case OP_TYPEMINSTAR:
1816        case OP_TYPEMINUPTO:
1817        case OP_TYPEPLUS:
1818        case OP_TYPEPOSPLUS:
1819        case OP_TYPEPOSQUERY:
1820        case OP_TYPEPOSSTAR:
1821        case OP_TYPEPOSUPTO:
1822        case OP_TYPEQUERY:
1823        case OP_TYPESTAR:
1824        case OP_TYPEUPTO:
1825        case OP_UPTO:
1826        case OP_UPTOI:
1827      return -1;      return -1;
1828    
1829        /* Catch unrecognized opcodes so that when new ones are added they
1830        are not forgotten, as has happened in the past. */
1831    
1832        default:
1833        return -4;
1834      }      }
1835    }    }
1836  /* Control never gets here */  /* Control never gets here */
# Line 1761  for (;;) Line 1925  for (;;)
1925        break;        break;
1926    
1927        case OP_THEN_ARG:        case OP_THEN_ARG:
1928        code += code[1+LINK_SIZE];        code += code[1];
1929        break;        break;
1930        }        }
1931    
# Line 1880  for (;;) Line 2044  for (;;)
2044        break;        break;
2045    
2046        case OP_THEN_ARG:        case OP_THEN_ARG:
2047        code += code[1+LINK_SIZE];        code += code[1];
2048        break;        break;
2049        }        }
2050    
# Line 2045  for (code = first_significant_code(code Line 2209  for (code = first_significant_code(code
2209    
2210    if (c == OP_BRA  || c == OP_BRAPOS ||    if (c == OP_BRA  || c == OP_BRAPOS ||
2211        c == OP_CBRA || c == OP_CBRAPOS ||        c == OP_CBRA || c == OP_CBRAPOS ||
2212        c == OP_ONCE || c == OP_COND)        c == OP_ONCE || c == OP_ONCE_NC ||
2213          c == OP_COND)
2214      {      {
2215      BOOL empty_branch;      BOOL empty_branch;
2216      if (GET(code, 1) == 0) return TRUE;    /* Hit unclosed bracket */      if (GET(code, 1) == 0) return TRUE;    /* Hit unclosed bracket */
# Line 2217  for (code = first_significant_code(code Line 2382  for (code = first_significant_code(code
2382      break;      break;
2383    
2384      case OP_THEN_ARG:      case OP_THEN_ARG:
2385      code += code[1+LINK_SIZE];      code += code[1];
2386      break;      break;
2387    
2388      /* None of the remaining opcodes are required to match a character. */      /* None of the remaining opcodes are required to match a character. */
# Line 3142  for (;; ptr++) Line 3307  for (;; ptr++)
3307    int subfirstbyte;    int subfirstbyte;
3308    int terminator;    int terminator;
3309    int mclength;    int mclength;
3310      int tempbracount;
3311    uschar mcbuffer[8];    uschar mcbuffer[8];
3312    
3313    /* Get next byte in the pattern */    /* Get next byte in the pattern */
# Line 3189  for (;; ptr++) Line 3355  for (;; ptr++)
3355        }        }
3356    
3357      *lengthptr += (int)(code - last_code);      *lengthptr += (int)(code - last_code);
3358      DPRINTF(("length=%d added %d c=%c\n", *lengthptr, code - last_code, c));      DPRINTF(("length=%d added %d c=%c\n", *lengthptr, (int)(code - last_code),
3359          c));
3360    
3361      /* 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
3362      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 3605  for (;; ptr++) Line 3772  for (;; ptr++)
3772          if (*errorcodeptr != 0) goto FAILED;          if (*errorcodeptr != 0) goto FAILED;
3773    
3774          if (-c == ESC_b) c = CHAR_BS;    /* \b is backspace in a class */          if (-c == ESC_b) c = CHAR_BS;    /* \b is backspace in a class */
3775            else if (-c == ESC_N)            /* \N is not supported in a class */
3776              {
3777              *errorcodeptr = ERR71;
3778              goto FAILED;
3779              }
3780          else if (-c == ESC_Q)            /* Handle start of quoted string */          else if (-c == ESC_Q)            /* Handle start of quoted string */
3781            {            {
3782            if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)            if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)
# Line 4261  for (;; ptr++) Line 4433  for (;; ptr++)
4433      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
4434      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,
4435      but for the moment we rely on the code for repeating groups. */      but for the moment we rely on the code for repeating groups. */
4436    
4437      if (*previous == OP_RECURSE)      if (*previous == OP_RECURSE)
4438        {        {
4439        memmove(previous + 1 + LINK_SIZE, previous, 1 + LINK_SIZE);        memmove(previous + 1 + LINK_SIZE, previous, 1 + LINK_SIZE);
# Line 4724  for (;; ptr++) Line 4896  for (;; ptr++)
4896                memcpy(code, previous, len);                memcpy(code, previous, len);
4897                for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE)                for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE)
4898                  {                  {
4899                    if (cd->hwm >= cd->start_workspace + WORK_SIZE_CHECK)
4900                      {
4901                      *errorcodeptr = ERR72;
4902                      goto FAILED;
4903                      }
4904                  PUT(cd->hwm, 0, GET(hc, 0) + len);                  PUT(cd->hwm, 0, GET(hc, 0) + len);
4905                  cd->hwm += LINK_SIZE;                  cd->hwm += LINK_SIZE;
4906                  }                  }
# Line 4751  for (;; ptr++) Line 4928  for (;; ptr++)
4928          add 2 + 2*LINKSIZE to allow for the nesting that occurs. Do some          add 2 + 2*LINKSIZE to allow for the nesting that occurs. Do some
4929          paranoid checks to avoid integer overflow. The INT64_OR_DOUBLE type is          paranoid checks to avoid integer overflow. The INT64_OR_DOUBLE type is
4930          a 64-bit integer type when available, otherwise double. */          a 64-bit integer type when available, otherwise double. */
4931    
4932          if (lengthptr != NULL && repeat_max > 0)          if (lengthptr != NULL && repeat_max > 0)
4933            {            {
4934            int delta = repeat_max * (length_prevgroup + 1 + 2 + 2*LINK_SIZE) -            int delta = repeat_max * (length_prevgroup + 1 + 2 + 2*LINK_SIZE) -
# Line 4791  for (;; ptr++) Line 4968  for (;; ptr++)
4968            memcpy(code, previous, len);            memcpy(code, previous, len);
4969            for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE)            for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE)
4970              {              {
4971                if (cd->hwm >= cd->start_workspace + WORK_SIZE_CHECK)
4972                  {
4973                  *errorcodeptr = ERR72;
4974                  goto FAILED;
4975                  }
4976              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));
4977              cd->hwm += LINK_SIZE;              cd->hwm += LINK_SIZE;
4978              }              }
# Line 4819  for (;; ptr++) Line 5001  for (;; ptr++)
5001        ONCE brackets can be converted into non-capturing brackets, as the        ONCE brackets can be converted into non-capturing brackets, as the
5002        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
5003        deal with possessive ONCEs specially.        deal with possessive ONCEs specially.
5004    
5005        Otherwise, if the quantifier was possessive, we convert the BRA code to        Otherwise, when we are doing the actual compile phase, check to see
5006        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,
5007        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
5008        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
5009        stack usage in pcre_exec(). If the group is preceded by OP_BRAZERO,        groups at runtime, but in a different way.]
5010        convert this to OP_BRAPOSZERO. Then cancel the possessive flag so that  
5011        the default action below, of wrapping everything inside atomic brackets,        Then, if the quantifier was possessive and the bracket is not a
5012        does not happen.        conditional, we convert the BRA code to the POS form, and the KET code to
5013          KETRPOS. (It turns out to be convenient at runtime to detect this kind of
5014        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
5015        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
5016        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.
5017        checking can be done. [This check is also applied to ONCE groups at  
5018        runtime, but in a different way.] */        Then, if the minimum number of matches is 1 or 0, cancel the possessive
5019          flag so that the default action below, of wrapping everything inside
5020          atomic brackets, does not happen. When the minimum is greater than 1,
5021          there will be earlier copies of the group, and so we still have to wrap
5022          the whole thing. */
5023    
5024        else        else
5025          {          {
5026          uschar *ketcode = code - 1 - LINK_SIZE;          uschar *ketcode = code - 1 - LINK_SIZE;
5027          uschar *bracode = ketcode - GET(ketcode, 1);          uschar *bracode = ketcode - GET(ketcode, 1);
5028    
5029          if (*bracode == OP_ONCE && possessive_quantifier) *bracode = OP_BRA;          /* Convert possessive ONCE brackets to non-capturing */
5030          if (*bracode == OP_ONCE)  
5031            if ((*bracode == OP_ONCE || *bracode == OP_ONCE_NC) &&
5032                possessive_quantifier) *bracode = OP_BRA;
5033    
5034            /* For non-possessive ONCE brackets, all we need to do is to
5035            set the KET. */
5036    
5037            if (*bracode == OP_ONCE || *bracode == OP_ONCE_NC)
5038            *ketcode = OP_KETRMAX + repeat_type;            *ketcode = OP_KETRMAX + repeat_type;
5039    
5040            /* Handle non-ONCE brackets and possessive ONCEs (which have been
5041            converted to non-capturing above). */
5042    
5043          else          else
5044            {            {
5045            if (possessive_quantifier)            /* In the compile phase, check for empty string matching. */
5046              {  
             *bracode += 1;                   /* Switch to xxxPOS opcodes */  
             *ketcode = OP_KETRPOS;  
             if (brazeroptr != NULL) *brazeroptr = OP_BRAPOSZERO;  
             possessive_quantifier = FALSE;  
             }  
           else *ketcode = OP_KETRMAX + repeat_type;  
   
5047            if (lengthptr == NULL)            if (lengthptr == NULL)
5048              {              {
5049              uschar *scode = bracode;              uschar *scode = bracode;
# Line 4868  for (;; ptr++) Line 5058  for (;; ptr++)
5058                }                }
5059              while (*scode == OP_ALT);              while (*scode == OP_ALT);
5060              }              }
5061    
5062              /* Handle possessive quantifiers. */
5063    
5064              if (possessive_quantifier)
5065                {
5066                /* For COND brackets, we wrap the whole thing in a possessively
5067                repeated non-capturing bracket, because we have not invented POS
5068                versions of the COND opcodes. Because we are moving code along, we
5069                must ensure that any pending recursive references are updated. */
5070    
5071                if (*bracode == OP_COND || *bracode == OP_SCOND)
5072                  {
5073                  int nlen = (int)(code - bracode);
5074                  *code = OP_END;
5075                  adjust_recurse(bracode, 1 + LINK_SIZE, utf8, cd, save_hwm);
5076                  memmove(bracode + 1+LINK_SIZE, bracode, nlen);
5077                  code += 1 + LINK_SIZE;
5078                  nlen += 1 + LINK_SIZE;
5079                  *bracode = OP_BRAPOS;
5080                  *code++ = OP_KETRPOS;
5081                  PUTINC(code, 0, nlen);
5082                  PUT(bracode, 1, nlen);
5083                  }
5084    
5085                /* For non-COND brackets, we modify the BRA code and use KETRPOS. */
5086    
5087                else
5088                  {
5089                  *bracode += 1;              /* Switch to xxxPOS opcodes */
5090                  *ketcode = OP_KETRPOS;
5091                  }
5092    
5093                /* If the minimum is zero, mark it as possessive, then unset the
5094                possessive flag when the minimum is 0 or 1. */
5095    
5096                if (brazeroptr != NULL) *brazeroptr = OP_BRAPOSZERO;
5097                if (repeat_min < 2) possessive_quantifier = FALSE;
5098                }
5099    
5100              /* Non-possessive quantifier */
5101    
5102              else *ketcode = OP_KETRMAX + repeat_type;
5103            }            }
5104          }          }
5105        }        }
# Line 4894  for (;; ptr++) Line 5126  for (;; ptr++)
5126      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
5127      special opcodes can optimize it.      special opcodes can optimize it.
5128    
5129      Possessively repeated subpatterns have already been handled in the code      Some (but not all) possessively repeated subpatterns have already been
5130      just above, so possessive_quantifier is always FALSE for them at this      completely handled in the code just above. For them, possessive_quantifier
5131      stage.      is always FALSE at this stage.
5132    
5133      Note that the repeated item starts at tempcode, not at previous, which      Note that the repeated item starts at tempcode, not at previous, which
5134      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 5045  for (;; ptr++) Line 5277  for (;; ptr++)
5277                PUT2INC(code, 0, oc->number);                PUT2INC(code, 0, oc->number);
5278                }                }
5279              *code++ = (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;              *code++ = (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;
5280    
5281              /* Do not set firstbyte after *ACCEPT */              /* Do not set firstbyte after *ACCEPT */
5282              if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;              if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;
5283              }              }
# Line 5060  for (;; ptr++) Line 5292  for (;; ptr++)
5292                goto FAILED;                goto FAILED;
5293                }                }
5294              *code = verbs[i].op;              *code = verbs[i].op;
5295              if (*code++ == OP_THEN)              if (*code++ == OP_THEN) cd->external_flags |= PCRE_HASTHEN;
               {  
               PUT(code, 0, code - bcptr->current_branch - 1);  
               code += LINK_SIZE;  
               cd->external_flags |= PCRE_HASTHEN;  
               }  
5296              }              }
5297    
5298            else            else
# Line 5076  for (;; ptr++) Line 5303  for (;; ptr++)
5303                goto FAILED;                goto FAILED;
5304                }                }
5305              *code = verbs[i].op_arg;              *code = verbs[i].op_arg;
5306              if (*code++ == OP_THEN_ARG)              if (*code++ == OP_THEN_ARG) cd->external_flags |= PCRE_HASTHEN;
               {  
               PUT(code, 0, code - bcptr->current_branch - 1);  
               code += LINK_SIZE;  
               }  
5307              *code++ = arglen;              *code++ = arglen;
5308              memcpy(code, arg, arglen);              memcpy(code, arg, arglen);
5309              code += arglen;              code += arglen;
# Line 5395  for (;; ptr++) Line 5618  for (;; ptr++)
5618    
5619          /* ------------------------------------------------------------ */          /* ------------------------------------------------------------ */
5620          case CHAR_C:                 /* Callout - may be followed by digits; */          case CHAR_C:                 /* Callout - may be followed by digits; */
5621          previous_callout = code;  /* Save for later completion */          previous_callout = code;     /* Save for later completion */
5622          after_manual_callout = 1; /* Skip one item before completing */          after_manual_callout = 1;    /* Skip one item before completing */
5623          *code++ = OP_CALLOUT;          *code++ = OP_CALLOUT;
5624            {            {
5625            int n = 0;            int n = 0;
# Line 5765  for (;; ptr++) Line 5988  for (;; ptr++)
5988                /* Fudge the value of "called" so that when it is inserted as an                /* Fudge the value of "called" so that when it is inserted as an
5989                offset below, what it actually inserted is the reference number                offset below, what it actually inserted is the reference number
5990                of the group. Then remember the forward reference. */                of the group. Then remember the forward reference. */
5991    
5992                called = cd->start_code + recno;                called = cd->start_code + recno;
5993                  if (cd->hwm >= cd->start_workspace + WORK_SIZE_CHECK)
5994                    {
5995                    *errorcodeptr = ERR72;
5996                    goto FAILED;
5997                    }
5998                PUTINC(cd->hwm, 0, (int)(code + 1 - cd->start_code));                PUTINC(cd->hwm, 0, (int)(code + 1 - cd->start_code));
5999                }                }
6000    
# Line 5915  for (;; ptr++) Line 6143  for (;; ptr++)
6143      *code = bravalue;      *code = bravalue;
6144      tempcode = code;      tempcode = code;
6145      tempreqvary = cd->req_varyopt;        /* Save value before bracket */      tempreqvary = cd->req_varyopt;        /* Save value before bracket */
6146        tempbracount = cd->bracount;          /* Save value before bracket */
6147      length_prevgroup = 0;                 /* Initialize for pre-compile phase */      length_prevgroup = 0;                 /* Initialize for pre-compile phase */
6148    
6149      if (!compile_regex(      if (!compile_regex(
# Line 5937  for (;; ptr++) Line 6166  for (;; ptr++)
6166           ))           ))
6167        goto FAILED;        goto FAILED;
6168    
6169        /* If this was an atomic group and there are no capturing groups within it,
6170        generate OP_ONCE_NC instead of OP_ONCE. */
6171    
6172        if (bravalue == OP_ONCE && cd->bracount <= tempbracount)
6173          *code = OP_ONCE_NC;
6174    
6175      if (bravalue >= OP_ASSERT && bravalue <= OP_ASSERTBACK_NOT)      if (bravalue >= OP_ASSERT && bravalue <= OP_ASSERTBACK_NOT)
6176        cd->assert_depth -= 1;        cd->assert_depth -= 1;
6177    
6178      /* 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
6179      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.
6180      and any option resetting that may follow it. The pattern pointer (ptr)      The pattern pointer (ptr) is on the bracket.
     is on the bracket. */  
6181    
6182      /* 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
6183      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
6184      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
6185      not be available. */      not be available. */
# Line 6267  for (;; ptr++) Line 6501  for (;; ptr++)
6501            }            }
6502          else          else
6503  #endif  #endif
6504            {          /* In non-UTF-8 mode, we turn \C into OP_ALLANY instead of OP_ANYBYTE
6505            so that it works in DFA mode and in lookbehinds. */
6506    
6507              {
6508            previous = (-c > ESC_b && -c < ESC_Z)? code : NULL;            previous = (-c > ESC_b && -c < ESC_Z)? code : NULL;
6509            *code++ = -c;            *code++ = (!utf8 && c == -ESC_C)? OP_ALLANY : -c;
6510            }            }
6511          }          }
6512        continue;        continue;
# Line 6327  for (;; ptr++) Line 6564  for (;; ptr++)
6564      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.
6565      Otherwise, leave the firstbyte value alone, and don't change it on a zero      Otherwise, leave the firstbyte value alone, and don't change it on a zero
6566      repeat. */      repeat. */
6567    
6568      if (firstbyte == REQ_UNSET)      if (firstbyte == REQ_UNSET)
6569        {        {
6570        zerofirstbyte = REQ_NONE;        zerofirstbyte = REQ_NONE;
# Line 6561  for (;;) Line 6798  for (;;)
6798          }          }
6799        else if (fixed_length < 0)        else if (fixed_length < 0)
6800          {          {
6801          *errorcodeptr = (fixed_length == -2)? ERR36 : ERR25;          *errorcodeptr = (fixed_length == -2)? ERR36 :
6802                            (fixed_length == -4)? ERR70: ERR25;
6803          *ptrptr = ptr;          *ptrptr = ptr;
6804          return FALSE;          return FALSE;
6805          }          }
# Line 6736  do { Line 6974  do {
6974    
6975     /* Other brackets */     /* Other brackets */
6976    
6977     else if (op == OP_ASSERT || op == OP_ONCE || op == OP_COND)     else if (op == OP_ASSERT || op == OP_ONCE || op == OP_ONCE_NC ||
6978                op == OP_COND)
6979       {       {
6980       if (!is_anchored(scode, bracket_map, backref_map)) return FALSE;       if (!is_anchored(scode, bracket_map, backref_map)) return FALSE;
6981       }       }
# Line 6840  do { Line 7079  do {
7079    
7080     /* Other brackets */     /* Other brackets */
7081    
7082     else if (op == OP_ASSERT || op == OP_ONCE)     else if (op == OP_ASSERT || op == OP_ONCE || op == OP_ONCE_NC)
7083       {       {
7084       if (!is_startline(scode, bracket_map, backref_map)) return FALSE;       if (!is_startline(scode, bracket_map, backref_map)) return FALSE;
7085       }       }
# Line 6910  do { Line 7149  do {
7149       case OP_SCBRAPOS:       case OP_SCBRAPOS:
7150       case OP_ASSERT:       case OP_ASSERT:
7151       case OP_ONCE:       case OP_ONCE:
7152         case OP_ONCE_NC:
7153       case OP_COND:       case OP_COND:
7154       if ((d = find_firstassertedchar(scode, op == OP_ASSERT)) < 0)       if ((d = find_firstassertedchar(scode, op == OP_ASSERT)) < 0)
7155         return -1;         return -1;
# Line 7358  if (cd->check_lookbehind) Line 7598  if (cd->check_lookbehind)
7598        DPRINTF(("fixed length = %d\n", fixed_length));        DPRINTF(("fixed length = %d\n", fixed_length));
7599        if (fixed_length < 0)        if (fixed_length < 0)
7600          {          {
7601          errorcode = (fixed_length == -2)? ERR36 : ERR25;          errorcode = (fixed_length == -2)? ERR36 :
7602                        (fixed_length == -4)? ERR70 : ERR25;
7603          break;          break;
7604          }          }
7605        PUT(cc, 1, fixed_length);        PUT(cc, 1, fixed_length);

Legend:
Removed from v.702  
changed lines
  Added in v.760

  ViewVC Help
Powered by ViewVC 1.1.5