summaryrefslogtreecommitdiff
path: root/src/search.c
diff options
context:
space:
mode:
authorGerd Möllmann <gerd@gnu.org>2022-06-24 10:44:17 +0200
committerEli Zaretskii <eliz@gnu.org>2022-06-27 16:23:07 +0300
commit1e58dc46b89da4cdb537c6966e6cba8f6df4a106 (patch)
tree2dd1381722be95ec6396f82c624803666c6b3d32 /src/search.c
parent0190dff96ac15e48ad57f33d69f5900b3851b9e0 (diff)
downloademacs-1e58dc46b89da4cdb537c6966e6cba8f6df4a106.tar.gz
emacs-1e58dc46b89da4cdb537c6966e6cba8f6df4a106.tar.bz2
emacs-1e58dc46b89da4cdb537c6966e6cba8f6df4a106.zip
Prevent regexp cache entries from being GC'ed in more cases
* src/search.c (string_match_1, fast_string_match_internal) (fast_c_string_match_ignore_case): Use freeze_pattern. (Bug#56108)
Diffstat (limited to 'src/search.c')
-rw-r--r--src/search.c49
1 files changed, 26 insertions, 23 deletions
diff --git a/src/search.c b/src/search.c
index 816a757c188..9d6bd074e1b 100644
--- a/src/search.c
+++ b/src/search.c
@@ -370,7 +370,6 @@ string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start,
bool posix, bool modify_data)
{
ptrdiff_t val;
- struct re_pattern_buffer *bufp;
EMACS_INT pos;
ptrdiff_t pos_byte, i;
bool modify_match_data = NILP (Vinhibit_changing_match_data) && modify_data;
@@ -401,17 +400,22 @@ string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start,
set_char_table_extras (BVAR (current_buffer, case_canon_table), 2,
BVAR (current_buffer, case_eqv_table));
- bufp = &compile_pattern (regexp,
- (modify_match_data ? &search_regs : NULL),
- (!NILP (BVAR (current_buffer, case_fold_search))
- ? BVAR (current_buffer, case_canon_table) : Qnil),
- posix,
- STRING_MULTIBYTE (string))->buf;
+ specpdl_ref count = SPECPDL_INDEX ();
+ struct regexp_cache *cache_entry
+ = compile_pattern (regexp,
+ modify_match_data ? &search_regs : NULL,
+ (!NILP (BVAR (current_buffer, case_fold_search))
+ ? BVAR (current_buffer, case_canon_table)
+ : Qnil),
+ posix,
+ STRING_MULTIBYTE (string));
+ freeze_pattern (cache_entry);
re_match_object = string;
- val = re_search (bufp, SSDATA (string),
+ val = re_search (&cache_entry->buf, SSDATA (string),
SBYTES (string), pos_byte,
SBYTES (string) - pos_byte,
(modify_match_data ? &search_regs : NULL));
+ unbind_to (count, Qnil);
/* Set last_thing_searched only when match data is changed. */
if (modify_match_data)
@@ -480,15 +484,15 @@ ptrdiff_t
fast_string_match_internal (Lisp_Object regexp, Lisp_Object string,
Lisp_Object table)
{
- ptrdiff_t val;
- struct re_pattern_buffer *bufp;
-
- bufp = &compile_pattern (regexp, 0, table,
- 0, STRING_MULTIBYTE (string))->buf;
re_match_object = string;
- val = re_search (bufp, SSDATA (string),
- SBYTES (string), 0,
- SBYTES (string), 0);
+ specpdl_ref count = SPECPDL_INDEX ();
+ struct regexp_cache *cache_entry
+ = compile_pattern (regexp, 0, table, 0, STRING_MULTIBYTE (string));
+ freeze_pattern (cache_entry);
+ ptrdiff_t val = re_search (&cache_entry->buf, SSDATA (string),
+ SBYTES (string), 0,
+ SBYTES (string), 0);
+ unbind_to (count, Qnil);
return val;
}
@@ -501,15 +505,14 @@ ptrdiff_t
fast_c_string_match_ignore_case (Lisp_Object regexp,
const char *string, ptrdiff_t len)
{
- ptrdiff_t val;
- struct re_pattern_buffer *bufp;
-
regexp = string_make_unibyte (regexp);
- bufp = &compile_pattern (regexp, 0,
- Vascii_canon_table, 0,
- 0)->buf;
+ specpdl_ref count = SPECPDL_INDEX ();
+ struct regexp_cache *cache_entry
+ = compile_pattern (regexp, 0, Vascii_canon_table, 0, 0);
+ freeze_pattern (cache_entry);
re_match_object = Qt;
- val = re_search (bufp, string, len, 0, len, 0);
+ ptrdiff_t val = re_search (&cache_entry->buf, string, len, 0, len, 0);
+ unbind_to (count, Qnil);
return val;
}