Commit e7deaab0 authored by Andreas Schwab's avatar Andreas Schwab
Browse files

* search.c: Use EMACS_INT for buffer positions. Add prototypes.

* lisp.h: Adjust prototypes.
parent 6340c70e
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
* search.c (boyer_moore): Use zero as marker value for a possible * search.c (boyer_moore): Use zero as marker value for a possible
match instead of depending on overflow behavior. (Bug#2844) match instead of depending on overflow behavior. (Bug#2844)
   
* search.c: Use EMACS_INT for buffer positions. Add prototypes.
* lisp.h: Adjust prototypes.
2009-04-16 Chong Yidong <cyd@stupidchicken.com> 2009-04-16 Chong Yidong <cyd@stupidchicken.com>
   
* keyboard.c (adjust_point_for_property): Disable 2009-02-12 * keyboard.c (adjust_point_for_property): Disable 2009-02-12
......
...@@ -2969,11 +2969,12 @@ extern int fast_c_string_match_ignore_case P_ ((Lisp_Object, const char *)); ...@@ -2969,11 +2969,12 @@ extern int fast_c_string_match_ignore_case P_ ((Lisp_Object, const char *));
extern int fast_string_match_ignore_case P_ ((Lisp_Object, Lisp_Object)); extern int fast_string_match_ignore_case P_ ((Lisp_Object, Lisp_Object));
extern EMACS_INT fast_looking_at P_ ((Lisp_Object, EMACS_INT, EMACS_INT, extern EMACS_INT fast_looking_at P_ ((Lisp_Object, EMACS_INT, EMACS_INT,
EMACS_INT, EMACS_INT, Lisp_Object)); EMACS_INT, EMACS_INT, Lisp_Object));
extern int scan_buffer P_ ((int, int, int, int, int *, int)); extern int scan_buffer P_ ((int, EMACS_INT, EMACS_INT, int, int *, int));
extern int scan_newline P_ ((int, int, int, int, int, int)); extern int scan_newline P_ ((EMACS_INT, EMACS_INT, EMACS_INT, EMACS_INT,
extern int find_next_newline P_ ((int, int)); int, int));
extern int find_next_newline_no_quit P_ ((int, int)); extern int find_next_newline P_ ((EMACS_INT, int));
extern int find_before_next_newline P_ ((int, int, int)); extern int find_next_newline_no_quit P_ ((EMACS_INT, int));
extern int find_before_next_newline P_ ((EMACS_INT, EMACS_INT, int));
extern void syms_of_search P_ ((void)); extern void syms_of_search P_ ((void));
extern void clear_regexp_cache P_ ((void)); extern void clear_regexp_cache P_ ((void));
......
...@@ -97,11 +97,18 @@ Lisp_Object Vsearch_spaces_regexp; ...@@ -97,11 +97,18 @@ Lisp_Object Vsearch_spaces_regexp;
only. */ only. */
Lisp_Object Vinhibit_changing_match_data; Lisp_Object Vinhibit_changing_match_data;
static void set_search_regs (); static void set_search_regs P_ ((EMACS_INT, EMACS_INT));
static void save_search_regs (); static void save_search_regs P_ ((void));
static int simple_search (); static EMACS_INT simple_search P_ ((int, unsigned char *, int, int,
static int boyer_moore (); Lisp_Object, EMACS_INT, EMACS_INT,
static int search_buffer (); EMACS_INT, EMACS_INT));
static EMACS_INT boyer_moore P_ ((int, unsigned char *, int, int,
Lisp_Object, Lisp_Object,
EMACS_INT, EMACS_INT,
EMACS_INT, EMACS_INT, int));
static EMACS_INT search_buffer P_ ((Lisp_Object, EMACS_INT, EMACS_INT,
EMACS_INT, EMACS_INT, int, int,
Lisp_Object, Lisp_Object, int));
static void matcher_overflow () NO_RETURN; static void matcher_overflow () NO_RETURN;
static void static void
...@@ -288,7 +295,7 @@ looking_at_1 (string, posix) ...@@ -288,7 +295,7 @@ looking_at_1 (string, posix)
{ {
Lisp_Object val; Lisp_Object val;
unsigned char *p1, *p2; unsigned char *p1, *p2;
int s1, s2; EMACS_INT s1, s2;
register int i; register int i;
struct re_pattern_buffer *bufp; struct re_pattern_buffer *bufp;
...@@ -390,7 +397,7 @@ string_match_1 (regexp, string, start, posix) ...@@ -390,7 +397,7 @@ string_match_1 (regexp, string, start, posix)
{ {
int val; int val;
struct re_pattern_buffer *bufp; struct re_pattern_buffer *bufp;
int pos, pos_byte; EMACS_INT pos, pos_byte;
int i; int i;
if (running_asynch_code) if (running_asynch_code)
...@@ -572,7 +579,7 @@ fast_looking_at (regexp, pos, pos_byte, limit, limit_byte, string) ...@@ -572,7 +579,7 @@ fast_looking_at (regexp, pos, pos_byte, limit, limit_byte, string)
int multibyte; int multibyte;
struct re_pattern_buffer *buf; struct re_pattern_buffer *buf;
unsigned char *p1, *p2; unsigned char *p1, *p2;
int s1, s2; EMACS_INT s1, s2;
EMACS_INT len; EMACS_INT len;
if (STRINGP (string)) if (STRINGP (string))
...@@ -676,7 +683,7 @@ newline_cache_on_off (buf) ...@@ -676,7 +683,7 @@ newline_cache_on_off (buf)
int int
scan_buffer (target, start, end, count, shortage, allow_quit) scan_buffer (target, start, end, count, shortage, allow_quit)
register int target; register int target;
int start, end; EMACS_INT start, end;
int count; int count;
int *shortage; int *shortage;
int allow_quit; int allow_quit;
...@@ -711,9 +718,9 @@ scan_buffer (target, start, end, count, shortage, allow_quit) ...@@ -711,9 +718,9 @@ scan_buffer (target, start, end, count, shortage, allow_quit)
the position of the last character before the next such the position of the last character before the next such
obstacle --- the last character the dumb search loop should obstacle --- the last character the dumb search loop should
examine. */ examine. */
int ceiling_byte = CHAR_TO_BYTE (end) - 1; EMACS_INT ceiling_byte = CHAR_TO_BYTE (end) - 1;
int start_byte = CHAR_TO_BYTE (start); EMACS_INT start_byte = CHAR_TO_BYTE (start);
int tem; EMACS_INT tem;
/* If we're looking for a newline, consult the newline cache /* If we're looking for a newline, consult the newline cache
to see where we can avoid some scanning. */ to see where we can avoid some scanning. */
...@@ -784,9 +791,9 @@ scan_buffer (target, start, end, count, shortage, allow_quit) ...@@ -784,9 +791,9 @@ scan_buffer (target, start, end, count, shortage, allow_quit)
while (start > end) while (start > end)
{ {
/* The last character to check before the next obstacle. */ /* The last character to check before the next obstacle. */
int ceiling_byte = CHAR_TO_BYTE (end); EMACS_INT ceiling_byte = CHAR_TO_BYTE (end);
int start_byte = CHAR_TO_BYTE (start); EMACS_INT start_byte = CHAR_TO_BYTE (start);
int tem; EMACS_INT tem;
/* Consult the newline cache, if appropriate. */ /* Consult the newline cache, if appropriate. */
if (target == '\n' && newline_cache) if (target == '\n' && newline_cache)
...@@ -872,8 +879,8 @@ scan_buffer (target, start, end, count, shortage, allow_quit) ...@@ -872,8 +879,8 @@ scan_buffer (target, start, end, count, shortage, allow_quit)
int int
scan_newline (start, start_byte, limit, limit_byte, count, allow_quit) scan_newline (start, start_byte, limit, limit_byte, count, allow_quit)
int start, start_byte; EMACS_INT start, start_byte;
int limit, limit_byte; EMACS_INT limit, limit_byte;
register int count; register int count;
int allow_quit; int allow_quit;
{ {
...@@ -882,7 +889,7 @@ scan_newline (start, start_byte, limit, limit_byte, count, allow_quit) ...@@ -882,7 +889,7 @@ scan_newline (start, start_byte, limit, limit_byte, count, allow_quit)
register unsigned char *cursor; register unsigned char *cursor;
unsigned char *base; unsigned char *base;
register int ceiling; EMACS_INT ceiling;
register unsigned char *ceiling_addr; register unsigned char *ceiling_addr;
int old_immediate_quit = immediate_quit; int old_immediate_quit = immediate_quit;
...@@ -970,7 +977,8 @@ scan_newline (start, start_byte, limit, limit_byte, count, allow_quit) ...@@ -970,7 +977,8 @@ scan_newline (start, start_byte, limit, limit_byte, count, allow_quit)
int int
find_next_newline_no_quit (from, cnt) find_next_newline_no_quit (from, cnt)
register int from, cnt; EMACS_INT from;
int cnt;
{ {
return scan_buffer ('\n', from, 0, cnt, (int *) 0, 0); return scan_buffer ('\n', from, 0, cnt, (int *) 0, 0);
} }
...@@ -981,7 +989,8 @@ find_next_newline_no_quit (from, cnt) ...@@ -981,7 +989,8 @@ find_next_newline_no_quit (from, cnt)
int int
find_before_next_newline (from, to, cnt) find_before_next_newline (from, to, cnt)
int from, to, cnt; EMACS_INT from, to;
int cnt;
{ {
int shortage; int shortage;
int pos = scan_buffer ('\n', from, to, cnt, &shortage, 1); int pos = scan_buffer ('\n', from, to, cnt, &shortage, 1);
...@@ -1142,14 +1151,14 @@ while (0) ...@@ -1142,14 +1151,14 @@ while (0)
(i.e. Vinhibit_changing_match_data is non-nil). */ (i.e. Vinhibit_changing_match_data is non-nil). */
static struct re_registers search_regs_1; static struct re_registers search_regs_1;
static int static EMACS_INT
search_buffer (string, pos, pos_byte, lim, lim_byte, n, search_buffer (string, pos, pos_byte, lim, lim_byte, n,
RE, trt, inverse_trt, posix) RE, trt, inverse_trt, posix)
Lisp_Object string; Lisp_Object string;
int pos; EMACS_INT pos;
int pos_byte; EMACS_INT pos_byte;
int lim; EMACS_INT lim;
int lim_byte; EMACS_INT lim_byte;
int n; int n;
int RE; int RE;
Lisp_Object trt; Lisp_Object trt;
...@@ -1493,14 +1502,14 @@ search_buffer (string, pos, pos_byte, lim, lim_byte, n, ...@@ -1493,14 +1502,14 @@ search_buffer (string, pos, pos_byte, lim, lim_byte, n,
regardless of what is in TRT. It is used in cases where regardless of what is in TRT. It is used in cases where
boyer_moore cannot work. */ boyer_moore cannot work. */
static int static EMACS_INT
simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte) simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte)
int n; int n;
unsigned char *pat; unsigned char *pat;
int len, len_byte; int len, len_byte;
Lisp_Object trt; Lisp_Object trt;
int pos, pos_byte; EMACS_INT pos, pos_byte;
int lim, lim_byte; EMACS_INT lim, lim_byte;
{ {
int multibyte = ! NILP (current_buffer->enable_multibyte_characters); int multibyte = ! NILP (current_buffer->enable_multibyte_characters);
int forward = n > 0; int forward = n > 0;
...@@ -1514,8 +1523,8 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte) ...@@ -1514,8 +1523,8 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte)
while (1) while (1)
{ {
/* Try matching at position POS. */ /* Try matching at position POS. */
int this_pos = pos; EMACS_INT this_pos = pos;
int this_pos_byte = pos_byte; EMACS_INT this_pos_byte = pos_byte;
int this_len = len; int this_len = len;
int this_len_byte = len_byte; int this_len_byte = len_byte;
unsigned char *p = pat; unsigned char *p = pat;
...@@ -1563,7 +1572,7 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte) ...@@ -1563,7 +1572,7 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte)
while (1) while (1)
{ {
/* Try matching at position POS. */ /* Try matching at position POS. */
int this_pos = pos; EMACS_INT this_pos = pos;
int this_len = len; int this_len = len;
unsigned char *p = pat; unsigned char *p = pat;
...@@ -1602,8 +1611,8 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte) ...@@ -1602,8 +1611,8 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte)
while (1) while (1)
{ {
/* Try matching at position POS. */ /* Try matching at position POS. */
int this_pos = pos - len; EMACS_INT this_pos = pos - len;
int this_pos_byte; EMACS_INT this_pos_byte;
int this_len = len; int this_len = len;
int this_len_byte = len_byte; int this_len_byte = len_byte;
unsigned char *p = pat; unsigned char *p = pat;
...@@ -1652,7 +1661,7 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte) ...@@ -1652,7 +1661,7 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte)
while (1) while (1)
{ {
/* Try matching at position POS. */ /* Try matching at position POS. */
int this_pos = pos - len; EMACS_INT this_pos = pos - len;
int this_len = len; int this_len = len;
unsigned char *p = pat; unsigned char *p = pat;
...@@ -1715,7 +1724,7 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte) ...@@ -1715,7 +1724,7 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte)
If that criterion is not satisfied, do not call this function. */ If that criterion is not satisfied, do not call this function. */
static int static EMACS_INT
boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt, boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt,
pos, pos_byte, lim, lim_byte, char_base) pos, pos_byte, lim, lim_byte, char_base)
int n; int n;
...@@ -1723,13 +1732,14 @@ boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt, ...@@ -1723,13 +1732,14 @@ boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt,
int len, len_byte; int len, len_byte;
Lisp_Object trt; Lisp_Object trt;
Lisp_Object inverse_trt; Lisp_Object inverse_trt;
int pos, pos_byte; EMACS_INT pos, pos_byte;
int lim, lim_byte; EMACS_INT lim, lim_byte;
int char_base; int char_base;
{ {
int direction = ((n > 0) ? 1 : -1); int direction = ((n > 0) ? 1 : -1);
register int dirlen; register int dirlen;
int limit, stride_for_teases = 0; EMACS_INT limit;
int stride_for_teases = 0;
int BM_tab[0400]; int BM_tab[0400];
register unsigned char *cursor, *p_limit; register unsigned char *cursor, *p_limit;
register int i, j; register int i, j;
...@@ -1888,7 +1898,7 @@ boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt, ...@@ -1888,7 +1898,7 @@ boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt,
char if reverse) of pattern would align in a possible match. */ char if reverse) of pattern would align in a possible match. */
while (n != 0) while (n != 0)
{ {
int tail_end; EMACS_INT tail_end;
unsigned char *tail_end_ptr; unsigned char *tail_end_ptr;
/* It's been reported that some (broken) compiler thinks that /* 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,7 +2002,7 @@ boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt,
cursor += dirlen - i - direction; /* fix cursor */ cursor += dirlen - i - direction; /* fix cursor */
if (i + direction == 0) if (i + direction == 0)
{ {
int position, start, end; EMACS_INT position, start, end;
cursor -= direction; cursor -= direction;
...@@ -2084,7 +2094,7 @@ boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt, ...@@ -2084,7 +2094,7 @@ boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt,
pos_byte += dirlen - i - direction; pos_byte += dirlen - i - direction;
if (i + direction == 0) if (i + direction == 0)
{ {
int position, start, end; EMACS_INT position, start, end;
pos_byte -= direction; pos_byte -= direction;
position = pos_byte + ((direction > 0) ? 1 - len_byte : 0); 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,7 +2136,7 @@ boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt,
static void static void
set_search_regs (beg_byte, nbytes) set_search_regs (beg_byte, nbytes)
int beg_byte, nbytes; EMACS_INT beg_byte, nbytes;
{ {
int i; int i;
...@@ -2478,7 +2488,7 @@ since only regular expressions have distinguished subexpressions. */) ...@@ -2478,7 +2488,7 @@ since only regular expressions have distinguished subexpressions. */)
int some_nonuppercase_initial; int some_nonuppercase_initial;
register int c, prevc; register int c, prevc;
int sub; int sub;
int opoint, newpoint; EMACS_INT opoint, newpoint;
CHECK_STRING (newtext); CHECK_STRING (newtext);
...@@ -2521,7 +2531,7 @@ since only regular expressions have distinguished subexpressions. */) ...@@ -2521,7 +2531,7 @@ since only regular expressions have distinguished subexpressions. */)
if (NILP (fixedcase)) if (NILP (fixedcase))
{ {
/* Decide how to casify by examining the matched text. */ /* Decide how to casify by examining the matched text. */
int last; EMACS_INT last;
pos = search_regs.start[sub]; pos = search_regs.start[sub];
last = search_regs.end[sub]; last = search_regs.end[sub];
...@@ -2608,8 +2618,8 @@ since only regular expressions have distinguished subexpressions. */) ...@@ -2608,8 +2618,8 @@ since only regular expressions have distinguished subexpressions. */)
if desired. */ if desired. */
if (NILP (literal)) if (NILP (literal))
{ {
int lastpos = 0; EMACS_INT lastpos = 0;
int lastpos_byte = 0; EMACS_INT lastpos_byte = 0;
/* We build up the substituted string in ACCUM. */ /* We build up the substituted string in ACCUM. */
Lisp_Object accum; Lisp_Object accum;
Lisp_Object middle; Lisp_Object middle;
...@@ -2799,7 +2809,7 @@ since only regular expressions have distinguished subexpressions. */) ...@@ -2799,7 +2809,7 @@ since only regular expressions have distinguished subexpressions. */)
set up ADD_STUFF and ADD_LEN to point to it. */ set up ADD_STUFF and ADD_LEN to point to it. */
if (idx >= 0) if (idx >= 0)
{ {
int begbyte = CHAR_TO_BYTE (search_regs.start[idx]); EMACS_INT begbyte = CHAR_TO_BYTE (search_regs.start[idx]);
add_len = CHAR_TO_BYTE (search_regs.end[idx]) - begbyte; add_len = CHAR_TO_BYTE (search_regs.end[idx]) - begbyte;
if (search_regs.start[idx] < GPT && GPT < search_regs.end[idx]) if (search_regs.start[idx] < GPT && GPT < search_regs.end[idx])
move_gap (search_regs.start[idx]); move_gap (search_regs.start[idx]);
...@@ -2853,9 +2863,9 @@ since only regular expressions have distinguished subexpressions. */) ...@@ -2853,9 +2863,9 @@ since only regular expressions have distinguished subexpressions. */)
/* Adjust search data for this change. */ /* Adjust search data for this change. */
{ {
int oldend = search_regs.end[sub]; EMACS_INT oldend = search_regs.end[sub];
int oldstart = search_regs.start[sub]; EMACS_INT oldstart = search_regs.start[sub];
int change = newpoint - search_regs.end[sub]; EMACS_INT change = newpoint - search_regs.end[sub];
int i; int i;
for (i = 0; i < search_regs.num_regs; i++) 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,7 +3121,7 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */)
} }
else else
{ {
int from; EMACS_INT from;
Lisp_Object m; Lisp_Object m;
m = marker; m = marker;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment