summaryrefslogtreecommitdiff
path: root/src/search.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/search.c')
-rw-r--r--src/search.c86
1 files changed, 37 insertions, 49 deletions
diff --git a/src/search.c b/src/search.c
index 818bb4af246..6fb3716cd43 100644
--- a/src/search.c
+++ b/src/search.c
@@ -353,8 +353,8 @@ data if you want to preserve them. */)
}
DEFUN ("posix-looking-at", Fposix_looking_at, Sposix_looking_at, 1, 1, 0,
- doc: /* Return t if text after point matches regular expression REGEXP.
-Find the longest match, in accord with Posix regular expression rules.
+ doc: /* Return t if text after point matches REGEXP according to Posix rules.
+Find the longest match, in accordance with Posix regular expression rules.
This function modifies the match data that `match-beginning',
`match-end' and `match-data' access; save and restore the match
data if you want to preserve them. */)
@@ -449,7 +449,7 @@ matched by the parenthesis constructions in REGEXP. */)
}
DEFUN ("posix-string-match", Fposix_string_match, Sposix_string_match, 2, 3, 0,
- doc: /* Return index of start of first match for REGEXP in STRING, or nil.
+ doc: /* Return index of start of first match for Posix REGEXP in STRING, or nil.
Find the longest match, in accord with Posix regular expression rules.
Case is ignored if `case-fold-search' is non-nil in the current buffer.
If third arg START is non-nil, start search at that index in STRING.
@@ -613,7 +613,10 @@ newline_cache_on_off (struct buffer *buf)
{
/* It should be on. */
if (base_buf->newline_cache == 0)
- base_buf->newline_cache = new_region_cache ();
+ {
+ base_buf->newline_cache = new_region_cache ();
+ __lsan_ignore_object (base_buf->newline_cache);
+ }
}
return base_buf->newline_cache;
}
@@ -994,7 +997,7 @@ find_before_next_newline (ptrdiff_t from, ptrdiff_t to,
if (counted == cnt)
{
if (bytepos)
- DEC_BOTH (pos, *bytepos);
+ dec_both (&pos, &*bytepos);
else
pos--;
}
@@ -1028,8 +1031,7 @@ search_command (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror,
}
else
{
- CHECK_FIXNUM_COERCE_MARKER (bound);
- lim = XFIXNUM (bound);
+ lim = fix_position (bound);
if (n > 0 ? lim < PT : lim > PT)
error ("Invalid search bound (wrong side of point)");
if (lim > ZV)
@@ -1354,8 +1356,8 @@ search_buffer_non_re (Lisp_Object string, ptrdiff_t pos,
while (--len >= 0)
{
unsigned char str_base[MAX_MULTIBYTE_LENGTH], *str;
- int c, translated, inverse;
- int in_charlen, charlen;
+ int translated, inverse;
+ int charlen;
/* If we got here and the RE flag is set, it's because we're
dealing with a regexp known to be trivial, so the backslash
@@ -1368,7 +1370,7 @@ search_buffer_non_re (Lisp_Object string, ptrdiff_t pos,
base_pat++;
}
- c = STRING_CHAR_AND_LENGTH (base_pat, in_charlen);
+ int in_charlen, c = string_char_and_length (base_pat, &in_charlen);
if (NILP (trt))
{
@@ -1551,12 +1553,10 @@ simple_search (EMACS_INT n, unsigned char *pat,
while (this_len > 0)
{
- int charlen, buf_charlen;
- int pat_ch, buf_ch;
-
- pat_ch = STRING_CHAR_AND_LENGTH (p, charlen);
- buf_ch = STRING_CHAR_AND_LENGTH (BYTE_POS_ADDR (this_pos_byte),
- buf_charlen);
+ int charlen, pat_ch = string_char_and_length (p, &charlen);
+ int buf_charlen, buf_ch
+ = string_char_and_length (BYTE_POS_ADDR (this_pos_byte),
+ &buf_charlen);
TRANSLATE (buf_ch, trt, buf_ch);
if (buf_ch != pat_ch)
@@ -1577,7 +1577,7 @@ simple_search (EMACS_INT n, unsigned char *pat,
break;
}
- INC_BOTH (pos, pos_byte);
+ inc_both (&pos, &pos_byte);
}
n--;
@@ -1639,8 +1639,8 @@ simple_search (EMACS_INT n, unsigned char *pat,
{
int pat_ch, buf_ch;
- DEC_BOTH (this_pos, this_pos_byte);
- PREV_CHAR_BOUNDARY (p, pat);
+ dec_both (&this_pos, &this_pos_byte);
+ p -= raw_prev_char_len (p);
pat_ch = STRING_CHAR (p);
buf_ch = STRING_CHAR (BYTE_POS_ADDR (this_pos_byte));
TRANSLATE (buf_ch, trt, buf_ch);
@@ -1659,7 +1659,7 @@ simple_search (EMACS_INT n, unsigned char *pat,
break;
}
- DEC_BOTH (pos, pos_byte);
+ dec_both (&pos, &pos_byte);
}
n++;
@@ -2279,7 +2279,7 @@ and `replace-match'. */)
DEFUN ("posix-search-backward", Fposix_search_backward, Sposix_search_backward, 1, 4,
"sPosix search backward: ",
- doc: /* Search backward from point for match for regular expression REGEXP.
+ doc: /* Search backward from point for match for REGEXP according to Posix rules.
Find the longest match in accord with Posix regular expression rules.
Set point to the beginning of the occurrence found, and return point.
An optional second argument bounds the search; it is a buffer position.
@@ -2307,7 +2307,7 @@ and `replace-match'. */)
DEFUN ("posix-search-forward", Fposix_search_forward, Sposix_search_forward, 1, 4,
"sPosix search: ",
- doc: /* Search forward from point for regular expression REGEXP.
+ doc: /* Search forward from point for REGEXP according to Posix rules.
Find the longest match in accord with Posix regular expression rules.
Set point to the end of the occurrence found, and return point.
An optional second argument bounds the search; it is a buffer position.
@@ -2393,14 +2393,7 @@ since only regular expressions have distinguished subexpressions. */)
if (num_regs <= 0)
error ("`replace-match' called before any match found");
- if (NILP (subexp))
- sub = 0;
- else
- {
- CHECK_RANGED_INTEGER (subexp, 0, num_regs - 1);
- sub = XFIXNUM (subexp);
- }
-
+ sub = !NILP (subexp) ? check_integer_range (subexp, 0, num_regs - 1) : 0;
ptrdiff_t sub_start = search_regs.start[sub];
ptrdiff_t sub_end = search_regs.end[sub];
eassert (sub_start <= sub_end);
@@ -2445,10 +2438,11 @@ since only regular expressions have distinguished subexpressions. */)
if (NILP (string))
{
c = FETCH_CHAR_AS_MULTIBYTE (pos_byte);
- INC_BOTH (pos, pos_byte);
+ inc_both (&pos, &pos_byte);
}
else
- FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, string, pos, pos_byte);
+ c = fetch_string_char_as_multibyte_advance (string,
+ &pos, &pos_byte);
if (lowercasep (c))
{
@@ -2521,11 +2515,11 @@ since only regular expressions have distinguished subexpressions. */)
ptrdiff_t subend = 0;
bool delbackslash = 0;
- FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte);
+ c = fetch_string_char_advance (newtext, &pos, &pos_byte);
if (c == '\\')
{
- FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte);
+ c = fetch_string_char_advance (newtext, &pos, &pos_byte);
if (c == '&')
{
@@ -2633,7 +2627,8 @@ since only regular expressions have distinguished subexpressions. */)
if (str_multibyte)
{
- FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c, newtext, pos, pos_byte);
+ c = fetch_string_char_advance_no_check (newtext,
+ &pos, &pos_byte);
if (!buf_multibyte)
c = CHAR_TO_BYTE8 (c);
}
@@ -2642,7 +2637,7 @@ since only regular expressions have distinguished subexpressions. */)
/* Note that we don't have to increment POS. */
c = SREF (newtext, pos_byte++);
if (buf_multibyte)
- MAKE_CHAR_MULTIBYTE (c);
+ c = make_char_multibyte (c);
}
/* Either set ADD_STUFF and ADD_LEN to the text to put in SUBSTED,
@@ -2655,8 +2650,8 @@ since only regular expressions have distinguished subexpressions. */)
if (str_multibyte)
{
- FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c, newtext,
- pos, pos_byte);
+ c = fetch_string_char_advance_no_check (newtext,
+ &pos, &pos_byte);
if (!buf_multibyte && !ASCII_CHAR_P (c))
c = CHAR_TO_BYTE8 (c);
}
@@ -2664,7 +2659,7 @@ since only regular expressions have distinguished subexpressions. */)
{
c = SREF (newtext, pos_byte++);
if (buf_multibyte)
- MAKE_CHAR_MULTIBYTE (c);
+ c = make_char_multibyte (c);
}
if (c == '&')
@@ -3276,7 +3271,7 @@ the buffer. If the buffer doesn't have a cache, the value is nil. */)
TYPE_MAXIMUM (ptrdiff_t), &nl_count_cache, NULL, true);
/* Create vector and populate it. */
- cache_newlines = make_uninit_vector (nl_count_cache);
+ cache_newlines = make_vector (nl_count_cache, make_fixnum (-1));
if (nl_count_cache)
{
@@ -3290,15 +3285,12 @@ the buffer. If the buffer doesn't have a cache, the value is nil. */)
break;
ASET (cache_newlines, i, make_fixnum (found - 1));
}
- /* Fill the rest of slots with an invalid position. */
- for ( ; i < nl_count_cache; i++)
- ASET (cache_newlines, i, make_fixnum (-1));
}
/* Now do the same, but without using the cache. */
find_newline1 (BEGV, BEGV_BYTE, ZV, ZV_BYTE,
TYPE_MAXIMUM (ptrdiff_t), &nl_count_buf, NULL, true);
- buf_newlines = make_uninit_vector (nl_count_buf);
+ buf_newlines = make_vector (nl_count_buf, make_fixnum (-1));
if (nl_count_buf)
{
for (from = BEGV, found = from, i = 0; from < ZV; from = found, i++)
@@ -3311,14 +3303,10 @@ the buffer. If the buffer doesn't have a cache, the value is nil. */)
break;
ASET (buf_newlines, i, make_fixnum (found - 1));
}
- for ( ; i < nl_count_buf; i++)
- ASET (buf_newlines, i, make_fixnum (-1));
}
/* Construct the value and return it. */
- val = make_uninit_vector (2);
- ASET (val, 0, cache_newlines);
- ASET (val, 1, buf_newlines);
+ val = CALLN (Fvector, cache_newlines, buf_newlines);
if (old != NULL)
set_buffer_internal_1 (old);