aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Schwab2009-04-16 16:01:14 +0000
committerAndreas Schwab2009-04-16 16:01:14 +0000
commite7deaab0bcbd095f3a6278b74e7cd29c0913370e (patch)
treea15d833bee77e0774bd77e941a06743606ebcca6
parent6340c70eb32758be2c3ca9059a3fb75bb9a79e72 (diff)
downloademacs-e7deaab0bcbd095f3a6278b74e7cd29c0913370e.tar.gz
emacs-e7deaab0bcbd095f3a6278b74e7cd29c0913370e.zip
* search.c: Use EMACS_INT for buffer positions. Add prototypes.
* lisp.h: Adjust prototypes.
-rw-r--r--src/ChangeLog3
-rw-r--r--src/lisp.h11
-rw-r--r--src/search.c112
3 files changed, 70 insertions, 56 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 75314968e5e..b65956d6d3c 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -3,6 +3,9 @@
3 * search.c (boyer_moore): Use zero as marker value for a possible 3 * search.c (boyer_moore): Use zero as marker value for a possible
4 match instead of depending on overflow behavior. (Bug#2844) 4 match instead of depending on overflow behavior. (Bug#2844)
5 5
6 * search.c: Use EMACS_INT for buffer positions. Add prototypes.
7 * lisp.h: Adjust prototypes.
8
62009-04-16 Chong Yidong <cyd@stupidchicken.com> 92009-04-16 Chong Yidong <cyd@stupidchicken.com>
7 10
8 * keyboard.c (adjust_point_for_property): Disable 2009-02-12 11 * keyboard.c (adjust_point_for_property): Disable 2009-02-12
diff --git a/src/lisp.h b/src/lisp.h
index 84dcc8fb23e..9d5aa9b15d3 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2969,11 +2969,12 @@ extern int fast_c_string_match_ignore_case P_ ((Lisp_Object, const char *));
2969extern int fast_string_match_ignore_case P_ ((Lisp_Object, Lisp_Object)); 2969extern int fast_string_match_ignore_case P_ ((Lisp_Object, Lisp_Object));
2970extern EMACS_INT fast_looking_at P_ ((Lisp_Object, EMACS_INT, EMACS_INT, 2970extern EMACS_INT fast_looking_at P_ ((Lisp_Object, EMACS_INT, EMACS_INT,
2971 EMACS_INT, EMACS_INT, Lisp_Object)); 2971 EMACS_INT, EMACS_INT, Lisp_Object));
2972extern int scan_buffer P_ ((int, int, int, int, int *, int)); 2972extern int scan_buffer P_ ((int, EMACS_INT, EMACS_INT, int, int *, int));
2973extern int scan_newline P_ ((int, int, int, int, int, int)); 2973extern int scan_newline P_ ((EMACS_INT, EMACS_INT, EMACS_INT, EMACS_INT,
2974extern int find_next_newline P_ ((int, int)); 2974 int, int));
2975extern int find_next_newline_no_quit P_ ((int, int)); 2975extern int find_next_newline P_ ((EMACS_INT, int));
2976extern int find_before_next_newline P_ ((int, int, int)); 2976extern int find_next_newline_no_quit P_ ((EMACS_INT, int));
2977extern int find_before_next_newline P_ ((EMACS_INT, EMACS_INT, int));
2977extern void syms_of_search P_ ((void)); 2978extern void syms_of_search P_ ((void));
2978extern void clear_regexp_cache P_ ((void)); 2979extern void clear_regexp_cache P_ ((void));
2979 2980
diff --git a/src/search.c b/src/search.c
index 2eb435276a3..2e5c379ea7d 100644
--- a/src/search.c
+++ b/src/search.c
@@ -97,11 +97,18 @@ Lisp_Object Vsearch_spaces_regexp;
97 only. */ 97 only. */
98Lisp_Object Vinhibit_changing_match_data; 98Lisp_Object Vinhibit_changing_match_data;
99 99
100static void set_search_regs (); 100static void set_search_regs P_ ((EMACS_INT, EMACS_INT));
101static void save_search_regs (); 101static void save_search_regs P_ ((void));
102static int simple_search (); 102static EMACS_INT simple_search P_ ((int, unsigned char *, int, int,
103static int boyer_moore (); 103 Lisp_Object, EMACS_INT, EMACS_INT,
104static int search_buffer (); 104 EMACS_INT, EMACS_INT));
105static EMACS_INT boyer_moore P_ ((int, unsigned char *, int, int,
106 Lisp_Object, Lisp_Object,
107 EMACS_INT, EMACS_INT,
108 EMACS_INT, EMACS_INT, int));
109static EMACS_INT search_buffer P_ ((Lisp_Object, EMACS_INT, EMACS_INT,
110 EMACS_INT, EMACS_INT, int, int,
111 Lisp_Object, Lisp_Object, int));
105static void matcher_overflow () NO_RETURN; 112static void matcher_overflow () NO_RETURN;
106 113
107static void 114static void
@@ -288,7 +295,7 @@ looking_at_1 (string, posix)
288{ 295{
289 Lisp_Object val; 296 Lisp_Object val;
290 unsigned char *p1, *p2; 297 unsigned char *p1, *p2;
291 int s1, s2; 298 EMACS_INT s1, s2;
292 register int i; 299 register int i;
293 struct re_pattern_buffer *bufp; 300 struct re_pattern_buffer *bufp;
294 301
@@ -390,7 +397,7 @@ string_match_1 (regexp, string, start, posix)
390{ 397{
391 int val; 398 int val;
392 struct re_pattern_buffer *bufp; 399 struct re_pattern_buffer *bufp;
393 int pos, pos_byte; 400 EMACS_INT pos, pos_byte;
394 int i; 401 int i;
395 402
396 if (running_asynch_code) 403 if (running_asynch_code)
@@ -572,7 +579,7 @@ fast_looking_at (regexp, pos, pos_byte, limit, limit_byte, string)
572 int multibyte; 579 int multibyte;
573 struct re_pattern_buffer *buf; 580 struct re_pattern_buffer *buf;
574 unsigned char *p1, *p2; 581 unsigned char *p1, *p2;
575 int s1, s2; 582 EMACS_INT s1, s2;
576 EMACS_INT len; 583 EMACS_INT len;
577 584
578 if (STRINGP (string)) 585 if (STRINGP (string))
@@ -676,7 +683,7 @@ newline_cache_on_off (buf)
676int 683int
677scan_buffer (target, start, end, count, shortage, allow_quit) 684scan_buffer (target, start, end, count, shortage, allow_quit)
678 register int target; 685 register int target;
679 int start, end; 686 EMACS_INT start, end;
680 int count; 687 int count;
681 int *shortage; 688 int *shortage;
682 int allow_quit; 689 int allow_quit;
@@ -711,9 +718,9 @@ scan_buffer (target, start, end, count, shortage, allow_quit)
711 the position of the last character before the next such 718 the position of the last character before the next such
712 obstacle --- the last character the dumb search loop should 719 obstacle --- the last character the dumb search loop should
713 examine. */ 720 examine. */
714 int ceiling_byte = CHAR_TO_BYTE (end) - 1; 721 EMACS_INT ceiling_byte = CHAR_TO_BYTE (end) - 1;
715 int start_byte = CHAR_TO_BYTE (start); 722 EMACS_INT start_byte = CHAR_TO_BYTE (start);
716 int tem; 723 EMACS_INT tem;
717 724
718 /* If we're looking for a newline, consult the newline cache 725 /* If we're looking for a newline, consult the newline cache
719 to see where we can avoid some scanning. */ 726 to see where we can avoid some scanning. */
@@ -784,9 +791,9 @@ scan_buffer (target, start, end, count, shortage, allow_quit)
784 while (start > end) 791 while (start > end)
785 { 792 {
786 /* The last character to check before the next obstacle. */ 793 /* The last character to check before the next obstacle. */
787 int ceiling_byte = CHAR_TO_BYTE (end); 794 EMACS_INT ceiling_byte = CHAR_TO_BYTE (end);
788 int start_byte = CHAR_TO_BYTE (start); 795 EMACS_INT start_byte = CHAR_TO_BYTE (start);
789 int tem; 796 EMACS_INT tem;
790 797
791 /* Consult the newline cache, if appropriate. */ 798 /* Consult the newline cache, if appropriate. */
792 if (target == '\n' && newline_cache) 799 if (target == '\n' && newline_cache)
@@ -872,8 +879,8 @@ scan_buffer (target, start, end, count, shortage, allow_quit)
872 879
873int 880int
874scan_newline (start, start_byte, limit, limit_byte, count, allow_quit) 881scan_newline (start, start_byte, limit, limit_byte, count, allow_quit)
875 int start, start_byte; 882 EMACS_INT start, start_byte;
876 int limit, limit_byte; 883 EMACS_INT limit, limit_byte;
877 register int count; 884 register int count;
878 int allow_quit; 885 int allow_quit;
879{ 886{
@@ -882,7 +889,7 @@ scan_newline (start, start_byte, limit, limit_byte, count, allow_quit)
882 register unsigned char *cursor; 889 register unsigned char *cursor;
883 unsigned char *base; 890 unsigned char *base;
884 891
885 register int ceiling; 892 EMACS_INT ceiling;
886 register unsigned char *ceiling_addr; 893 register unsigned char *ceiling_addr;
887 894
888 int old_immediate_quit = immediate_quit; 895 int old_immediate_quit = immediate_quit;
@@ -970,7 +977,8 @@ scan_newline (start, start_byte, limit, limit_byte, count, allow_quit)
970 977
971int 978int
972find_next_newline_no_quit (from, cnt) 979find_next_newline_no_quit (from, cnt)
973 register int from, cnt; 980 EMACS_INT from;
981 int cnt;
974{ 982{
975 return scan_buffer ('\n', from, 0, cnt, (int *) 0, 0); 983 return scan_buffer ('\n', from, 0, cnt, (int *) 0, 0);
976} 984}
@@ -981,7 +989,8 @@ find_next_newline_no_quit (from, cnt)
981 989
982int 990int
983find_before_next_newline (from, to, cnt) 991find_before_next_newline (from, to, cnt)
984 int from, to, cnt; 992 EMACS_INT from, to;
993 int cnt;
985{ 994{
986 int shortage; 995 int shortage;
987 int pos = scan_buffer ('\n', from, to, cnt, &shortage, 1); 996 int pos = scan_buffer ('\n', from, to, cnt, &shortage, 1);
@@ -1142,14 +1151,14 @@ while (0)
1142 (i.e. Vinhibit_changing_match_data is non-nil). */ 1151 (i.e. Vinhibit_changing_match_data is non-nil). */
1143static struct re_registers search_regs_1; 1152static struct re_registers search_regs_1;
1144 1153
1145static int 1154static EMACS_INT
1146search_buffer (string, pos, pos_byte, lim, lim_byte, n, 1155search_buffer (string, pos, pos_byte, lim, lim_byte, n,
1147 RE, trt, inverse_trt, posix) 1156 RE, trt, inverse_trt, posix)
1148 Lisp_Object string; 1157 Lisp_Object string;
1149 int pos; 1158 EMACS_INT pos;
1150 int pos_byte; 1159 EMACS_INT pos_byte;
1151 int lim; 1160 EMACS_INT lim;
1152 int lim_byte; 1161 EMACS_INT lim_byte;
1153 int n; 1162 int n;
1154 int RE; 1163 int RE;
1155 Lisp_Object trt; 1164 Lisp_Object trt;
@@ -1493,14 +1502,14 @@ search_buffer (string, pos, pos_byte, lim, lim_byte, n,
1493 regardless of what is in TRT. It is used in cases where 1502 regardless of what is in TRT. It is used in cases where
1494 boyer_moore cannot work. */ 1503 boyer_moore cannot work. */
1495 1504
1496static int 1505static EMACS_INT
1497simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte) 1506simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte)
1498 int n; 1507 int n;
1499 unsigned char *pat; 1508 unsigned char *pat;
1500 int len, len_byte; 1509 int len, len_byte;
1501 Lisp_Object trt; 1510 Lisp_Object trt;
1502 int pos, pos_byte; 1511 EMACS_INT pos, pos_byte;
1503 int lim, lim_byte; 1512 EMACS_INT lim, lim_byte;
1504{ 1513{
1505 int multibyte = ! NILP (current_buffer->enable_multibyte_characters); 1514 int multibyte = ! NILP (current_buffer->enable_multibyte_characters);
1506 int forward = n > 0; 1515 int forward = n > 0;
@@ -1514,8 +1523,8 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte)
1514 while (1) 1523 while (1)
1515 { 1524 {
1516 /* Try matching at position POS. */ 1525 /* Try matching at position POS. */
1517 int this_pos = pos; 1526 EMACS_INT this_pos = pos;
1518 int this_pos_byte = pos_byte; 1527 EMACS_INT this_pos_byte = pos_byte;
1519 int this_len = len; 1528 int this_len = len;
1520 int this_len_byte = len_byte; 1529 int this_len_byte = len_byte;
1521 unsigned char *p = pat; 1530 unsigned char *p = pat;
@@ -1563,7 +1572,7 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte)
1563 while (1) 1572 while (1)
1564 { 1573 {
1565 /* Try matching at position POS. */ 1574 /* Try matching at position POS. */
1566 int this_pos = pos; 1575 EMACS_INT this_pos = pos;
1567 int this_len = len; 1576 int this_len = len;
1568 unsigned char *p = pat; 1577 unsigned char *p = pat;
1569 1578
@@ -1602,8 +1611,8 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte)
1602 while (1) 1611 while (1)
1603 { 1612 {
1604 /* Try matching at position POS. */ 1613 /* Try matching at position POS. */
1605 int this_pos = pos - len; 1614 EMACS_INT this_pos = pos - len;
1606 int this_pos_byte; 1615 EMACS_INT this_pos_byte;
1607 int this_len = len; 1616 int this_len = len;
1608 int this_len_byte = len_byte; 1617 int this_len_byte = len_byte;
1609 unsigned char *p = pat; 1618 unsigned char *p = pat;
@@ -1652,7 +1661,7 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte)
1652 while (1) 1661 while (1)
1653 { 1662 {
1654 /* Try matching at position POS. */ 1663 /* Try matching at position POS. */
1655 int this_pos = pos - len; 1664 EMACS_INT this_pos = pos - len;
1656 int this_len = len; 1665 int this_len = len;
1657 unsigned char *p = pat; 1666 unsigned char *p = pat;
1658 1667
@@ -1715,7 +1724,7 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte)
1715 1724
1716 If that criterion is not satisfied, do not call this function. */ 1725 If that criterion is not satisfied, do not call this function. */
1717 1726
1718static int 1727static EMACS_INT
1719boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt, 1728boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt,
1720 pos, pos_byte, lim, lim_byte, char_base) 1729 pos, pos_byte, lim, lim_byte, char_base)
1721 int n; 1730 int n;
@@ -1723,13 +1732,14 @@ boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt,
1723 int len, len_byte; 1732 int len, len_byte;
1724 Lisp_Object trt; 1733 Lisp_Object trt;
1725 Lisp_Object inverse_trt; 1734 Lisp_Object inverse_trt;
1726 int pos, pos_byte; 1735 EMACS_INT pos, pos_byte;
1727 int lim, lim_byte; 1736 EMACS_INT lim, lim_byte;
1728 int char_base; 1737 int char_base;
1729{ 1738{
1730 int direction = ((n > 0) ? 1 : -1); 1739 int direction = ((n > 0) ? 1 : -1);
1731 register int dirlen; 1740 register int dirlen;
1732 int limit, stride_for_teases = 0; 1741 EMACS_INT limit;
1742 int stride_for_teases = 0;
1733 int BM_tab[0400]; 1743 int BM_tab[0400];
1734 register unsigned char *cursor, *p_limit; 1744 register unsigned char *cursor, *p_limit;
1735 register int i, j; 1745 register int i, j;
@@ -1888,7 +1898,7 @@ boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt,
1888 char if reverse) of pattern would align in a possible match. */ 1898 char if reverse) of pattern would align in a possible match. */
1889 while (n != 0) 1899 while (n != 0)
1890 { 1900 {
1891 int tail_end; 1901 EMACS_INT tail_end;
1892 unsigned char *tail_end_ptr; 1902 unsigned char *tail_end_ptr;
1893 1903
1894 /* It's been reported that some (broken) compiler thinks that 1904 /* It's been reported that some (broken) compiler thinks that
@@ -1992,7 +2002,7 @@ boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt,
1992 cursor += dirlen - i - direction; /* fix cursor */ 2002 cursor += dirlen - i - direction; /* fix cursor */
1993 if (i + direction == 0) 2003 if (i + direction == 0)
1994 { 2004 {
1995 int position, start, end; 2005 EMACS_INT position, start, end;
1996 2006
1997 cursor -= direction; 2007 cursor -= direction;
1998 2008
@@ -2084,7 +2094,7 @@ boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt,
2084 pos_byte += dirlen - i - direction; 2094 pos_byte += dirlen - i - direction;
2085 if (i + direction == 0) 2095 if (i + direction == 0)
2086 { 2096 {
2087 int position, start, end; 2097 EMACS_INT position, start, end;
2088 pos_byte -= direction; 2098 pos_byte -= direction;
2089 2099
2090 position = pos_byte + ((direction > 0) ? 1 - len_byte : 0); 2100 position = pos_byte + ((direction > 0) ? 1 - len_byte : 0);
@@ -2126,7 +2136,7 @@ boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt,
2126 2136
2127static void 2137static void
2128set_search_regs (beg_byte, nbytes) 2138set_search_regs (beg_byte, nbytes)
2129 int beg_byte, nbytes; 2139 EMACS_INT beg_byte, nbytes;
2130{ 2140{
2131 int i; 2141 int i;
2132 2142
@@ -2478,7 +2488,7 @@ since only regular expressions have distinguished subexpressions. */)
2478 int some_nonuppercase_initial; 2488 int some_nonuppercase_initial;
2479 register int c, prevc; 2489 register int c, prevc;
2480 int sub; 2490 int sub;
2481 int opoint, newpoint; 2491 EMACS_INT opoint, newpoint;
2482 2492
2483 CHECK_STRING (newtext); 2493 CHECK_STRING (newtext);
2484 2494
@@ -2521,7 +2531,7 @@ since only regular expressions have distinguished subexpressions. */)
2521 if (NILP (fixedcase)) 2531 if (NILP (fixedcase))
2522 { 2532 {
2523 /* Decide how to casify by examining the matched text. */ 2533 /* Decide how to casify by examining the matched text. */
2524 int last; 2534 EMACS_INT last;
2525 2535
2526 pos = search_regs.start[sub]; 2536 pos = search_regs.start[sub];
2527 last = search_regs.end[sub]; 2537 last = search_regs.end[sub];
@@ -2608,8 +2618,8 @@ since only regular expressions have distinguished subexpressions. */)
2608 if desired. */ 2618 if desired. */
2609 if (NILP (literal)) 2619 if (NILP (literal))
2610 { 2620 {
2611 int lastpos = 0; 2621 EMACS_INT lastpos = 0;
2612 int lastpos_byte = 0; 2622 EMACS_INT lastpos_byte = 0;
2613 /* We build up the substituted string in ACCUM. */ 2623 /* We build up the substituted string in ACCUM. */
2614 Lisp_Object accum; 2624 Lisp_Object accum;
2615 Lisp_Object middle; 2625 Lisp_Object middle;
@@ -2799,7 +2809,7 @@ since only regular expressions have distinguished subexpressions. */)
2799 set up ADD_STUFF and ADD_LEN to point to it. */ 2809 set up ADD_STUFF and ADD_LEN to point to it. */
2800 if (idx >= 0) 2810 if (idx >= 0)
2801 { 2811 {
2802 int begbyte = CHAR_TO_BYTE (search_regs.start[idx]); 2812 EMACS_INT begbyte = CHAR_TO_BYTE (search_regs.start[idx]);
2803 add_len = CHAR_TO_BYTE (search_regs.end[idx]) - begbyte; 2813 add_len = CHAR_TO_BYTE (search_regs.end[idx]) - begbyte;
2804 if (search_regs.start[idx] < GPT && GPT < search_regs.end[idx]) 2814 if (search_regs.start[idx] < GPT && GPT < search_regs.end[idx])
2805 move_gap (search_regs.start[idx]); 2815 move_gap (search_regs.start[idx]);
@@ -2853,9 +2863,9 @@ since only regular expressions have distinguished subexpressions. */)
2853 2863
2854 /* Adjust search data for this change. */ 2864 /* Adjust search data for this change. */
2855 { 2865 {
2856 int oldend = search_regs.end[sub]; 2866 EMACS_INT oldend = search_regs.end[sub];
2857 int oldstart = search_regs.start[sub]; 2867 EMACS_INT oldstart = search_regs.start[sub];
2858 int change = newpoint - search_regs.end[sub]; 2868 EMACS_INT change = newpoint - search_regs.end[sub];
2859 int i; 2869 int i;
2860 2870
2861 for (i = 0; i < search_regs.num_regs; i++) 2871 for (i = 0; i < search_regs.num_regs; i++)
@@ -3111,7 +3121,7 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */)
3111 } 3121 }
3112 else 3122 else
3113 { 3123 {
3114 int from; 3124 EMACS_INT from;
3115 Lisp_Object m; 3125 Lisp_Object m;
3116 3126
3117 m = marker; 3127 m = marker;