Mercurial > emacs
comparison src/regex.c @ 52838:246c94760bee
(MAX_BUF_SIZE): Reduce to 2**15.
(print_partial_compiled_pattern): Replace assert with a printout.
(skip_noops, mutually_exclusive_p): Change args, values to re_char *.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 13 Oct 2003 18:48:14 +0000 |
parents | 3614833210ba |
children | ada02c2b390c |
comparison
equal
deleted
inserted
replaced
52837:1bbf3f566879 | 52838:246c94760bee |
---|---|
973 register int in_range = 0; | 973 register int in_range = 0; |
974 int length = CHARSET_BITMAP_SIZE (p - 1); | 974 int length = CHARSET_BITMAP_SIZE (p - 1); |
975 int has_range_table = CHARSET_RANGE_TABLE_EXISTS_P (p - 1); | 975 int has_range_table = CHARSET_RANGE_TABLE_EXISTS_P (p - 1); |
976 | 976 |
977 fprintf (stderr, "/charset [%s", | 977 fprintf (stderr, "/charset [%s", |
978 (re_opcode_t) *(p - 1) == charset_not ? "^" : ""); | 978 (re_opcode_t) *(p - 1) == charset_not ? "^" : ""); |
979 | 979 |
980 assert (p + *p < pend); | 980 if (p + *p >= pend) |
981 fprintf (stderr, " !extends past end of pattern! "); | |
981 | 982 |
982 for (c = 0; c < 256; c++) | 983 for (c = 0; c < 256; c++) |
983 if (c / 8 < length | 984 if (c / 8 < length |
984 && (p[1 + (c/8)] & (1 << (c % 8)))) | 985 && (p[1 + (c/8)] & (1 << (c % 8)))) |
985 { | 986 { |
1734 #define INSERT_JUMP2(op, loc, to, arg) \ | 1735 #define INSERT_JUMP2(op, loc, to, arg) \ |
1735 insert_op2 (op, loc, (to) - (loc) - 3, arg, b) | 1736 insert_op2 (op, loc, (to) - (loc) - 3, arg, b) |
1736 | 1737 |
1737 | 1738 |
1738 /* This is not an arbitrary limit: the arguments which represent offsets | 1739 /* This is not an arbitrary limit: the arguments which represent offsets |
1739 into the pattern are two bytes long. So if 2^16 bytes turns out to | 1740 into the pattern are two bytes long. So if 2^15 bytes turns out to |
1740 be too small, many things would have to change. */ | 1741 be too small, many things would have to change. */ |
1742 # define MAX_BUF_SIZE (1L << 15) | |
1743 | |
1744 #if 0 /* This is when we thought it could be 2^16 bytes. */ | |
1741 /* Any other compiler which, like MSC, has allocation limit below 2^16 | 1745 /* Any other compiler which, like MSC, has allocation limit below 2^16 |
1742 bytes will have to use approach similar to what was done below for | 1746 bytes will have to use approach similar to what was done below for |
1743 MSC and drop MAX_BUF_SIZE a bit. Otherwise you may end up | 1747 MSC and drop MAX_BUF_SIZE a bit. Otherwise you may end up |
1744 reallocating to 0 bytes. Such thing is not going to work too well. | 1748 reallocating to 0 bytes. Such thing is not going to work too well. |
1745 You have been warned!! */ | 1749 You have been warned!! */ |
1747 /* Microsoft C 16-bit versions limit malloc to approx 65512 bytes. */ | 1751 /* Microsoft C 16-bit versions limit malloc to approx 65512 bytes. */ |
1748 # define MAX_BUF_SIZE 65500L | 1752 # define MAX_BUF_SIZE 65500L |
1749 #else | 1753 #else |
1750 # define MAX_BUF_SIZE (1L << 16) | 1754 # define MAX_BUF_SIZE (1L << 16) |
1751 #endif | 1755 #endif |
1756 #endif /* 0 */ | |
1752 | 1757 |
1753 /* Extend the buffer by twice its current size via realloc and | 1758 /* Extend the buffer by twice its current size via realloc and |
1754 reset the pointers that pointed into the old block to point to the | 1759 reset the pointers that pointed into the old block to point to the |
1755 correct places in the new one. If extending the buffer results in it | 1760 correct places in the new one. If extending the buffer results in it |
1756 being larger than MAX_BUF_SIZE, then flag memory exhausted. */ | 1761 being larger than MAX_BUF_SIZE, then flag memory exhausted. */ |
4454 return p; | 4459 return p; |
4455 } | 4460 } |
4456 | 4461 |
4457 | 4462 |
4458 /* Jump over non-matching operations. */ | 4463 /* Jump over non-matching operations. */ |
4459 static unsigned char * | 4464 static re_char * |
4460 skip_noops (p, pend) | 4465 skip_noops (p, pend) |
4461 unsigned char *p, *pend; | 4466 re_char *p, *pend; |
4462 { | 4467 { |
4463 int mcnt; | 4468 int mcnt; |
4464 while (p < pend) | 4469 while (p < pend) |
4465 { | 4470 { |
4466 switch (SWITCH_ENUM_CAST ((re_opcode_t) *p)) | 4471 switch (SWITCH_ENUM_CAST ((re_opcode_t) *p)) |
4485 | 4490 |
4486 /* Non-zero if "p1 matches something" implies "p2 fails". */ | 4491 /* Non-zero if "p1 matches something" implies "p2 fails". */ |
4487 static int | 4492 static int |
4488 mutually_exclusive_p (bufp, p1, p2) | 4493 mutually_exclusive_p (bufp, p1, p2) |
4489 struct re_pattern_buffer *bufp; | 4494 struct re_pattern_buffer *bufp; |
4490 unsigned char *p1, *p2; | 4495 re_char *p1, *p2; |
4491 { | 4496 { |
4492 re_opcode_t op2; | 4497 re_opcode_t op2; |
4493 const boolean multibyte = RE_MULTIBYTE_P (bufp); | 4498 const boolean multibyte = RE_MULTIBYTE_P (bufp); |
4494 unsigned char *pend = bufp->buffer + bufp->used; | 4499 unsigned char *pend = bufp->buffer + bufp->used; |
4495 | 4500 |